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
-
#initialize(representation) ⇒ Factory
constructor
A new instance of Factory.
- #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
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 |
#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 |