Class: DataMapper::NestedAttributes::BackwardsCompatibilityHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/dm-accepts_nested_attributes/model.rb

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ BackwardsCompatibilityHash

Returns a new instance of BackwardsCompatibilityHash.



4
5
6
# File 'lib/dm-accepts_nested_attributes/model.rb', line 4

def initialize(model)
  @model = model
end

Instance Method Details

#[](key) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/dm-accepts_nested_attributes/model.rb', line 8

def [](key)
  if key.is_a?(DataMapper::Associations::Relationship)
    warn "#{@model}#options_for_nested_attributes: Using a relationship " +
         "as key is deprecated. Use the relationship name (i.e. " +
         "#{key.name.inspect}) as key."
    key = key.name
  end
  super(key)
end

#[]=(key, value) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/dm-accepts_nested_attributes/model.rb', line 18

def []=(key, value)
  if key.is_a?(DataMapper::Associations::Relationship)
    warn "#{@model}#options_for_nested_attributes: Using a relationship " +
         "as key is deprecated. Use the relationship name (i.e. " +
         "#{key.name.inspect}) as key."
    key = key.name
  end
  super(key, value)
end