Module: Virtus::Mapper

Defined in:
lib/virtus/mapper.rb,
lib/virtus/mapper/version.rb

Constant Summary collapse

VERSION =
"0.3.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mapped_attributesObject (readonly)

Returns the value of attribute mapped_attributes.



10
11
12
# File 'lib/virtus/mapper.rb', line 10

def mapped_attributes
  @mapped_attributes
end

#nil_value_keysObject (readonly)

Returns the value of attribute nil_value_keys.



10
11
12
# File 'lib/virtus/mapper.rb', line 10

def nil_value_keys
  @nil_value_keys
end

Instance Method Details

#extend_with(mod) ⇒ Object



19
20
21
22
23
24
# File 'lib/virtus/mapper.rb', line 19

def extend_with(mod)
  attr_set = attribute_set
  self.extend(mod) # Virtus modifies attribute_set
  set_attr_values(attribute_set.collect(&:name))
  update_attribute_set(attr_set)
end

#initialize(attrs = {}) ⇒ Object



12
13
14
15
16
# File 'lib/virtus/mapper.rb', line 12

def initialize(attrs={})
  @mapped_attributes = HWIA.new(attrs)
  @nil_value_keys = @mapped_attributes.collect { |k, v| k if v.nil? }.compact
  super(prepare_attributes_for_assignment!(@mapped_attributes))
end