Class: FactoryGirl::Syntax::Default::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/baja.rb

Instance Method Summary collapse

Instance Method Details

#factory(name, options = {}, &block) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/baja.rb', line 90

def factory(name, options = {}, &block)  
  options[:class] = name.to_s.gsub(/_list/,'') unless options.has_key?(:class) 
  name = :"#{@namespace}___#{name.to_s}" unless @namespace.nil?

  unless @namespace.nil?
    name = :"#{@namespace}__#{name.to_s}" 
  else
    puts "#{Baja::Blast.baja.as_json}"
    unless Baja::Blast.baja[:factories].nil?
      Baja::Blast.baja[:factories].each do |dew|            
        if FactoryLoad.path.include?(dew[:name])            
          name = :"#{dew[:name]}__#{name.to_s}" 
        end            
      end
    end        
  end
  puts "name: #{name}"
  factory = FactoryGirl::Factory.new(name, options)
  proxy = FactoryGirl::DefinitionProxy.new(factory.definition)
  proxy.instance_eval(&block) if block_given?

  FactoryGirl.register_factory(factory)

  proxy.child_factories.each do |(child_name, child_options, child_block)|
    parent_factory = child_options.delete(:parent) || name
    factory(child_name, child_options.merge(parent: parent_factory), &child_block)
  end
end

#namespace(name) ⇒ Object



86
87
88
89
# File 'lib/baja.rb', line 86

def namespace(name)
  @namespace = name.to_s
  yield
end