Class: Redis::ORM

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks, ActiveModel::Naming
Includes:
ActiveModel::Validations, Actions, Attributes, Relations, Validations
Defined in:
lib/redis/orm.rb,
lib/redis/orm/version.rb,
lib/redis/orm/attributes.rb

Defined Under Namespace

Modules: Attributes, Version

Constant Summary collapse

VERSION =
Version::STRING

Instance Method Summary collapse

Methods included from Validations

included

Methods included from Relations

included

Methods included from Actions

included

Methods included from Attributes

#attribute_names, #attributes, #attributes=, #changed?, included, #new_record?, #previous_attributes, #set_unchanged!

Constructor Details

#initialize(attributes = {}) ⇒ ORM

Returns a new instance of ORM.



45
46
47
48
49
50
# File 'lib/redis/orm.rb', line 45

def initialize(attributes = {})
  run_callbacks :initialize do
    self.attributes = attributes
    @previous_attributes = nil
  end
end

Instance Method Details

#==(other) ⇒ Object



56
57
58
# File 'lib/redis/orm.rb', line 56

def ==(other)
  other && key == other.key
end

#persisted?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/redis/orm.rb', line 41

def persisted?
  !new_record? && !changed?
end

#to_keyObject



33
34
35
# File 'lib/redis/orm.rb', line 33

def to_key
  persisted? ? key : nil
end

#to_paramObject



37
38
39
# File 'lib/redis/orm.rb', line 37

def to_param
  persisted? ? File.join(model_name, key) : nil
end

#transaction(&block) ⇒ Object



52
53
54
# File 'lib/redis/orm.rb', line 52

def transaction(&block)
  connection.multi &block
end