Class: ActiveFactory::FactoryDSL
- Inherits:
-
Object
- Object
- ActiveFactory::FactoryDSL
show all
- Defined in:
- lib/active_factory.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of FactoryDSL.
49
50
51
|
# File 'lib/active_factory.rb', line 49
def initialize
@attribute_expressions = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &expression) ⇒ Object
65
66
67
68
69
70
|
# File 'lib/active_factory.rb', line 65
def method_missing method, *args, &expression
if args.many? or args.any? and block_given?
raise "should be either block or value: #{method} #{args.inspect[1..-2]}"
end
@attribute_expressions[method.to_sym] = expression || proc { args[0] }
end
|
Instance Method Details
#after_build(&callback) ⇒ Object
57
58
59
|
# File 'lib/active_factory.rb', line 57
def after_build &callback
@after_build = callback
end
|
#before_save(&callback) ⇒ Object
61
62
63
|
# File 'lib/active_factory.rb', line 61
def before_save &callback
@before_save = callback
end
|
#prefer_associations(*assoc_symbols) ⇒ Object
53
54
55
|
# File 'lib/active_factory.rb', line 53
def prefer_associations *assoc_symbols
@prefer_associations = assoc_symbols
end
|