Class: Restful::Rails::ActiveRecord::Configuration::Config
- Inherits:
-
Object
- Object
- Restful::Rails::ActiveRecord::Configuration::Config
- Defined in:
- lib/restful/rails/active_record/configuration.rb
Overview
configures what attributes are exposed to the api. for a single resource.
Instance Attribute Summary collapse
-
#restful_options ⇒ Object
Returns the value of attribute restful_options.
-
#whitelisted ⇒ Object
Returns the value of attribute whitelisted.
Instance Method Summary collapse
-
#expanded?(key, nested = false) ⇒ Boolean
if nothing was set, this defaults to true.
- #force_expanded?(key) ⇒ Boolean
-
#initialize(*fields) ⇒ Config
constructor
set; eg :name, :pets => [:name, :species].
- #nested(key) ⇒ Object
- #nested? ⇒ Boolean
- #published?(key) ⇒ Boolean
Constructor Details
#initialize(*fields) ⇒ Config
set; eg :name, :pets => [:name, :species]
116 117 118 |
# File 'lib/restful/rails/active_record/configuration.rb', line 116 def initialize(*fields) # set; eg :name, :pets => [:name, :species] @whitelisted, @restful_options = ([fields].flatten.compact) end |
Instance Attribute Details
#restful_options ⇒ Object
Returns the value of attribute restful_options.
114 115 116 |
# File 'lib/restful/rails/active_record/configuration.rb', line 114 def @restful_options end |
#whitelisted ⇒ Object
Returns the value of attribute whitelisted.
114 115 116 |
# File 'lib/restful/rails/active_record/configuration.rb', line 114 def whitelisted @whitelisted end |
Instance Method Details
#expanded?(key, nested = false) ⇒ Boolean
if nothing was set, this defaults to true.
124 125 126 |
# File 'lib/restful/rails/active_record/configuration.rb', line 124 def (key, nested = false) # if nothing was set, this defaults to true. (key) || (@restful_options[:expansion] != :collapsed && !nested) end |
#force_expanded?(key) ⇒ Boolean
128 129 130 131 |
# File 'lib/restful/rails/active_record/configuration.rb', line 128 def (key) force = [*@restful_options[:force_expand]] force.include?(key) end |
#nested(key) ⇒ Object
137 138 139 140 |
# File 'lib/restful/rails/active_record/configuration.rb', line 137 def nested(key) definition = @whitelisted.select { |field| field.is_a?(Hash) && field.keys.include?(key) }.first Config.new((definition[key] if definition)) end |
#nested? ⇒ Boolean
133 134 135 |
# File 'lib/restful/rails/active_record/configuration.rb', line 133 def nested? !![:nested] end |
#published?(key) ⇒ Boolean
120 121 122 |
# File 'lib/restful/rails/active_record/configuration.rb', line 120 def published?(key) @whitelisted.include?(key) || !!@whitelisted.select { |field| field.is_a?(Hash) && field.keys.include?(key) }.first end |