class ToFactory::Generation::Factory
Public Class Methods
new(representation)
click to toggle source
# File lib/to_factory/generation/factory.rb, line 4 def initialize(representation) @representation = representation end
Public Instance Methods
attributes()
click to toggle source
# 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)
click to toggle source
# File lib/to_factory/generation/factory.rb, line 24 def factory_attribute(attr, value) Attribute.new(attr, value).to_s end
header(&block)
click to toggle source
# File lib/to_factory/generation/factory.rb, line 20 def header(&block) generic_header(" factory", "", " end", &block) end
name()
click to toggle source
# File lib/to_factory/generation/factory.rb, line 8 def name add_quotes @representation.name end
to_factory()
click to toggle source
# 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
Private Instance Methods
add_quotes(name)
click to toggle source
# File lib/to_factory/generation/factory.rb, line 54 def add_quotes(name) name = name.to_s if name["/"] if name[/^".*"$/] name else "\"#{name}\"" end else name end end
generic_header(factory_start, block_arg, ending) { || ... }
click to toggle source
# File lib/to_factory/generation/factory.rb, line 40 def generic_header(factory_start, block_arg, ending, &block) out = "#{factory_start}(:#{name}#{parent_clause}) do#{block_arg}\n" out << yield.to_s out << "#{ending}\n" end
has_parent?()
click to toggle source
# File lib/to_factory/generation/factory.rb, line 50 def has_parent? parent_name.to_s.length > 0 end
parent_clause()
click to toggle source
# File lib/to_factory/generation/factory.rb, line 46 def parent_clause has_parent? ? ", :parent => :#{add_quotes parent_name}" : "" end
parent_name()
click to toggle source
# File lib/to_factory/generation/factory.rb, line 36 def parent_name @representation.parent_name end