Module: ActsAsApi::Base::ClassMethods
- Defined in:
- lib/acts_as_api/base.rb
Instance Method Summary collapse
-
#acts_as_api? ⇒ Boolean
:nodoc:.
-
#api_accessible(api_template, options = {}, &block) ⇒ Object
Determines the attributes, methods of the model that are accessible in the api response.
-
#api_accessible_attributes(api_template) ⇒ Object
Returns an array of all the attributes that have been made accessible to the api response.
Instance Method Details
#acts_as_api? ⇒ Boolean
:nodoc:
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 = {}, &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.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/acts_as_api/base.rb', line 32 def api_accessible(api_template, = {}, &block) attributes = api_accessible_attributes(api_template).try(:dup) || ApiTemplate.new(api_template) attributes.merge!(api_accessible_attributes([:extend])) if [: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.
45 46 47 |
# File 'lib/acts_as_api/base.rb', line 45 def api_accessible_attributes(api_template) begin send "api_accessible_#{api_template}".to_sym rescue nil end end |