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
-
#mapped_attributes ⇒ Object
readonly
Returns the value of attribute mapped_attributes.
-
#nil_value_keys ⇒ Object
readonly
Returns the value of attribute nil_value_keys.
Instance Method Summary collapse
-
#extend_with(mod) ⇒ Object
A workaround for github.com/solnic/virtus/issues/266.
- #initialize(attrs = {}) ⇒ Object
Instance Attribute Details
#mapped_attributes ⇒ Object (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_keys ⇒ Object (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
A workaround for github.com/solnic/virtus/issues/266
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 |