Module: ActsAsApi::Base::ClassMethods

Defined in:
lib/acts_as_api/base.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_api?Boolean

:nodoc:

Returns:

  • (Boolean)

24
25
26
# File 'lib/acts_as_api/base.rb', line 24

def acts_as_api? #:nodoc:
  included_modules.include?(InstanceMethods)
end

#api_accessible(api_template, options = {}) {|attributes| ... } ⇒ Object

Determines the attributes, methods of the model that are accessible in the api response. Note: There is only whitelisting for api accessible attributes. So once the model acts as api, you have to determine all attributes here that should be contained in the api responses.

Yields:

  • (attributes)

32
33
34
35
36
37
38
39
40
# File 'lib/acts_as_api/base.rb', line 32

def api_accessible(api_template, options = {}, &block)
  attributes = api_accessible_attributes(api_template).try(:dup) || ApiTemplate.new(api_template)
  attributes.merge!(api_accessible_attributes(options[:extend])) if options[:extend]

  yield attributes if block_given?

  class_attribute "api_accessible_#{api_template}".to_sym
  send "api_accessible_#{api_template}=", attributes
end

#api_accessible_attributes(api_template) ⇒ Object

Returns an array of all the attributes that have been made accessible to the api response.


43
44
45
# File 'lib/acts_as_api/base.rb', line 43

def api_accessible_attributes(api_template)
  begin send "api_accessible_#{api_template}".to_sym rescue nil end
end