Class: ToFactory::Generation::Factory
- Inherits:
-
Object
- Object
- ToFactory::Generation::Factory
- Defined in:
- lib/to_factory/generation/factory.rb
Instance Method Summary collapse
- #factory_attribute(attr, value) ⇒ Object
- #header(&block) ⇒ Object
- #header_factory_girl_1(&block) ⇒ Object
-
#initialize(representation) ⇒ Factory
constructor
A new instance of Factory.
- #modern_header(&block) ⇒ Object
- #name ⇒ Object
- #to_factory ⇒ Object
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 |
#name ⇒ Object
8 9 10 |
# File 'lib/to_factory/generation/factory.rb', line 8 def name add_quotes @representation.name end |
#to_factory ⇒ Object
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 |