Module: Riik::Document

Defined in:
lib/riik/document.rb,
lib/riik/document/finders.rb,
lib/riik/document/persistence.rb

Overview

Document is the base object for the Riik ORM. Including it provides the basic functionality for assigning attributes to models, assigning a bucket name, and serializing objects.

Defined Under Namespace

Modules: ClassMethods, Finders, Persistence

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#robjectRiak::RObject

Create or return the current Riak client object.

Returns:

  • (Riak::RObject)


102
103
104
# File 'lib/riik/document.rb', line 102

def robject
  @robject
end

Class Method Details

.included(base) ⇒ Object



11
12
13
14
15
16
# File 'lib/riik/document.rb', line 11

def self.included(base)
  base.send :extend, ClassMethods

  base.send :include, Finders
  base.send :include, Persistence
end

Instance Method Details

#attributesHash

Serialize the attributes of this model.

Returns:

  • (Hash)

    serialized attributes.



71
72
73
# File 'lib/riik/document.rb', line 71

def attributes
  Hash[riik_attributes.zip(riik_attributes.map { |attr| instance_variable_get "@#{attr}" })]
end

#bucketRiak::Bucket

Return the bucket for this class.

Returns:

  • (Riak::Bucket)


88
89
90
# File 'lib/riik/document.rb', line 88

def bucket
  self.class.bucket
end

#initialize(attributes = {}) ⇒ Object

Assign model attributes through initialization hash.

Parameters:

  • attributes (Hash) (defaults to: {})


58
59
60
61
62
63
64
# File 'lib/riik/document.rb', line 58

def initialize(attributes = {})
  attributes.symbolize_keys.each do |key, value|
    if riik_attributes.include?(key)
      instance_variable_set "@#{key}", value
    end
  end
end

#keyString

Delegate the object key to the Riak object.

Returns:

  • (String)


96
97
98
# File 'lib/riik/document.rb', line 96

def key
  robject.key
end

#riik_attributesArray

Return the riik attribute list for this class.

Returns:

  • (Array)

    symbols for each model property.



80
81
82
# File 'lib/riik/document.rb', line 80

def riik_attributes
  self.class.riik_attributes
end