Class: Damsel::AttributeSet

Inherits:
Object
  • Object
show all
Defined in:
lib/damsel/attribute_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttributeSet

Returns a new instance of AttributeSet.



5
6
7
# File 'lib/damsel/attribute_set.rb', line 5

def initialize
  @attrs = {}
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



3
4
5
# File 'lib/damsel/attribute_set.rb', line 3

def attrs
  @attrs
end

Instance Method Details

#<<(attribute) ⇒ Object



9
10
11
# File 'lib/damsel/attribute_set.rb', line 9

def <<(attribute)
  @attrs[attribute.name] = attribute
end

#[](name) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/damsel/attribute_set.rb', line 13

def [](name)
  return @attrs[name] if @attrs[name]
  singular = name.to_s.singularize.to_sym
  return @attrs[singular] if @attrs[singular]
  plural = name.to_s.pluralize.to_sym
  return @attrs[plural] if @attrs[plural]
  raise "unknown attribute: #{name} (#{singular} #{plural})"
end