Class: ToFactory::Generation::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/to_factory/generation/factory.rb

Instance Method Summary collapse

Constructor Details

#initialize(representation) ⇒ Factory

Returns a new instance of Factory.



4
5
6
# File 'lib/to_factory/generation/factory.rb', line 4

def initialize(representation)
  @representation = representation
end

Instance Method Details

#attributesObject



28
29
30
31
32
# File 'lib/to_factory/generation/factory.rb', line 28

def attributes
  to_skip = [:id, :created_at, :created_on, :updated_at, :updated_on]

  @representation.attributes.delete_if{|key, _| key.nil? || to_skip.include?(key.to_sym)}
end

#factory_attribute(attr, value) ⇒ Object



24
25
26
# File 'lib/to_factory/generation/factory.rb', line 24

def factory_attribute(attr, value)
  Attribute.new(attr, value).to_s
end

#header(&block) ⇒ Object



20
21
22
# File 'lib/to_factory/generation/factory.rb', line 20

def header(&block)
  generic_header("  factory", "", "  end", &block)
end

#nameObject



8
9
10
# File 'lib/to_factory/generation/factory.rb', line 8

def name
  add_quotes @representation.name
end

#to_factoryObject



12
13
14
15
16
17
18
# File 'lib/to_factory/generation/factory.rb', line 12

def to_factory
  header do
    attributes.map do |attr, value|
      factory_attribute(attr, value)
    end.sort.join("\n") << "\n"
  end
end