lib/temping.rb in temping-3.3.1 vs lib/temping.rb in temping-3.4.0
- old
+ new
@@ -2,12 +2,12 @@
require "active_support/core_ext/string"
class Temping
@model_klasses = []
- def self.create(model_name, &block)
- factory = ModelFactory.new(model_name.to_s.classify, &block)
+ def self.create(model_name, options = {}, &block)
+ factory = ModelFactory.new(model_name.to_s.classify, options, &block)
klass = factory.klass
@model_klasses << klass
klass
end
@@ -20,12 +20,13 @@
end
@model_klasses.clear
end
class ModelFactory
- def initialize(model_name, &block)
+ def initialize(model_name, options = {}, &block)
@model_name = model_name
+ @options = options
klass.class_eval(&block) if block_given?
klass.reset_column_information
end
def klass
@@ -39,16 +40,17 @@
def build
Class.new(ActiveRecord::Base).tap do |klass|
Object.const_set(@model_name, klass)
klass.primary_key = :id
- create_table
+ create_table(@options)
add_methods
end
end
- def create_table
- connection.create_table(table_name, :temporary => true)
+ DEFAULT_OPTIONS = { :temporary => true }
+ def create_table(options = {})
+ connection.create_table(table_name, DEFAULT_OPTIONS.merge(options))
end
def add_methods
class << klass
def with_columns