Class: LazyFixtures::FactoryGirl::ValueMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/lazy_fixtures/factory_girl/value_mapper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#keyObject (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

#objectObject (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_classObject (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_valueObject



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_attributesObject



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