Class: Capabilities::Cacheable

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
app/models/capabilities.rb

Constant Summary collapse

ATTRS =

Changing this order will break serialization of cached data

[:max_gears, :consumed_gears, :gear_sizes].each{ |s| attr_reader s }

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#gears_free, #gears_free?

Constructor Details

#initialize(*args) ⇒ Cacheable

Returns a new instance of Cacheable.



33
34
35
36
37
# File 'app/models/capabilities.rb', line 33

def initialize(*args)
  arg = args.each
  ATTRS.each{ |t| send("#{t}=", arg.next) }
rescue StopIteration
end

Class Method Details

.from(obj) ⇒ Object



39
40
41
# File 'app/models/capabilities.rb', line 39

def self.from(obj)
  new(*(obj.is_a?(Array) ? obj : ATTRS.map{ |s| obj.send(s) })) if obj
end

Instance Method Details

#to_aObject



47
48
49
# File 'app/models/capabilities.rb', line 47

def to_a
  ATTRS.map{ |s| send(s) }
end

#to_capabilitiesObject



43
44
45
# File 'app/models/capabilities.rb', line 43

def to_capabilities
  self
end