Module: Castkit::ActiveRecord::ClassMethods
- Includes:
- Serialization
- Defined in:
- lib/castkit/active_record.rb
Overview
Defines class-level behavior for ActiveRecord integration.
Instance Method Summary collapse
-
#ensure_model_defined!(klass = self) ⇒ Object
Ensures that a model has been defined for the given DataObject class.
-
#ensure_model_type!(obj, klass = self) ⇒ Object
Ensures that the given object is an instance of the associated model class.
-
#model(model = nil) ⇒ Class
Defines or returns the ActiveRecord model class associated with the DataObject.
Methods included from Serialization
#from_model, #from_relation, #nested_associations
Instance Method Details
#ensure_model_defined!(klass = self) ⇒ Object
Ensures that a model has been defined for the given DataObject class.
56 57 58 |
# File 'lib/castkit/active_record.rb', line 56 def ensure_model_defined!(klass = self) raise Castkit::ActiveRecord::ModelNotDefined, klass unless klass.model end |
#ensure_model_type!(obj, klass = self) ⇒ Object
Ensures that the given object is an instance of the associated model class.
66 67 68 69 |
# File 'lib/castkit/active_record.rb', line 66 def ensure_model_type!(obj, klass = self) ensure_model_defined!(klass) raise Castkit::ActiveRecord::InvalidModel.new(model, obj) unless obj.is_a?(model) end |
#model(model = nil) ⇒ Class
Defines or returns the ActiveRecord model class associated with the DataObject.
48 49 50 |
# File 'lib/castkit/active_record.rb', line 48 def model(model = nil) model ? (@model_class = model) : @model_class end |