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)
-
+ (Integer) next_id
Return incremented value of last id in the model's table.
-
+ (Boolean) persistent?
State wether model should be cached or not.
-
+ (Array) properties
Return array with names of model properties.
Instance Method Summary (collapse)
-
- (Object) cache_key
Return cache key of model instance.
-
- (Array) values
Return array with values of model properties.
Class Method Details
+ (Integer) next_id
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 |
+ (Boolean) persistent?
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 |
+ (Array) properties
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
- (Object) cache_key
Return cache key of model instance
24 25 26 |
# File 'lib/tango/abstract_model.rb', line 24 def cache_key raise NotImplementedError end |
- (Array) values
Return array with values of model properties
17 18 19 |
# File 'lib/tango/abstract_model.rb', line 17 def values self.attributes.values end |