lib/with_model/model.rb in with_model-1.0.0 vs lib/with_model/model.rb in with_model-1.1.0
- old
+ new
@@ -1,5 +1,6 @@
+require 'active_record'
require 'active_support/core_ext/string/inflections'
require 'with_model/constant_stubber'
require 'with_model/methods'
require 'with_model/table'
@@ -8,29 +9,26 @@
attr_writer :model_block, :table_block, :table_options
def initialize name, options = {}
@name = name.to_sym
@options = options
- @model_block = proc {}
- @table_block = proc {}
+ @model_block = nil
+ @table_block = nil
@table_options = {}
end
def create
table.create
- @model = Class.new(superclass)
-
- class << @model
- include WithModel::Methods
+ @model = Class.new(superclass) do
+ extend WithModel::Methods
end
-
stubber.stub_const @model
setup_model
end
def superclass
- @options.fetch(:superclass) { ActiveRecord::Base }
+ @options.fetch(:superclass, ActiveRecord::Base)
end
def destroy
stubber.unstub_const
remove_from_superclass_descendants
@@ -45,10 +43,10 @@
@name.to_s.camelize.freeze
end
def setup_model
@model.table_name = table_name
- @model.class_eval(&@model_block)
+ @model.class_eval(&@model_block) if @model_block
@model.reset_column_information
end
def remove_from_superclass_descendants
return unless @model.superclass.respond_to?(:direct_descendants)