Class: LazyFixtures::AttributesManager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of AttributesManager.



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

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

Instance Method Details

#add_attributesObject



12
13
14
15
16
17
18
19
20
# File 'lib/lazy_fixtures/attributes_manager.rb', line 12

def add_attributes
  return_value = ''
  attributes.each do |k,v|
    value =  ValueMapper.new(@object, k.to_s.dup, v).map_values
    key = ValueMapper.remove_encrypted(k.to_s.dup)
    return_value += "    #{key} #{value}\n"
  end
  return_value
end

#delete_association_attributes(method) ⇒ Object



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

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

#eachObject



32
33
34
# File 'lib/lazy_fixtures/attributes_manager.rb', line 32

def each
  attributes
end

#manipulate_attributesObject



22
23
24
25
26
# File 'lib/lazy_fixtures/attributes_manager.rb', line 22

def manipulate_attributes
  @options[:skip_attr].each { |x|  attributes.delete(x)} unless @options[:skip_attr].empty?
  attributes.merge!(@options[:change_attr]) unless @options[:change_attr].empty?
  attributes
end