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.
19 20 21 22 23 24 25 |
# File 'lib/with_model/model.rb', line 19 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
14 15 16 |
# File 'lib/with_model/model.rb', line 14 def model_block=(value) @model_block = value end |
#table_block=(value) ⇒ Object (writeonly)
Sets the attribute table_block
14 15 16 |
# File 'lib/with_model/model.rb', line 14 def table_block=(value) @table_block = value end |
#table_options=(value) ⇒ Object (writeonly)
Sets the attribute table_options
14 15 16 |
# File 'lib/with_model/model.rb', line 14 def (value) @table_options = value end |
Instance Method Details
#create ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/with_model/model.rb', line 27 def create table.create @model = Class.new(@superclass) do extend WithModel::Methods end stubber.stub_const @model setup_model end |
#destroy ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/with_model/model.rb', line 36 def destroy stubber.unstub_const cleanup_descendants_tracking reset_dependencies_cache table.destroy @model = nil end |