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



36
37
38
# File 'lib/to_factory/generation/factory.rb', line 36

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?
    modern_header &block
  else
    header_factory_girl_1 &block
  end
end

#header_factory_girl_1(&block) ⇒ Object



32
33
34
# File 'lib/to_factory/generation/factory.rb', line 32

def header_factory_girl_1(&block)
  generic_header("Factory.define", " |o|", &block)
end

#modern_header(&block) ⇒ Object



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

def modern_header(&block)
  generic_header("factory", "", &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