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
data/lib/ripple/observable.rb
CHANGED
@@ -1,16 +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
1
|
|
15
2
|
require 'active_support/concern'
|
16
3
|
require 'active_model/observing'
|
data/lib/ripple/properties.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 'ripple/core_ext/casting'
|
16
2
|
require 'active_support/core_ext/hash/except'
|
17
3
|
require 'active_support/core_ext/hash/indifferent_access'
|
@@ -61,6 +47,7 @@ module Ripple
|
|
61
47
|
# @return [Object] The default value for this property if defined, or nil.
|
62
48
|
def default
|
63
49
|
default = options[:default]
|
50
|
+
default = default.dup if default.duplicable?
|
64
51
|
|
65
52
|
return nil if default.nil?
|
66
53
|
type_cast(default.respond_to?(:call) ? default.call : default)
|
@@ -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/translation'
|
16
2
|
|
17
3
|
module Ripple
|
data/lib/ripple/railtie.rb
CHANGED
@@ -1,23 +1,13 @@
|
|
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 'rails/railtie'
|
16
2
|
|
17
3
|
module Ripple
|
18
4
|
# Railtie for automatic initialization of the Ripple framework
|
19
5
|
# during Rails initialization.
|
20
6
|
class Railtie < Rails::Railtie
|
7
|
+
rake_tasks do
|
8
|
+
load "ripple/railties/ripple.rake"
|
9
|
+
end
|
10
|
+
|
21
11
|
initializer "ripple.configure_rails_initialization" do
|
22
12
|
if File.exist?(Rails.root + "config/ripple.yml")
|
23
13
|
Ripple.load_configuration Rails.root.join('config', 'ripple.yml'), [Rails.env]
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'ripple/translation'
|
2
|
+
require 'riak/cluster'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
namespace :riak do
|
6
|
+
task :cluster_created => :rails_env do
|
7
|
+
fail Ripple::Translator.t('cluster_not_created') unless cluster.exist?
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Starts the Riak cluster for the current environment"
|
11
|
+
task :start => :cluster_created do
|
12
|
+
cluster.start
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Stops the Riak cluster for the current environment"
|
16
|
+
task :stop => :cluster_created do
|
17
|
+
cluster.stop
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Creates a Riak cluster for the current environment in db/, e.g. db/development"
|
21
|
+
task :create => :rails_env do
|
22
|
+
cluster.create
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Destroys and recreates the cluster for the current environment."
|
26
|
+
task :reset => ['riak:destroy', 'riak:setup']
|
27
|
+
|
28
|
+
desc "Creates the Riak cluster and loads the seed data."
|
29
|
+
task :setup => ["riak:create", "db:seed"]
|
30
|
+
|
31
|
+
desc "Destroys the generated Riak cluster for the current environment."
|
32
|
+
task :destroy => :rails_env do
|
33
|
+
cluster.destroy
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Drops data only from the Riak cluster for the current environment."
|
37
|
+
task :drop => :cluster_created do
|
38
|
+
cluster.drop
|
39
|
+
end
|
40
|
+
|
41
|
+
namespace :create do
|
42
|
+
desc "Creates Riak clusters for all environments defined in config/ripple.yml"
|
43
|
+
task :all do
|
44
|
+
load_config.each do |env, config|
|
45
|
+
cluster(env.to_s, config).create
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
namespace :drop do
|
51
|
+
desc "Drops data Riak clusters for all environments defined in config/ripple.yml"
|
52
|
+
task :all do
|
53
|
+
load_config.each do |env, config|
|
54
|
+
c = cluster(env.to_s, config)
|
55
|
+
warn Ripple::Translator.t('cluster_not_created') unless c.exist?
|
56
|
+
c.drop
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
namespace :db do
|
63
|
+
task :create => "riak:create"
|
64
|
+
namespace(:create){ task :all => "riak:create:all" }
|
65
|
+
task :drop => "riak:drop"
|
66
|
+
namespace(:drop) { task :all => "riak:drop:all" }
|
67
|
+
task :setup => "riak:setup"
|
68
|
+
task :reset => "riak:reset"
|
69
|
+
task seed: ['riak:start', 'environment'] do
|
70
|
+
Rails.application.load_seed
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def load_config
|
75
|
+
file = Rails.root + "config/ripple.yml"
|
76
|
+
raise Ripple::MissingConfiguration, file.to_s unless file.exist?
|
77
|
+
YAML.load(ERB.new(file.read).result).with_indifferent_access
|
78
|
+
end
|
79
|
+
|
80
|
+
def cluster(environment=nil, config=nil)
|
81
|
+
environment ||= Rails.env
|
82
|
+
config ||= load_config[environment]
|
83
|
+
root = Rails.root + "db" + environment.to_s
|
84
|
+
# TODO: We need to deal with multiple hosts and client ports
|
85
|
+
Riak::Cluster.new(config.merge(:root => root.to_s).with_indifferent_access)
|
86
|
+
end
|
data/lib/ripple/serialization.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
# Copyright 2010 Sean Cribbs
|
1
|
+
# Copyright 2010-2011 Sean Cribbs and Basho Technologies, Inc.
|
2
2
|
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
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
6
|
#
|
7
|
-
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
8
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
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
14
|
|
15
15
|
require 'active_support/concern'
|
16
16
|
require 'active_model/serialization'
|
@@ -42,7 +42,7 @@ module Ripple
|
|
42
42
|
|
43
43
|
hash = super(options)
|
44
44
|
|
45
|
-
hash['key'] = key if respond_to?(:key)
|
45
|
+
hash['key'] = key if respond_to?(:key) && key.present? && (!options[:except] || !options[:except].map(&:to_s).include?("key"))
|
46
46
|
|
47
47
|
serializable_add_includes(options) do |association, records, opts|
|
48
48
|
hash[association.to_s] = records.is_a?(Enumerable) ? records.map {|r| r.serializable_hash(opts) } : records.serializable_hash(opts)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'riak/test_server'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module Ripple
|
5
|
+
# Extends the {Riak::TestServer} to be aware of the Ripple
|
6
|
+
# configuration and adjust settings appropriately. Also simplifies
|
7
|
+
# its usage in the generation of test helpers.
|
8
|
+
class TestServer < Riak::TestServer
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
# Creates and starts the test server
|
12
|
+
def self.setup
|
13
|
+
instance.create
|
14
|
+
instance.start
|
15
|
+
end
|
16
|
+
|
17
|
+
# Clears data from the test server
|
18
|
+
def self.clear
|
19
|
+
instance.drop
|
20
|
+
end
|
21
|
+
|
22
|
+
# @private
|
23
|
+
def initialize(options=Ripple.config.dup)
|
24
|
+
options[:env] ||= {}
|
25
|
+
options[:env][:riak_kv] ||= {}
|
26
|
+
options[:env][:riak_kv][:js_source_dir] ||= Ripple.config.delete(:js_source_dir) || (Rails.root + "app/mapreduce").to_s
|
27
|
+
options[:env][:riak_kv][:map_cache_size] ||= 0
|
28
|
+
options[:env][:riak_core] ||= {}
|
29
|
+
options[:env][:riak_core][:http] ||= [ Tuple[Ripple.config[:host], Ripple.config[:http_port]] ]
|
30
|
+
options[:env][:riak_kv][:pb_port] ||= Ripple.config[:pb_port]
|
31
|
+
options[:env][:riak_kv][:pb_ip] ||= Ripple.config[:host]
|
32
|
+
options[:root] ||= (Rails.root + 'tmp/riak_test_server').to_s
|
33
|
+
super(options)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/ripple/timestamps.rb
CHANGED
@@ -1,16 +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
1
|
require 'active_support/time'
|
15
2
|
require 'active_support/concern'
|
16
3
|
|
data/lib/ripple/translation.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 'ripple/i18n'
|
16
2
|
require 'riak/util/translation'
|
17
3
|
|
@@ -25,4 +11,8 @@ module Ripple
|
|
25
11
|
:ripple
|
26
12
|
end
|
27
13
|
end
|
14
|
+
|
15
|
+
# A dummy object so translations can be accessed without module
|
16
|
+
# inclusion.
|
17
|
+
Translator = Object.new.tap {|o| o.extend Translation }
|
28
18
|
end
|
data/lib/ripple/validations.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
|
require 'active_model/validations'
|
17
3
|
require 'ripple/translation'
|
@@ -64,7 +50,7 @@ module Ripple
|
|
64
50
|
end
|
65
51
|
|
66
52
|
# Saves the document and raises {DocumentInvalid} exception if
|
67
|
-
# validations fail.
|
53
|
+
# validations fail.
|
68
54
|
def save!
|
69
55
|
(raise Ripple::DocumentInvalid.new(self) unless save) || true
|
70
56
|
end
|
@@ -1,28 +1,37 @@
|
|
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
|
-
# Taken from ActiveRecord::Validations::AssociatedValidators
|
16
|
-
#
|
17
1
|
require 'active_model/validator'
|
18
2
|
|
19
3
|
module Ripple
|
20
4
|
module Validations
|
21
5
|
class AssociatedValidator < ActiveModel::EachValidator
|
6
|
+
include Translation
|
22
7
|
def validate_each(record, attribute, value)
|
23
8
|
return if (value.is_a?(Array) ? value : [value]).collect{ |r| r.nil? || r.valid? }.all?
|
24
|
-
record.errors.add(attribute,
|
9
|
+
record.errors.add(attribute, error_message_for(attribute, value))
|
25
10
|
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def error_message_for(attribute, associated_records)
|
15
|
+
if associated_records.respond_to?(:each_with_index)
|
16
|
+
record_errors = associated_records.enum_for(:each_with_index).collect do |record, index|
|
17
|
+
next unless record.errors.any?
|
18
|
+
|
19
|
+
t("associated_document_error_summary",
|
20
|
+
:doc_type => attribute.to_s.singularize,
|
21
|
+
:doc_id => index + 1,
|
22
|
+
:errors => record.errors.full_messages.to_sentence
|
23
|
+
)
|
24
|
+
end
|
25
|
+
record_errors.compact!
|
26
|
+
record_errors.flatten!
|
27
|
+
|
28
|
+
t("many_association_validation_error",
|
29
|
+
:association_errors => record_errors.join('; '))
|
30
|
+
else
|
31
|
+
t("one_association_validation_error",
|
32
|
+
:association_errors => associated_records.errors.full_messages.to_sentence)
|
33
|
+
end
|
34
|
+
end
|
26
35
|
end
|
27
36
|
|
28
37
|
module ClassMethods
|
data/ripple.gemspec
CHANGED
@@ -1,39 +1,28 @@
|
|
1
|
-
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'ripple/version'
|
2
3
|
|
3
|
-
Gem::Specification.new do |
|
4
|
-
|
5
|
-
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
# Meta
|
6
|
+
gem.name = "ripple"
|
7
|
+
gem.version = Ripple::VERSION
|
8
|
+
gem.summary = %Q{ripple is an object-mapper library for Riak, the distributed database by Basho.}
|
9
|
+
gem.description = %Q{ripple is an object-mapper library for Riak, the distributed database by Basho. It uses ActiveModel to provide an experience that integrates well with Rails 3 applications.}
|
10
|
+
gem.email = ["sean@basho.com"]
|
11
|
+
gem.homepage = "http://seancribbs.github.com/ripple"
|
12
|
+
gem.authors = ["Sean Cribbs"]
|
6
13
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
s.require_paths = [%q{lib}]
|
15
|
-
s.rubygems_version = %q{1.8.5}
|
16
|
-
s.summary = %q{ripple is an object-mapper library for Riak, the distributed database by Basho.}
|
17
|
-
s.test_files = [%q{spec/integration/ripple/associations_spec.rb}, %q{spec/integration/ripple/nested_attributes_spec.rb}, %q{spec/integration/ripple/persistence_spec.rb}, %q{spec/ripple/associations/many_embedded_proxy_spec.rb}, %q{spec/ripple/associations/many_linked_proxy_spec.rb}, %q{spec/ripple/associations/one_embedded_proxy_spec.rb}, %q{spec/ripple/associations/one_linked_proxy_spec.rb}, %q{spec/ripple/associations/proxy_spec.rb}, %q{spec/ripple/associations_spec.rb}, %q{spec/ripple/attribute_methods/dirty_spec.rb}, %q{spec/ripple/attribute_methods_spec.rb}, %q{spec/ripple/bucket_access_spec.rb}, %q{spec/ripple/callbacks_spec.rb}, %q{spec/ripple/conversion_spec.rb}, %q{spec/ripple/core_ext_spec.rb}, %q{spec/ripple/document_spec.rb}, %q{spec/ripple/embedded_document/finders_spec.rb}, %q{spec/ripple/embedded_document/persistence_spec.rb}, %q{spec/ripple/embedded_document_spec.rb}, %q{spec/ripple/finders_spec.rb}, %q{spec/ripple/inspection_spec.rb}, %q{spec/ripple/key_spec.rb}, %q{spec/ripple/observable_spec.rb}, %q{spec/ripple/persistence_spec.rb}, %q{spec/ripple/properties_spec.rb}, %q{spec/ripple/ripple_spec.rb}, %q{spec/ripple/serialization_spec.rb}, %q{spec/ripple/timestamps_spec.rb}, %q{spec/ripple/validations/associated_validator_spec.rb}, %q{spec/ripple/validations_spec.rb}]
|
14
|
+
# Deps
|
15
|
+
gem.add_development_dependency "rspec", "~>2.6.0"
|
16
|
+
gem.add_development_dependency 'rake', '~> 0.8.7'
|
17
|
+
gem.add_dependency "riak-client", "~>#{Ripple::VERSION}"
|
18
|
+
gem.add_dependency "activesupport", [">= 3.0.0", "< 3.2.0"]
|
19
|
+
gem.add_dependency "activemodel", [">= 3.0.0", "< 3.2.0"]
|
20
|
+
gem.add_dependency "tzinfo"
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0"])
|
26
|
-
s.add_runtime_dependency(%q<activemodel>, ["~> 3.0.0"])
|
27
|
-
else
|
28
|
-
s.add_dependency(%q<rspec>, ["~> 2.4.0"])
|
29
|
-
s.add_dependency(%q<riak-client>, ["~> 0.9.5"])
|
30
|
-
s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
|
31
|
-
s.add_dependency(%q<activemodel>, ["~> 3.0.0"])
|
32
|
-
end
|
33
|
-
else
|
34
|
-
s.add_dependency(%q<rspec>, ["~> 2.4.0"])
|
35
|
-
s.add_dependency(%q<riak-client>, ["~> 0.9.5"])
|
36
|
-
s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
|
37
|
-
s.add_dependency(%q<activemodel>, ["~> 3.0.0"])
|
38
|
-
end
|
22
|
+
# Files
|
23
|
+
ignores = File.read(".gitignore").split(/\r?\n/).reject{ |f| f =~ /^(#.+|\s*)$/ }.map {|f| Dir[f] }.flatten
|
24
|
+
gem.files = (Dir['**/*','.gitignore'] - ignores).reject {|f| !File.file?(f) }
|
25
|
+
gem.test_files = (Dir['spec/**/*','.gitignore'] - ignores).reject {|f| !File.file?(f) }
|
26
|
+
# gem.executables = Dir['bin/*'].map { |f| File.basename(f) }
|
27
|
+
gem.require_paths = ['lib']
|
39
28
|
end
|