Class: Tango::AbstractModel
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Tango::AbstractModel
- Defined in:
- lib/tango/abstract_model.rb
Overview
Base model for Tango resources
Class Method Summary collapse
-
.next_id ⇒ Integer
Return incremented value of last id in the model’s table.
-
.persistent? ⇒ Boolean
State wether model should be cached or not.
-
.properties ⇒ Array
Return array with names of model properties.
Instance Method Summary collapse
-
#cache_key ⇒ Object
Return cache key of model instance.
-
#values ⇒ Array
Return array with values of model properties.
Class Method Details
.next_id ⇒ Integer
Return incremented value of last id in the model’s table
38 39 40 41 |
# File 'lib/tango/abstract_model.rb', line 38 def self.next_id @last_id ||= self.pluck( :id ).last || 0 @last_id += 1 end |
.persistent? ⇒ Boolean
Note:
If model is not persistent, model’s table will be truncated
State wether model should be cached or not
47 48 49 |
# File 'lib/tango/abstract_model.rb', line 47 def self.persistent? raise NotImplementedError end |
.properties ⇒ Array
Return array with names of model properties
31 32 33 |
# File 'lib/tango/abstract_model.rb', line 31 def self.properties @properties || @properties = self.attribute_names.map { |a| a.to_sym } end |
Instance Method Details
#cache_key ⇒ Object
Return cache key of model instance
24 25 26 |
# File 'lib/tango/abstract_model.rb', line 24 def cache_key raise NotImplementedError end |
#values ⇒ Array
Return array with values of model properties
17 18 19 |
# File 'lib/tango/abstract_model.rb', line 17 def values self.attributes.values end |