Class: Redtape::AttributeWhitelist
- Inherits:
-
Object
- Object
- Redtape::AttributeWhitelist
- Defined in:
- lib/redtape/attribute_whitelist.rb
Instance Attribute Summary collapse
-
#whitelisted_attrs ⇒ Object
readonly
Returns the value of attribute whitelisted_attrs.
Instance Method Summary collapse
- #allows?(args = {}) ⇒ Boolean
-
#initialize(whitelisted_attrs) ⇒ AttributeWhitelist
constructor
A new instance of AttributeWhitelist.
- #top_level_name ⇒ Object
Constructor Details
#initialize(whitelisted_attrs) ⇒ AttributeWhitelist
Returns a new instance of AttributeWhitelist.
5 6 7 |
# File 'lib/redtape/attribute_whitelist.rb', line 5 def initialize(whitelisted_attrs) @whitelisted_attrs = whitelisted_attrs end |
Instance Attribute Details
#whitelisted_attrs ⇒ Object (readonly)
Returns the value of attribute whitelisted_attrs.
3 4 5 |
# File 'lib/redtape/attribute_whitelist.rb', line 3 def whitelisted_attrs @whitelisted_attrs end |
Instance Method Details
#allows?(args = {}) ⇒ Boolean
13 14 15 16 17 18 |
# File 'lib/redtape/attribute_whitelist.rb', line 13 def allows?(args = {}) allowed_attrs = whitelisted_attrs_for(args[:association_name]) || [] allowed_attrs = allowed_attrs.map(&:to_s) allowed_attrs << "id" allowed_attrs.include?(args[:attr].to_s) end |
#top_level_name ⇒ Object
9 10 11 |
# File 'lib/redtape/attribute_whitelist.rb', line 9 def top_level_name whitelisted_attrs.try(:keys).try(:first) end |