Class: Redtape::AttributeWhitelist

Inherits:
Object
  • Object
show all
Defined in:
lib/redtape/attribute_whitelist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_attrsObject (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

Returns:

  • (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_nameObject



9
10
11
# File 'lib/redtape/attribute_whitelist.rb', line 9

def top_level_name
  whitelisted_attrs.try(:keys).try(:first)
end