Class: LazyFixtures::FactoryGirl::AttributesManager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, options = {}) ⇒ AttributesManager

Returns a new instance of AttributesManager.



8
9
10
11
12
13
# File 'lib/lazy_fixtures/factory_girl/attributes_manager.rb', line 8

def initialize(object, options={})
  @object = object
  @attributes = @object.attributes
  @options    = options
  manipulate_attributes
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



5
6
7
# File 'lib/lazy_fixtures/factory_girl/attributes_manager.rb', line 5

def attributes
  @attributes
end

#objectObject (readonly)

Returns the value of attribute object.



6
7
8
# File 'lib/lazy_fixtures/factory_girl/attributes_manager.rb', line 6

def object
  @object
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/lazy_fixtures/factory_girl/attributes_manager.rb', line 6

def options
  @options
end

Instance Method Details

#delete_association_attributesObject



27
28
29
# File 'lib/lazy_fixtures/factory_girl/attributes_manager.rb', line 27

def delete_association_attributes
  attributes.delete_if {|k,v| k =~ Regexp.new(/.+_id/) && !v.nil?}
end

#eachObject



15
16
17
# File 'lib/lazy_fixtures/factory_girl/attributes_manager.rb', line 15

def each
  attributes
end

#stringify_attributesObject



19
20
21
22
23
24
25
# File 'lib/lazy_fixtures/factory_girl/attributes_manager.rb', line 19

def stringify_attributes
  attributes.map do |k,v|
    value =  ValueMapper.new(object, k.to_s.dup, v).get_value
    key = ValueMapper.remove_encrypted(k.to_s.dup)
    "    #{key} #{value}\n"
  end.join
end