Class: WithModel::Model
- Inherits:
-
Object
- Object
- WithModel::Model
- Defined in:
- lib/with_model/model.rb,
lib/with_model/model/dsl.rb
Overview
In general, direct use of this class should be avoided. Instead use either the high-level API or low-level API.
Defined Under Namespace
Classes: DSL
Instance Attribute Summary collapse
-
#model_block ⇒ Object
writeonly
Sets the attribute model_block.
-
#table_block ⇒ Object
writeonly
Sets the attribute table_block.
-
#table_options ⇒ Object
writeonly
Sets the attribute table_options.
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
-
#initialize(name, superclass: ActiveRecord::Base) ⇒ Model
constructor
A new instance of Model.
Constructor Details
#initialize(name, superclass: ActiveRecord::Base) ⇒ Model
Returns a new instance of Model.
21 22 23 24 25 26 27 |
# File 'lib/with_model/model.rb', line 21 def initialize(name, superclass: ActiveRecord::Base) @name = name.to_sym @model_block = nil @table_block = nil @table_options = {} @superclass = superclass end |
Instance Attribute Details
#model_block=(value) ⇒ Object (writeonly)
Sets the attribute model_block
16 17 18 |
# File 'lib/with_model/model.rb', line 16 def model_block=(value) @model_block = value end |
#table_block=(value) ⇒ Object (writeonly)
Sets the attribute table_block
16 17 18 |
# File 'lib/with_model/model.rb', line 16 def table_block=(value) @table_block = value end |
#table_options=(value) ⇒ Object (writeonly)
Sets the attribute table_options
16 17 18 |
# File 'lib/with_model/model.rb', line 16 def (value) @table_options = value end |
Instance Method Details
#create ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/with_model/model.rb', line 29 def create table.create @model = Class.new(@superclass) do extend WithModel::Methods end stubber.stub_const @model setup_model end |
#destroy ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/with_model/model.rb', line 38 def destroy stubber.unstub_const cleanup_descendants_tracking reset_dependencies_cache table.destroy WithModel::DescendantsTracker.clear([@model]) @model = nil end |