Class: LazyFixtures::ValueMapper
- Inherits:
-
Object
- Object
- LazyFixtures::ValueMapper
- Defined in:
- lib/lazy_fixtures/value_mapper.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(object, key, value) ⇒ ValueMapper
constructor
A new instance of ValueMapper.
- #map_values ⇒ Object
- #remove_encrypted_attributes ⇒ Object
Constructor Details
#initialize(object, key, value) ⇒ ValueMapper
Returns a new instance of ValueMapper.
3 4 5 6 7 8 9 |
# File 'lib/lazy_fixtures/value_mapper.rb', line 3 def initialize(object, key, value) @object = object @object_class = @object.class.name.constantize @key = key @value = value remove_encrypted_attributes end |
Class Method Details
.remove_encrypted(key) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/lazy_fixtures/value_mapper.rb', line 30 def self.remove_encrypted(key) return_key = key if key =~ /(encrypted_)/ return_key.slice!($1) end return_key end |
Instance Method Details
#map_values ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lazy_fixtures/value_mapper.rb', line 19 def map_values type = @object_class.columns_hash[@key].type value = if @value.nil? "nil" elsif type == :string || type == :datetime || type == :text || type == :date "\'#{@value}\'" else @value end end |
#remove_encrypted_attributes ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/lazy_fixtures/value_mapper.rb', line 11 def remove_encrypted_attributes if @key =~ /(encrypted_)/ key = @key.dup key.slice!($1) @value = @object.send(key) end end |