Skip to content

Instantly share code, notes, and snippets.

@vapidbabble
Forked from stephencelis/minifacture.rb
Created January 12, 2010 19:54
Show Gist options
  • Save vapidbabble/275541 to your computer and use it in GitHub Desktop.
Save vapidbabble/275541 to your computer and use it in GitHub Desktop.
# Factory girl, relaxed.
module Miniskirt
mattr_reader :factories
@@factories = {}
class << self
def define(name)
factories[name.to_s] = {} and yield BasicObject.new.instance_eval(%{
def method_missing(name, value)
::Miniskirt.factories["#{name}"][name] = value
end
self
})
end
def build(name, attrs = {})
name.to_s.classify.constantize.new factories[name.to_s].merge(attrs)
end
def create(name, attrs = {})
build(name, attrs).tap { |record| record.save }
end
end
end
def Miniskirt(name, attrs = {})
Miniskirt.create(name, attrs)
end
Factory = Miniskirt
alias Factory Miniskirt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment