class Traver::TraverConstructor

Attributes

factories_store[R]
sequencer[R]

Public Class Methods

new() click to toggle source
# File lib/traver/traver_constructor.rb, line 5
def initialize
  @factories_store = FactoriesStore.new
  @sequencer       = Sequencer.new
end

Public Instance Methods

create(*options) click to toggle source
# File lib/traver/traver_constructor.rb, line 16
def create(*options)
  factory_name, params = parse_create_options(options)
  
  ObjectCreator.create_object(factory_name, params, factories_store, sequencer)
end
create_graph(*options) click to toggle source
# File lib/traver/traver_constructor.rb, line 22
def create_graph(*options)
  factory_name, params = parse_create_options(options)

  graph_creator = GraphCreator.new(factory_name, params, factories_store, sequencer)
  graph_creator.create_graph

  graph_creator.graph
end
create_list(num, *options) click to toggle source
# File lib/traver/traver_constructor.rb, line 31
def create_list(num, *options)
  factory_name, params = parse_create_options(options)
  
  list_creator = ListCreator.new(num, factory_name, params, factories_store, sequencer)
  list_creator.create_list
  
  list_creator.list
end
define_factories(&block) click to toggle source
# File lib/traver/traver_constructor.rb, line 40
def define_factories(&block)
  instance_exec(&block)
end
Also aliased as: factories
define_factory(factory_name, *options) click to toggle source
# File lib/traver/traver_constructor.rb, line 46
def define_factory(factory_name, *options)
  parent_factory_name, params = parse_factory_options(options)

  factories_store.define_factory(factory_name, parent_factory_name, params)
end
Also aliased as: factory
factories(&block)
Alias for: define_factories
factories_count() click to toggle source
# File lib/traver/traver_constructor.rb, line 58
def factories_count
  factories_store.factories_count
end
factory(factory_name, *options)
Alias for: define_factory
include(*modules) click to toggle source
# File lib/traver/traver_constructor.rb, line 10
def include(*modules)
  modules.each do |mod|
    self.class.include(mod)
  end
end
undefine_all_factories() click to toggle source
# File lib/traver/traver_constructor.rb, line 54
def undefine_all_factories
  factories_store.undefine_all_factories
end

Private Instance Methods

factory_girl_options?(options) click to toggle source
# File lib/traver/traver_constructor.rb, line 72
def factory_girl_options?(options)
  options.first.is_a?(Symbol)
end
parse_create_options(options) click to toggle source
# File lib/traver/traver_constructor.rb, line 64
def parse_create_options(options)
  if factory_girl_options?(options)
    parse_factory_girl_options(options)
  else
    parse_traver_options(options)
  end
end
parse_factory_girl_options(options) click to toggle source
# File lib/traver/traver_constructor.rb, line 76
def parse_factory_girl_options(options)
  factory_name, params = options
  params ||= {}
  
  [factory_name, params]
end
parse_factory_options(options) click to toggle source
# File lib/traver/traver_constructor.rb, line 87
def parse_factory_options(options)
  parent_factory_name = nil

  if options.size == 1
    params = options.first
  elsif options.size == 2
    parent_factory_name, params = options
  end
  
  [parent_factory_name, params]
end
parse_traver_options(options) click to toggle source
# File lib/traver/traver_constructor.rb, line 83
def parse_traver_options(options)
  options.first.first
end