Sha256: 9f6fc4db4bf2e7fd31f6f2c49ca35c9e5dbd7c09dae411189a62cfe268e90357

Contents?: true

Size: 530 Bytes

Versions: 1

Compression:

Stored size: 530 Bytes

Contents

class Possibility < ActiveEntity::Base
  attr_accessor :id

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

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

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

  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
polutan-1.0.0 lib/polutan/possibility.rb