Module: Ork::Document

Defined in:
lib/ork/model/document.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/ork/model/document.rb', line 6

def id
  @id
end

Class Method Details

.included(klass) ⇒ Object



8
9
10
11
# File 'lib/ork/model/document.rb', line 8

def self.included(klass)
  klass.send(:include, Ork::Model)
  klass.extend(Ork::Model::Finders)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Check for equality by doing the following assertions:

  1. That the passed model is of the same type.

  2. That they represent the same RObject id.



18
19
20
# File 'lib/ork/model/document.rb', line 18

def ==(other)
  other.kind_of?(model) && other.id == id
end

#deleteObject

Delete the model



91
92
93
94
95
96
# File 'lib/ork/model/document.rb', line 91

def delete
  __robject.delete unless new?
  freeze
rescue Riak::FailedRequest
  false
end

#embeddable?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ork/model/document.rb', line 27

def embeddable?
  false
end

#inspectObject

Pretty print for the model

Example:

  User.new(name: 'John').inspect
  # => #<User:6kS5VHNbaed9h7gFLnVg5lmO4U7 {:name=>"John"}>


37
38
39
# File 'lib/ork/model/document.rb', line 37

def inspect
  "#<#{model}:#{id || 'nil'} #{attributes.inspect}>"
end

#new?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ork/model/document.rb', line 23

def new?
  !id
end

#reloadObject

Preload all the attributes of this model from Riak.



86
87
88
# File 'lib/ork/model/document.rb', line 86

def reload
  new? ? self : self.load!(@id)
end

#saveObject

Persist the model attributes and update indices and unique indices.

Example:

class User
  include Ork::Document

  attribute :name
end

u = User.new(:name => "John").save
# => #<User:6kS5VHNbaed9h7gFLnVg5lmO4U7 {:name=>"John"}>


72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ork/model/document.rb', line 72

def save
  __robject.content_type = model.content_type
  __robject.data = __persist_attributes

  __check_unique_indices
  __update_indices
  __robject.store

  @id = __robject.key

  self
end

#update(attributes) ⇒ Object

Update the model attributes and call save.

Example:

User[1].update(:name => "John")

# It's the same as:

u = User[1]
u.update_attributes(:name => "John")
u.save


53
54
55
56
# File 'lib/ork/model/document.rb', line 53

def update(attributes)
  update_attributes(attributes)
  save
end