ripple 0.9.5 → 1.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +32 -0
- data/Gemfile +10 -9
- data/Guardfile +15 -0
- data/Rakefile +11 -40
- data/lib/rails/generators/ripple/configuration/configuration_generator.rb +0 -13
- data/lib/rails/generators/ripple/configuration/templates/ripple.yml +4 -4
- data/lib/rails/generators/ripple/js/js_generator.rb +0 -13
- data/lib/rails/generators/ripple/js/templates/js/contrib.js +0 -17
- data/lib/rails/generators/ripple/js/templates/js/ripple.js +0 -13
- data/lib/rails/generators/ripple/model/model_generator.rb +0 -14
- data/lib/rails/generators/ripple/model/templates/model.rb +1 -1
- data/lib/rails/generators/ripple/observer/observer_generator.rb +0 -14
- data/lib/rails/generators/ripple/test/test_generator.rb +7 -19
- data/lib/rails/generators/ripple_generator.rb +1 -14
- data/lib/ripple.rb +7 -14
- data/lib/ripple/associations.rb +129 -26
- data/lib/ripple/associations/embedded.rb +1 -15
- data/lib/ripple/associations/instantiators.rb +0 -13
- data/lib/ripple/associations/linked.rb +41 -19
- data/lib/ripple/associations/many.rb +0 -14
- data/lib/ripple/associations/many_embedded_proxy.rb +0 -14
- data/lib/ripple/associations/many_linked_proxy.rb +39 -18
- data/lib/ripple/associations/many_reference_proxy.rb +93 -0
- data/lib/ripple/associations/many_stored_key_proxy.rb +76 -0
- data/lib/ripple/associations/one.rb +1 -15
- data/lib/ripple/associations/one_embedded_proxy.rb +0 -14
- data/lib/ripple/associations/one_key_proxy.rb +58 -0
- data/lib/ripple/associations/one_linked_proxy.rb +4 -14
- data/lib/ripple/associations/one_stored_key_proxy.rb +43 -0
- data/lib/ripple/associations/proxy.rb +8 -14
- data/lib/ripple/attribute_methods.rb +19 -17
- data/lib/ripple/attribute_methods/dirty.rb +19 -15
- data/lib/ripple/attribute_methods/query.rb +0 -14
- data/lib/ripple/attribute_methods/read.rb +0 -14
- data/lib/ripple/attribute_methods/write.rb +0 -14
- data/lib/ripple/callbacks.rb +10 -16
- data/lib/ripple/conflict/basic_resolver.rb +82 -0
- data/lib/ripple/conflict/document_hooks.rb +20 -0
- data/lib/ripple/conflict/resolver.rb +71 -0
- data/lib/ripple/conflict/test_helper.rb +33 -0
- data/lib/ripple/conversion.rb +0 -14
- data/lib/ripple/core_ext.rb +1 -14
- data/lib/ripple/core_ext/casting.rb +19 -19
- data/lib/ripple/core_ext/object.rb +8 -0
- data/lib/ripple/document.rb +21 -16
- data/lib/ripple/document/bucket_access.rb +0 -14
- data/lib/ripple/document/finders.rb +17 -23
- data/lib/ripple/document/key.rb +8 -28
- data/lib/ripple/document/link.rb +30 -0
- data/lib/ripple/document/persistence.rb +12 -20
- data/lib/ripple/embedded_document.rb +10 -15
- data/lib/ripple/embedded_document/around_callbacks.rb +18 -0
- data/lib/ripple/embedded_document/finders.rb +7 -18
- data/lib/ripple/embedded_document/persistence.rb +5 -17
- data/lib/ripple/i18n.rb +0 -14
- data/lib/ripple/inspection.rb +21 -15
- data/lib/ripple/locale/en.yml +9 -13
- data/lib/ripple/nested_attributes.rb +33 -39
- data/lib/ripple/observable.rb +0 -13
- data/lib/ripple/properties.rb +1 -14
- data/lib/ripple/property_type_mismatch.rb +0 -14
- data/lib/ripple/railtie.rb +4 -14
- data/lib/ripple/railties/ripple.rake +86 -0
- data/lib/ripple/serialization.rb +11 -11
- data/lib/ripple/test_server.rb +36 -0
- data/lib/ripple/timestamps.rb +0 -13
- data/lib/ripple/translation.rb +4 -14
- data/lib/ripple/validations.rb +1 -15
- data/lib/ripple/validations/associated_validator.rb +26 -17
- data/lib/ripple/version.rb +3 -0
- data/ripple.gemspec +24 -35
- data/spec/integration/ripple/associations_spec.rb +89 -58
- data/spec/integration/ripple/conflict_resolution_spec.rb +298 -0
- data/spec/integration/ripple/nested_attributes_spec.rb +19 -19
- data/spec/integration/ripple/persistence_spec.rb +15 -34
- data/spec/integration/ripple/search_associations_spec.rb +31 -0
- data/spec/ripple/associations/many_embedded_proxy_spec.rb +23 -36
- data/spec/ripple/associations/many_linked_proxy_spec.rb +133 -45
- data/spec/ripple/associations/many_reference_proxy_spec.rb +170 -0
- data/spec/ripple/associations/many_stored_key_proxy_spec.rb +158 -0
- data/spec/ripple/associations/one_embedded_proxy_spec.rb +24 -37
- data/spec/ripple/associations/one_key_proxy_spec.rb +82 -0
- data/spec/ripple/associations/one_linked_proxy_spec.rb +22 -23
- data/spec/ripple/associations/one_stored_key_proxy_spec.rb +72 -0
- data/spec/ripple/associations/proxy_spec.rb +21 -15
- data/spec/ripple/associations_spec.rb +54 -23
- data/spec/ripple/attribute_methods/dirty_spec.rb +56 -5
- data/spec/ripple/attribute_methods_spec.rb +47 -21
- data/spec/ripple/bucket_access_spec.rb +4 -17
- data/spec/ripple/callbacks_spec.rb +52 -15
- data/spec/ripple/conflict/resolver_spec.rb +42 -0
- data/spec/ripple/conversion_spec.rb +2 -15
- data/spec/ripple/core_ext_spec.rb +12 -15
- data/spec/ripple/document/link_spec.rb +67 -0
- data/spec/ripple/document_spec.rb +34 -19
- data/spec/ripple/embedded_document/finders_spec.rb +12 -19
- data/spec/ripple/embedded_document/persistence_spec.rb +20 -26
- data/spec/ripple/embedded_document_spec.rb +44 -34
- data/spec/ripple/finders_spec.rb +58 -29
- data/spec/ripple/inspection_spec.rb +40 -37
- data/spec/ripple/key_spec.rb +5 -17
- data/spec/ripple/observable_spec.rb +3 -16
- data/spec/ripple/persistence_spec.rb +134 -18
- data/spec/ripple/properties_spec.rb +21 -15
- data/spec/ripple/ripple_spec.rb +1 -14
- data/spec/ripple/serialization_spec.rb +16 -17
- data/spec/ripple/timestamps_spec.rb +73 -52
- data/spec/ripple/validations/associated_validator_spec.rb +69 -25
- data/spec/ripple/validations_spec.rb +3 -16
- data/spec/spec_helper.rb +17 -18
- data/spec/support/associations.rb +1 -1
- data/spec/support/associations/proxies.rb +0 -13
- data/spec/support/integration_setup.rb +11 -0
- data/spec/support/mocks.rb +0 -13
- data/spec/support/models.rb +33 -2
- data/spec/support/models/address.rb +1 -16
- data/spec/support/models/box.rb +7 -14
- data/spec/support/models/car.rb +27 -1
- data/spec/support/models/cardboard_box.rb +0 -14
- data/spec/support/models/clock.rb +6 -15
- data/spec/support/models/clock_observer.rb +0 -14
- data/spec/support/models/credit_card.rb +5 -0
- data/spec/support/models/customer.rb +0 -14
- data/spec/support/models/email.rb +0 -14
- data/spec/support/models/family.rb +1 -13
- data/spec/support/models/favorite.rb +0 -14
- data/spec/support/models/invoice.rb +0 -14
- data/spec/support/models/late_invoice.rb +0 -14
- data/spec/support/models/nested.rb +12 -0
- data/spec/support/models/ninja.rb +7 -0
- data/spec/support/models/note.rb +0 -14
- data/spec/support/models/page.rb +1 -15
- data/spec/support/models/paid_invoice.rb +0 -14
- data/spec/support/models/post.rb +12 -0
- data/spec/support/models/profile.rb +7 -0
- data/spec/support/models/subscription.rb +26 -0
- data/spec/support/models/tasks.rb +0 -18
- data/spec/support/models/team.rb +11 -0
- data/spec/support/models/transactions.rb +17 -0
- data/spec/support/models/tree.rb +2 -16
- data/spec/support/models/user.rb +14 -16
- data/spec/support/models/widget.rb +8 -14
- data/spec/support/search.rb +14 -0
- data/spec/support/test_server.rb +22 -12
- data/spec/support/test_server.yml.example +14 -2
- metadata +223 -59
- data/lib/rails/generators/ripple/test/templates/test_server.rb +0 -46
- data/spec/support/models/driver.rb +0 -5
- data/spec/support/models/engine.rb +0 -4
- data/spec/support/models/passenger.rb +0 -5
- data/spec/support/models/seat.rb +0 -4
- data/spec/support/models/wheel.rb +0 -5
@@ -0,0 +1,20 @@
|
|
1
|
+
module Ripple
|
2
|
+
module Conflict
|
3
|
+
module DocumentHooks
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
attr_reader :on_conflict_block
|
8
|
+
|
9
|
+
def on_conflict(*expected_conflicts, &block)
|
10
|
+
@expected_conflicts = expected_conflicts
|
11
|
+
@on_conflict_block = block
|
12
|
+
end
|
13
|
+
|
14
|
+
def expected_conflicts
|
15
|
+
@expected_conflicts ||= []
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'ripple/conflict/basic_resolver'
|
2
|
+
|
3
|
+
module Ripple
|
4
|
+
module Conflict
|
5
|
+
class Resolver
|
6
|
+
include Translation
|
7
|
+
|
8
|
+
attr_reader :document, :model_class
|
9
|
+
|
10
|
+
delegate :expected_conflicts, :on_conflict_block, :to => :model_class
|
11
|
+
|
12
|
+
def self.to_proc
|
13
|
+
@to_proc ||= lambda do |robject|
|
14
|
+
possible_model_classes = robject.siblings.map { |s| s.data['_type'] }.uniq
|
15
|
+
return nil unless possible_model_classes.size == 1
|
16
|
+
|
17
|
+
resolver = new(robject, possible_model_classes.first.constantize)
|
18
|
+
resolver.resolve
|
19
|
+
resolver.document.robject
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Riak::RObject.on_conflict(&self)
|
24
|
+
|
25
|
+
def initialize(robject, model_class)
|
26
|
+
@robject = robject
|
27
|
+
@model_class = model_class
|
28
|
+
end
|
29
|
+
|
30
|
+
def resolve
|
31
|
+
assert_conflict_block
|
32
|
+
basic_resolver.perform
|
33
|
+
assert_no_unexpected_conflicts
|
34
|
+
document.instance_exec(siblings, basic_resolver.remaining_conflicts, &on_conflict_block)
|
35
|
+
document.update_robject
|
36
|
+
end
|
37
|
+
|
38
|
+
def siblings
|
39
|
+
@siblings ||= @robject.siblings.map { |s| @model_class.send(:instantiate, s) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def document
|
43
|
+
# pick a sibling robject to use as the basis of the document to resolve
|
44
|
+
# which one doesn't really matter.
|
45
|
+
@document ||= @model_class.send(:instantiate, @robject.siblings.first.dup)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def basic_resolver
|
51
|
+
@basic_resolver ||= BasicResolver.new(self)
|
52
|
+
end
|
53
|
+
|
54
|
+
def assert_conflict_block
|
55
|
+
return if on_conflict_block
|
56
|
+
|
57
|
+
raise NotImplementedError, t('conflict_handler_not_implemented', :document => document)
|
58
|
+
end
|
59
|
+
|
60
|
+
def assert_no_unexpected_conflicts
|
61
|
+
return unless basic_resolver.unexpected_conflicts.any?
|
62
|
+
|
63
|
+
raise NotImplementedError, t('unexpected_conflicts',
|
64
|
+
:conflicts => basic_resolver.unexpected_conflicts.inspect,
|
65
|
+
:document => document.inspect
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Ripple
|
2
|
+
module Conflict
|
3
|
+
module TestHelper
|
4
|
+
def create_conflict(main_record, *modifiers)
|
5
|
+
# We have to disable all on conflict resolvers while we create conflict
|
6
|
+
# so that they don't auto-resolve it.
|
7
|
+
orig_hooks = Riak::RObject.on_conflict_hooks.dup
|
8
|
+
Riak::RObject.on_conflict_hooks.clear
|
9
|
+
|
10
|
+
begin
|
11
|
+
klass, key = main_record.class, main_record.key
|
12
|
+
records = modifiers.map { |_| klass.find!(key) }
|
13
|
+
|
14
|
+
records.zip(modifiers).each do |(record, modifier)|
|
15
|
+
# necessary to get conflict, so riak thinks they are being saved by different clients
|
16
|
+
Ripple.client.client_id += 1
|
17
|
+
|
18
|
+
modifier.call(record)
|
19
|
+
record.save!
|
20
|
+
end
|
21
|
+
|
22
|
+
robject = klass.bucket.get(key)
|
23
|
+
raise "#{robject} is not in conflict as expected." unless robject.conflict?
|
24
|
+
ensure
|
25
|
+
orig_hooks.each do |hook|
|
26
|
+
Riak::RObject.on_conflict(&hook)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/lib/ripple/conversion.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
1
|
require 'active_model/conversion'
|
16
2
|
|
17
3
|
module Ripple
|
data/lib/ripple/core_ext.rb
CHANGED
@@ -1,15 +1,2 @@
|
|
1
|
-
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
1
|
require 'ripple/core_ext/casting'
|
2
|
+
require 'ripple/core_ext/object'
|
@@ -1,17 +1,4 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
1
|
+
require 'tzinfo'
|
15
2
|
require 'active_support/json'
|
16
3
|
require 'active_support/core_ext/object/blank'
|
17
4
|
require 'active_support/core_ext/object/to_json'
|
@@ -23,6 +10,7 @@ require 'active_support/core_ext/time/conversions'
|
|
23
10
|
require 'active_support/core_ext/time/zones'
|
24
11
|
require 'active_support/core_ext/string/conversions'
|
25
12
|
require 'ripple/property_type_mismatch'
|
13
|
+
require 'set'
|
26
14
|
|
27
15
|
# @private
|
28
16
|
class Object
|
@@ -74,8 +62,8 @@ class String
|
|
74
62
|
end
|
75
63
|
end
|
76
64
|
|
77
|
-
|
78
|
-
def
|
65
|
+
BooleanCast = Module.new do
|
66
|
+
def ripple_cast(value)
|
79
67
|
case value
|
80
68
|
when NilClass
|
81
69
|
nil
|
@@ -98,9 +86,9 @@ unless defined?(::Boolean)
|
|
98
86
|
module ::Boolean; end
|
99
87
|
end
|
100
88
|
|
101
|
-
::Boolean.
|
102
|
-
TrueClass.
|
103
|
-
FalseClass.
|
89
|
+
::Boolean.send(:extend, BooleanCast)
|
90
|
+
TrueClass.send(:extend, BooleanCast)
|
91
|
+
FalseClass.send(:extend, BooleanCast)
|
104
92
|
|
105
93
|
# @private
|
106
94
|
class Time
|
@@ -147,3 +135,15 @@ module ActiveSupport
|
|
147
135
|
end
|
148
136
|
end
|
149
137
|
|
138
|
+
# @private
|
139
|
+
class Set
|
140
|
+
def as_json(options = {})
|
141
|
+
map { |e| e.as_json(options) }
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.ripple_cast(value)
|
145
|
+
return nil if value.nil?
|
146
|
+
value.is_a?(Enumerable) && new(value) or raise Ripple::PropertyTypeMismatch.new(self, value)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
data/lib/ripple/document.rb
CHANGED
@@ -1,23 +1,11 @@
|
|
1
|
-
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
1
|
require 'active_support/concern'
|
16
2
|
require 'active_model/naming'
|
3
|
+
require 'ripple/conflict/document_hooks'
|
17
4
|
require 'ripple/document/bucket_access'
|
18
5
|
require 'ripple/document/key'
|
19
6
|
require 'ripple/document/persistence'
|
20
7
|
require 'ripple/document/finders'
|
8
|
+
require 'ripple/document/link'
|
21
9
|
require 'ripple/properties'
|
22
10
|
require 'ripple/attribute_methods'
|
23
11
|
require 'ripple/timestamps'
|
@@ -64,6 +52,7 @@ module Ripple
|
|
64
52
|
include Ripple::Document::Key
|
65
53
|
include Ripple::Document::Persistence
|
66
54
|
extend Ripple::Properties
|
55
|
+
include Ripple::Document::Finders
|
67
56
|
include Ripple::AttributeMethods
|
68
57
|
include Ripple::Timestamps
|
69
58
|
include Ripple::Validations
|
@@ -71,10 +60,10 @@ module Ripple
|
|
71
60
|
include Ripple::Callbacks
|
72
61
|
include Ripple::Observable
|
73
62
|
include Ripple::Conversion
|
74
|
-
include Ripple::Document::Finders
|
75
63
|
include Ripple::Inspection
|
76
64
|
include Ripple::NestedAttributes
|
77
65
|
include Ripple::Serialization
|
66
|
+
include Ripple::Conflict::DocumentHooks
|
78
67
|
end
|
79
68
|
|
80
69
|
module ClassMethods
|
@@ -92,7 +81,23 @@ module Ripple
|
|
92
81
|
def ==(comparison_object)
|
93
82
|
comparison_object.equal?(self) ||
|
94
83
|
(comparison_object.class < Document && (comparison_object.instance_of?(self.class) || comparison_object.class.bucket.name == self.class.bucket.name) &&
|
95
|
-
comparison_object.key == key && !comparison_object.new?)
|
84
|
+
!new? && comparison_object.key == key && !comparison_object.new?)
|
85
|
+
end
|
86
|
+
|
87
|
+
def eql?(other)
|
88
|
+
return true if other.equal?(self)
|
89
|
+
|
90
|
+
(other.class.equal?(self.class)) &&
|
91
|
+
!other.new? && !new? &&
|
92
|
+
(other.key == key)
|
93
|
+
end
|
94
|
+
|
95
|
+
def hash
|
96
|
+
if new?
|
97
|
+
super # every new document should be treated as a different doc
|
98
|
+
else
|
99
|
+
[self.class, key].hash
|
100
|
+
end
|
96
101
|
end
|
97
102
|
end
|
98
103
|
end
|
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
1
|
require 'ripple'
|
16
2
|
|
17
3
|
module Ripple
|
@@ -1,22 +1,9 @@
|
|
1
|
-
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
1
|
require 'ripple/translation'
|
16
2
|
require 'active_support/concern'
|
17
3
|
require 'active_support/inflector'
|
18
4
|
require 'active_support/core_ext/hash/except'
|
19
5
|
require 'active_support/core_ext/hash/slice'
|
6
|
+
require 'ripple/conflict/resolver'
|
20
7
|
|
21
8
|
module Ripple
|
22
9
|
|
@@ -60,10 +47,14 @@ module Ripple
|
|
60
47
|
# @param [Array<String>] keylist an array of keys to find
|
61
48
|
# @return [Array<Document>] a list of found documents, including nil for missing documents
|
62
49
|
def find(*args)
|
63
|
-
args.
|
64
|
-
|
65
|
-
|
66
|
-
|
50
|
+
if args.first.is_a?(Array)
|
51
|
+
args.flatten.map {|key| find_one(key) }
|
52
|
+
else
|
53
|
+
args.flatten!
|
54
|
+
return nil if args.empty? || args.all?(&:blank?)
|
55
|
+
return find_one(args.first) if args.size == 1
|
56
|
+
args.map {|key| find_one(key) }
|
57
|
+
end
|
67
58
|
end
|
68
59
|
|
69
60
|
# Retrieve single or multiple documents from Riak
|
@@ -90,15 +81,17 @@ module Ripple
|
|
90
81
|
end
|
91
82
|
|
92
83
|
# Find all documents in the Document's bucket and return them.
|
93
|
-
# @overload
|
84
|
+
# @overload list()
|
94
85
|
# Get all documents and return them in an array.
|
95
86
|
# @param [Hash] options options to be passed to the
|
96
87
|
# underlying {Bucket#keys} method.
|
97
88
|
# @return [Array<Document>] all found documents in the bucket
|
98
|
-
# @overload
|
89
|
+
# @overload list() {|doc| ... }
|
99
90
|
# Stream all documents in the bucket through the block.
|
100
91
|
# @yield [Document] doc a found document
|
101
|
-
|
92
|
+
# @note This operation is incredibly expensive and should not
|
93
|
+
# be used in production applications.
|
94
|
+
def list
|
102
95
|
if block_given?
|
103
96
|
bucket.keys do |keys|
|
104
97
|
keys.each do |key|
|
@@ -108,7 +101,7 @@ module Ripple
|
|
108
101
|
end
|
109
102
|
[]
|
110
103
|
else
|
111
|
-
bucket.keys
|
104
|
+
bucket.keys.inject([]) do |acc, k|
|
112
105
|
obj = find_one(k)
|
113
106
|
obj ? acc << obj : acc
|
114
107
|
end
|
@@ -126,9 +119,10 @@ module Ripple
|
|
126
119
|
klass = robject.data['_type'].constantize rescue self
|
127
120
|
klass.new.tap do |doc|
|
128
121
|
doc.key = robject.key
|
129
|
-
doc.__send__(:
|
122
|
+
doc.__send__(:raw_attributes=, robject.data.except("_type")) if robject.data
|
130
123
|
doc.instance_variable_set(:@new, false)
|
131
124
|
doc.instance_variable_set(:@robject, robject)
|
125
|
+
doc.changed_attributes.clear
|
132
126
|
end
|
133
127
|
end
|
134
128
|
end
|
data/lib/ripple/document/key.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
1
|
require 'active_support/concern'
|
16
2
|
|
17
3
|
module Ripple
|
@@ -23,26 +9,20 @@ module Ripple
|
|
23
9
|
# Defines the key to be derived from a property.
|
24
10
|
# @param [String,Symbol] prop the property to derive the key from
|
25
11
|
def key_on(prop)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
self.#{prop} = value
|
32
|
-
end
|
33
|
-
def key_attr
|
34
|
-
:#{prop}
|
35
|
-
end
|
36
|
-
CODE
|
12
|
+
prop = prop.to_sym
|
13
|
+
|
14
|
+
define_method(:key) { send(prop).to_s }
|
15
|
+
define_method(:key=) { |v| send(:"#{prop}=", v) }
|
16
|
+
define_method(:key_attr) { prop }
|
37
17
|
end
|
38
18
|
end
|
39
|
-
|
19
|
+
|
40
20
|
module InstanceMethods
|
41
21
|
# Reads the key for this Document.
|
42
22
|
def key
|
43
23
|
@key
|
44
24
|
end
|
45
|
-
|
25
|
+
|
46
26
|
# Sets the key for this Document.
|
47
27
|
def key=(value)
|
48
28
|
@key = value.to_s
|
@@ -50,7 +30,7 @@ module Ripple
|
|
50
30
|
|
51
31
|
def key_attr
|
52
32
|
:key
|
53
|
-
end
|
33
|
+
end
|
54
34
|
end
|
55
35
|
end
|
56
36
|
end
|