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

#factory_attribute(attr, value) ⇒ Object



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

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

#header(&block) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/to_factory/generation/factory.rb', line 20

def header(&block)
  if ToFactory.new_syntax?
    generic_header("  factory", "", "  end", &block)
  else
    generic_header("Factory.define", " |o|", "end", &block)
  end
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