Class: Tango::AbstractModel

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/tango/abstract_model.rb

Overview

Base model for Tango resources

Author:

  • Mckomo

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_idInteger

Return incremented value of last id in the model’s table

Returns:

  • (Integer)


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

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/tango/abstract_model.rb', line 47

def self.persistent?
  raise NotImplementedError
end

.propertiesArray

Return array with names of model properties

Returns:

  • (Array)


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_keyObject

Return cache key of model instance

Returns:

  • (Object)

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/tango/abstract_model.rb', line 24

def cache_key
  raise NotImplementedError
end

#valuesArray

Return array with values of model properties

Returns:

  • (Array)


17
18
19
# File 'lib/tango/abstract_model.rb', line 17

def values
  self.attributes.values
end