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)


27
28
29
# File 'lib/acts_as_api/base.rb', line 27

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

#api_accessible(api_template, options = {}, &block) ⇒ 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.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/acts_as_api/base.rb', line 35

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]

  if block_given?
    yield attributes
  end

  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.



50
51
52
# File 'lib/acts_as_api/base.rb', line 50

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