Class: ClassFactory

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

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.factoriesObject

Returns the value of attribute factories.



5
6
7
# File 'lib/class_factory/class_factory.rb', line 5

def factories
  @factories
end

Class Method Details

.create(name, options, block) ⇒ Object



11
12
13
14
15
# File 'lib/class_factory/class_factory.rb', line 11

def create(name, options, block)
  raise "No such class factory defined" if !factories.has_key?(name)
  options.merge!(:migration => block) if block
  factories[name].create(options)
end

.define(name, options = {}, &block) ⇒ Object



7
8
9
# File 'lib/class_factory/class_factory.rb', line 7

def define(name, options = {}, &block)
  factories[name] = self.new({ :name => name, :migration => block }.merge(options))
end

Instance Method Details

#create(override_options) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/class_factory/class_factory.rb', line 18

def create(override_options)
  @options = @definition.merge(override_options)
  @options[:super] = ActiveRecord::Base if @options[:super].nil?
  create_table if is_active_record?(@options[:super])
  klass = create_class
  klass.class_eval @options[:class_eval] if @options[:class_eval]
  klass
end