Method: Maxiskirt.build
- Defined in:
- lib/maxiskirt.rb
.build(name, params = {}) ⇒ Object
Initialize and setup class from factory.
You can override default factory settings, by passing them as second argument.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/maxiskirt.rb', line 51 def build(name, params = {}) factory = @factories[name.to_s] klass = factory.__klass__ parent = factory.__parent__ attributes = attributes_for(name, params) # If parent set, then merge parent template with current template if parent klass = @factories[parent.to_s].__klass__ end # Convert klass to real Class klass = klass.is_a?(Class) ? klass : klass.to_s.classify.constantize object = klass.new attributes.each do |name, value| object.send(:"#{name}=", value) end return object end |