Class: AllFutures

Inherits:
ActiveEntity::Base
  • Object
show all
Defined in:
lib/all_futures/all_futures.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ AllFutures

Returns a new instance of AllFutures.



4
5
6
7
8
9
10
# File 'lib/all_futures/all_futures.rb', line 4

def initialize(attributes={})
  super
  unless @id
    @id = SecureRandom.uuid
    save
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



2
3
4
# File 'lib/all_futures/all_futures.rb', line 2

def id
  @id
end

Class Method Details

.find(id) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
27
# File 'lib/all_futures/all_futures.rb', line 22

def self.find(id)
  raise ArgumentError unless id
  json = Kredis.json("#{name}:#{id}").value
  raise ActiveRecord::RecordNotFound unless json
  new json.merge(id: id)
end

Instance Method Details

#[]=(attr_name, value) ⇒ Object



12
13
14
15
# File 'lib/all_futures/all_futures.rb', line 12

def []=(attr_name, value)
  super
  save
end

#saveObject



17
18
19
20
# File 'lib/all_futures/all_futures.rb', line 17

def save
  Kredis.json("#{self.class.name}:#{@id}").value = self.attributes
  changes_applied
end