Module: Tenacity::OrmExt::Ripple::ClassMethods

Includes:
Helpers
Defined in:
lib/tenacity/orm_ext/ripple.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#_t_serialize_id_for_sql, #_t_serialize_ids, #id_class_for

Instance Attribute Details

#_t_belongs_to_associationsObject

Returns the value of attribute _t_belongs_to_associations.



54
55
56
# File 'lib/tenacity/orm_ext/ripple.rb', line 54

def _t_belongs_to_associations
  @_t_belongs_to_associations
end

#_t_has_many_associationsObject

Returns the value of attribute _t_has_many_associations.



53
54
55
# File 'lib/tenacity/orm_ext/ripple.rb', line 53

def _t_has_many_associations
  @_t_has_many_associations
end

#_t_has_one_associationsObject

Returns the value of attribute _t_has_one_associations.



52
53
54
# File 'lib/tenacity/orm_ext/ripple.rb', line 52

def _t_has_one_associations
  @_t_has_one_associations
end

Instance Method Details

#_t_delete(ids, run_callbacks = true) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/tenacity/orm_ext/ripple.rb', line 115

def _t_delete(ids, run_callbacks=true)
  docs = _t_find_bulk(ids)
  if run_callbacks
    docs.each { |doc| doc.destroy }
  else
    docs.each { |doc| doc.delete }
  end
end

#_t_find(id) ⇒ Object



60
61
62
# File 'lib/tenacity/orm_ext/ripple.rb', line 60

def _t_find(id)
  find(_t_serialize(id))
end

#_t_find_all_by_associate(property, id) ⇒ Object



80
81
82
# File 'lib/tenacity/orm_ext/ripple.rb', line 80

def _t_find_all_by_associate(property, id)
  find(_t_find_all_ids_by_associate(property, id)) || []
end

#_t_find_all_ids_by_associate(property, id) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/tenacity/orm_ext/ripple.rb', line 84

def _t_find_all_ids_by_associate(property, id)
  bucket = ::Ripple.client.bucket(_t_bucket_name(property))
  if bucket.exist?(id)
    object = bucket.get(id)
    object.data || []
  else
    []
  end
end

#_t_find_bulk(ids) ⇒ Object



64
65
66
67
68
# File 'lib/tenacity/orm_ext/ripple.rb', line 64

def _t_find_bulk(ids)
  objects = find(_t_serialize_ids(ids)) || []
  objects = [objects] unless objects.respond_to?(:each)
  objects.reject(&:nil?)
end

#_t_find_first_by_associate(property, id) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/tenacity/orm_ext/ripple.rb', line 70

def _t_find_first_by_associate(property, id)
  bucket = ::Ripple.client.bucket(_t_bucket_name(property))
  if bucket.exist?(id)
    object = bucket.get(id)
    find(object.data.first)
  else
    nil
  end
end

#_t_id_typeObject



56
57
58
# File 'lib/tenacity/orm_ext/ripple.rb', line 56

def _t_id_type
  String
end

#_t_initialize_belongs_to_association(association) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/tenacity/orm_ext/ripple.rb', line 107

def _t_initialize_belongs_to_association(association)
  @_t_belongs_to_associations ||= []
  @_t_belongs_to_associations << association

  property association.foreign_key, id_class_for(association)
  property association.polymorphic_type, String if association.polymorphic?
end

#_t_initialize_has_many_association(association) ⇒ Object



102
103
104
105
# File 'lib/tenacity/orm_ext/ripple.rb', line 102

def _t_initialize_has_many_association(association)
  @_t_has_many_associations ||= []
  @_t_has_many_associations << association
end

#_t_initialize_has_one_association(association) ⇒ Object



97
98
99
100
# File 'lib/tenacity/orm_ext/ripple.rb', line 97

def _t_initialize_has_one_association(association)
  @_t_has_one_associations ||= []
  @_t_has_one_associations << association
end

#_t_initialize_tenacityObject



94
95
# File 'lib/tenacity/orm_ext/ripple.rb', line 94

def _t_initialize_tenacity
end