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