ripple 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +61 -48
- data/lib/ripple.rb +5 -1
- data/lib/ripple/core_ext/casting.rb +3 -0
- data/lib/ripple/document.rb +6 -2
- data/lib/ripple/document/associations.rb +154 -0
- data/lib/ripple/document/{persistence/callbacks.rb → associations/embedded.rb} +20 -24
- data/lib/ripple/document/associations/instantiators.rb +41 -0
- data/lib/{riak/util/translation.rb → ripple/document/associations/linked.rb} +14 -11
- data/lib/ripple/document/associations/many.rb +52 -0
- data/lib/ripple/document/associations/many_embedded_proxy.rb +49 -0
- data/lib/{riak/i18n.rb → ripple/document/associations/one.rb} +18 -2
- data/lib/ripple/document/associations/one_embedded_proxy.rb +41 -0
- data/lib/ripple/document/associations/proxy.rb +125 -0
- data/lib/ripple/document/attribute_methods.rb +8 -1
- data/lib/ripple/document/attribute_methods/read.rb +4 -0
- data/lib/ripple/document/attribute_methods/write.rb +4 -0
- data/lib/ripple/document/bucket_access.rb +1 -1
- data/lib/ripple/document/callbacks.rb +75 -0
- data/lib/ripple/document/finders.rb +50 -3
- data/lib/ripple/document/persistence.rb +14 -6
- data/lib/ripple/document/validations.rb +35 -7
- data/lib/ripple/document/validations/associated_validator.rb +37 -0
- data/lib/ripple/embedded_document.rb +8 -2
- data/lib/{riak/map_reduce_error.rb → ripple/embedded_document/conversion.rb} +19 -5
- data/lib/{riak/invalid_response.rb → ripple/embedded_document/finders.rb} +17 -8
- data/lib/ripple/embedded_document/persistence.rb +75 -13
- data/lib/ripple/locale/en.yml +7 -1
- data/{spec/riak/net_http_backend_spec.rb → lib/ripple/railtie.rb} +17 -13
- data/spec/fixtures/config.yml +3 -0
- data/spec/integration/ripple/associations_spec.rb +81 -0
- data/spec/integration/ripple/persistence_spec.rb +54 -0
- data/spec/ripple/associations/many_embedded_proxy_spec.rb +124 -0
- data/spec/ripple/associations/one_embedded_proxy_spec.rb +130 -0
- data/spec/ripple/associations/proxy_spec.rb +78 -0
- data/spec/ripple/associations_spec.rb +111 -0
- data/spec/ripple/attribute_methods_spec.rb +37 -16
- data/spec/ripple/bucket_access_spec.rb +3 -14
- data/spec/ripple/callbacks_spec.rb +53 -9
- data/spec/ripple/document_spec.rb +22 -6
- data/spec/ripple/embedded_document/conversion_spec.rb +35 -0
- data/spec/{riak/headers_spec.rb → ripple/embedded_document/finders_spec.rb} +17 -14
- data/spec/ripple/embedded_document/persistence_spec.rb +86 -0
- data/spec/ripple/embedded_document_spec.rb +1 -26
- data/spec/ripple/finders_spec.rb +66 -30
- data/spec/ripple/persistence_spec.rb +33 -21
- data/spec/ripple/properties_spec.rb +1 -7
- data/spec/ripple/ripple_spec.rb +10 -0
- data/spec/ripple/timestamps_spec.rb +12 -19
- data/spec/ripple/validations_spec.rb +48 -6
- data/spec/spec_helper.rb +4 -10
- data/spec/support/associations/proxies.rb +16 -0
- data/spec/support/integration.rb +4 -0
- data/spec/support/mocks.rb +3 -0
- data/spec/support/models/address.rb +8 -0
- data/spec/support/models/box.rb +6 -0
- data/spec/support/models/cardboard_box.rb +3 -0
- data/spec/support/models/clock.rb +6 -0
- data/spec/support/models/customer.rb +4 -0
- data/spec/support/models/email.rb +4 -0
- data/spec/support/models/family.rb +14 -0
- data/spec/support/models/favorite.rb +4 -0
- data/spec/support/models/invoice.rb +6 -0
- data/spec/support/models/late_invoice.rb +3 -0
- data/spec/support/models/note.rb +4 -0
- data/spec/support/models/page.rb +4 -0
- data/spec/support/models/paid_invoice.rb +4 -0
- data/spec/support/models/tree.rb +3 -0
- data/spec/support/models/user.rb +6 -0
- data/spec/support/models/widget.rb +6 -0
- metadata +111 -138
- data/.document +0 -5
- data/.gitignore +0 -26
- data/CONTRIBUTORS.textile +0 -5
- data/LICENSE +0 -13
- data/README.textile +0 -128
- data/RELEASE_NOTES.textile +0 -68
- data/VERSION +0 -1
- data/lib/riak.rb +0 -46
- data/lib/riak/bucket.rb +0 -157
- data/lib/riak/client.rb +0 -139
- data/lib/riak/client/curb_backend.rb +0 -82
- data/lib/riak/client/http_backend.rb +0 -209
- data/lib/riak/client/net_http_backend.rb +0 -49
- data/lib/riak/failed_request.rb +0 -37
- data/lib/riak/link.rb +0 -73
- data/lib/riak/locale/en.yml +0 -37
- data/lib/riak/map_reduce.rb +0 -248
- data/lib/riak/robject.rb +0 -258
- data/lib/riak/util/escape.rb +0 -12
- data/lib/riak/util/fiber1.8.rb +0 -48
- data/lib/riak/util/headers.rb +0 -44
- data/lib/riak/util/multipart.rb +0 -52
- data/lib/riak/walk_spec.rb +0 -117
- data/ripple.gemspec +0 -169
- data/spec/fixtures/cat.jpg +0 -0
- data/spec/fixtures/multipart-blank.txt +0 -7
- data/spec/fixtures/multipart-with-body.txt +0 -16
- data/spec/riak/bucket_spec.rb +0 -230
- data/spec/riak/client_spec.rb +0 -174
- data/spec/riak/curb_backend_spec.rb +0 -50
- data/spec/riak/escape_spec.rb +0 -17
- data/spec/riak/http_backend_spec.rb +0 -131
- data/spec/riak/link_spec.rb +0 -82
- data/spec/riak/map_reduce_spec.rb +0 -352
- data/spec/riak/multipart_spec.rb +0 -36
- data/spec/riak/object_spec.rb +0 -532
- data/spec/riak/walk_spec_spec.rb +0 -208
- data/spec/spec.opts +0 -1
- data/spec/support/http_backend_implementation_examples.rb +0 -215
- data/spec/support/mock_server.rb +0 -58
data/Rakefile
CHANGED
|
@@ -1,61 +1,74 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
|
-
require 'rake'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
2
|
+
require 'rake/gempackagetask'
|
|
3
|
+
|
|
4
|
+
version = File.read('../VERSION').strip
|
|
5
|
+
|
|
6
|
+
gemspec = Gem::Specification.new do |gem|
|
|
7
|
+
gem.name = "ripple"
|
|
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.version = version
|
|
11
|
+
gem.email = "seancribbs@gmail.com"
|
|
12
|
+
gem.homepage = "http://seancribbs.github.com/ripple"
|
|
13
|
+
gem.authors = ["Sean Cribbs"]
|
|
14
|
+
gem.add_development_dependency "rspec", "~>2.0.0.beta.6"
|
|
15
|
+
gem.add_dependency "riak-client", version
|
|
16
|
+
gem.add_dependency "activesupport", "3.0.0.beta3"
|
|
17
|
+
gem.add_dependency "activemodel", "3.0.0.beta3"
|
|
18
|
+
|
|
19
|
+
files = FileList["**/*"]
|
|
20
|
+
files.exclude /\.DS_Store/
|
|
21
|
+
files.exclude /\#/
|
|
22
|
+
files.exclude /~/
|
|
23
|
+
files.exclude /\.swp/
|
|
24
|
+
files.exclude '**/._*'
|
|
25
|
+
files.exclude '**/*.orig'
|
|
26
|
+
files.exclude '**/*.rej'
|
|
27
|
+
files.exclude /^pkg/
|
|
28
|
+
files.exclude 'ripple.gemspec'
|
|
29
|
+
|
|
30
|
+
gem.files = files.to_a
|
|
31
|
+
|
|
32
|
+
gem.test_files = FileList["spec/**/*.rb"].to_a
|
|
26
33
|
end
|
|
27
34
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
# Gem packaging tasks
|
|
36
|
+
Rake::GemPackageTask.new(gemspec) do |pkg|
|
|
37
|
+
pkg.need_zip = false
|
|
38
|
+
pkg.need_tar = false
|
|
32
39
|
end
|
|
33
40
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
task :gem => :gemspec
|
|
42
|
+
|
|
43
|
+
desc %{Build the gemspec file.}
|
|
44
|
+
task :gemspec do
|
|
45
|
+
gemspec.validate
|
|
46
|
+
File.open("#{gemspec.name}.gemspec", 'w'){|f| f.write gemspec.to_ruby }
|
|
39
47
|
end
|
|
40
48
|
|
|
41
|
-
|
|
49
|
+
desc %{Release the gem to RubyGems.org}
|
|
50
|
+
task :release => :gem do
|
|
51
|
+
"gem push pkg/#{gemspec.name}-#{gemspec.version}.gem"
|
|
52
|
+
end
|
|
42
53
|
|
|
43
|
-
|
|
54
|
+
require 'rspec/core'
|
|
55
|
+
require 'rspec/core/rake_task'
|
|
44
56
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
yard.files = docfiles
|
|
49
|
-
yard.options = ["--no-private"]
|
|
57
|
+
desc "Run Unit Specs Only"
|
|
58
|
+
Rspec::Core::RakeTask.new(:spec) do |spec|
|
|
59
|
+
spec.pattern = "spec/ripple/**/*_spec.rb"
|
|
50
60
|
end
|
|
51
61
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
namespace :spec do
|
|
63
|
+
desc "Run Integration Specs Only"
|
|
64
|
+
Rspec::Core::RakeTask.new(:integration) do |spec|
|
|
65
|
+
spec.pattern = "spec/integration/**/*_spec.rb"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
desc "Run All Specs"
|
|
69
|
+
Rspec::Core::RakeTask.new(:all) do |spec|
|
|
70
|
+
spec.pattern = "spec/**/*_spec.rb"
|
|
71
|
+
end
|
|
58
72
|
end
|
|
59
73
|
|
|
60
|
-
|
|
61
|
-
CLOBBER.include("doc")
|
|
74
|
+
task :default => :spec
|
data/lib/ripple.rb
CHANGED
|
@@ -42,9 +42,13 @@ module Ripple
|
|
|
42
42
|
Thread.current[:ripple_client] = value
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
def config=(
|
|
45
|
+
def config=(hash)
|
|
46
46
|
self.client = nil
|
|
47
47
|
super
|
|
48
48
|
end
|
|
49
|
+
|
|
50
|
+
def load_config(config_file)
|
|
51
|
+
self.config = YAML.load_file(File.expand_path config_file).with_indifferent_access[:ripple]
|
|
52
|
+
end
|
|
49
53
|
end
|
|
50
54
|
end
|
|
@@ -102,6 +102,7 @@ class Time
|
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
def self.ripple_cast(value)
|
|
105
|
+
return nil if value.nil?
|
|
105
106
|
value.respond_to?(:to_time) && value.to_time or raise Ripple::PropertyTypeMismatch.new(self, value)
|
|
106
107
|
end
|
|
107
108
|
end
|
|
@@ -113,6 +114,7 @@ class Date
|
|
|
113
114
|
end
|
|
114
115
|
|
|
115
116
|
def self.ripple_cast(value)
|
|
117
|
+
return nil if value.nil?
|
|
116
118
|
value.respond_to?(:to_date) && value.to_date or raise Ripple::PropertyTypeMismatch.new(self, value)
|
|
117
119
|
end
|
|
118
120
|
end
|
|
@@ -124,6 +126,7 @@ class DateTime
|
|
|
124
126
|
end
|
|
125
127
|
|
|
126
128
|
def self.ripple_cast(value)
|
|
129
|
+
return nil if value.nil?
|
|
127
130
|
value.respond_to?(:to_datetime) && value.to_datetime or raise Ripple::PropertyTypeMismatch.new(self, value)
|
|
128
131
|
end
|
|
129
132
|
end
|
data/lib/ripple/document.rb
CHANGED
|
@@ -42,8 +42,11 @@ module Ripple
|
|
|
42
42
|
extend ActiveSupport::Concern
|
|
43
43
|
extend ActiveSupport::Autoload
|
|
44
44
|
|
|
45
|
+
autoload :Association, "ripple/document/associations"
|
|
46
|
+
autoload :Associations
|
|
45
47
|
autoload :AttributeMethods
|
|
46
48
|
autoload :BucketAccess
|
|
49
|
+
autoload :Callbacks
|
|
47
50
|
autoload :Finders
|
|
48
51
|
autoload :Persistence
|
|
49
52
|
autoload :Properties
|
|
@@ -53,9 +56,10 @@ module Ripple
|
|
|
53
56
|
|
|
54
57
|
included do
|
|
55
58
|
extend BucketAccess
|
|
56
|
-
include Persistence
|
|
59
|
+
include Ripple::Document::Persistence
|
|
57
60
|
include Ripple::EmbeddedDocument
|
|
58
|
-
include Finders
|
|
61
|
+
include Ripple::Document::Finders
|
|
59
62
|
end
|
|
63
|
+
|
|
60
64
|
end
|
|
61
65
|
end
|
|
@@ -0,0 +1,154 @@
|
|
|
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
|
+
require 'ripple'
|
|
15
|
+
|
|
16
|
+
module Ripple
|
|
17
|
+
module Document
|
|
18
|
+
module Associations
|
|
19
|
+
extend ActiveSupport::Concern
|
|
20
|
+
extend ActiveSupport::Autoload
|
|
21
|
+
|
|
22
|
+
autoload :Proxy
|
|
23
|
+
autoload :One
|
|
24
|
+
autoload :Many
|
|
25
|
+
autoload :Embedded
|
|
26
|
+
autoload :Instantiators
|
|
27
|
+
autoload :OneEmbeddedProxy
|
|
28
|
+
autoload :ManyEmbeddedProxy
|
|
29
|
+
|
|
30
|
+
module ClassMethods
|
|
31
|
+
# @private
|
|
32
|
+
def inherited(subclass)
|
|
33
|
+
super
|
|
34
|
+
subclass.associations.merge!(associations)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Associations defined on the document
|
|
38
|
+
def associations
|
|
39
|
+
@associations ||= {}.with_indifferent_access
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Creates a singular association
|
|
43
|
+
def one(name, options={})
|
|
44
|
+
create_association(:one, name, options)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Creates a plural association
|
|
48
|
+
def many(name, options={})
|
|
49
|
+
create_association(:many, name, options)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
def create_association(type, name, options={})
|
|
54
|
+
association = associations[name] = Association.new(type, name, options)
|
|
55
|
+
|
|
56
|
+
define_method(name) do
|
|
57
|
+
get_proxy(association)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
define_method("#{name}=") do |value|
|
|
61
|
+
get_proxy(association).replace(value)
|
|
62
|
+
value
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
if association.one?
|
|
66
|
+
define_method("#{name}?") do
|
|
67
|
+
get_proxy(association).present?
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
module InstanceMethods
|
|
74
|
+
def associations
|
|
75
|
+
self.class.associations
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def embedded_associations
|
|
79
|
+
associations.map do |name, association|
|
|
80
|
+
association if association.embeddable?
|
|
81
|
+
end.compact
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# @private
|
|
85
|
+
def get_proxy(association)
|
|
86
|
+
unless proxy = instance_variable_get(association.ivar)
|
|
87
|
+
proxy = association.proxy_class.new(self, association)
|
|
88
|
+
instance_variable_set(association.ivar, proxy)
|
|
89
|
+
end
|
|
90
|
+
proxy
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
class Association
|
|
96
|
+
attr_reader :type, :name, :options
|
|
97
|
+
|
|
98
|
+
# association options :using, :class_name, :class, :extend,
|
|
99
|
+
# options that may be added :validate
|
|
100
|
+
|
|
101
|
+
def initialize(type, name, options={})
|
|
102
|
+
@type, @name, @options = type, name, options.to_options
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def class_name
|
|
106
|
+
@class_name ||= case
|
|
107
|
+
when @options[:class_name]
|
|
108
|
+
@options[:class_name]
|
|
109
|
+
when @options[:class]
|
|
110
|
+
@options[:class].to_s
|
|
111
|
+
when many?
|
|
112
|
+
@name.to_s.classify
|
|
113
|
+
else
|
|
114
|
+
@name.to_s.camelize
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def klass
|
|
119
|
+
@klass ||= options[:class] || class_name.constantize
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def many?
|
|
123
|
+
@type == :many
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def one?
|
|
127
|
+
@type == :one
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def embeddable?
|
|
131
|
+
klass.embeddable?
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def polymorphic?
|
|
135
|
+
false
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def ivar
|
|
139
|
+
"@_#{name}"
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def proxy_class
|
|
143
|
+
return @proxy_class if defined?(@proxy_class)
|
|
144
|
+
proxy_class_name.constantize
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def proxy_class_name
|
|
148
|
+
@using ||= options[:using] || (embeddable? ? :embedded : :link)
|
|
149
|
+
klass_name = (many? ? 'Many' : 'One') + @using.to_s.camelize + ('Polymorphic' if polymorphic?).to_s + 'Proxy'
|
|
150
|
+
"Ripple::Document::Associations::#{klass_name}"
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
@@ -15,34 +15,30 @@ require 'ripple'
|
|
|
15
15
|
|
|
16
16
|
module Ripple
|
|
17
17
|
module Document
|
|
18
|
-
module
|
|
19
|
-
module
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
define_model_callbacks :create, :update, :save, :destroy
|
|
18
|
+
module Associations
|
|
19
|
+
module Embedded
|
|
20
|
+
|
|
21
|
+
def initialize(*args)
|
|
22
|
+
super
|
|
23
|
+
owner.class.validates reflection.name, :associated => true
|
|
25
24
|
end
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
super
|
|
34
|
-
end
|
|
25
|
+
|
|
26
|
+
protected
|
|
27
|
+
|
|
28
|
+
def assign_references(docs)
|
|
29
|
+
Array(docs).each do |doc|
|
|
30
|
+
next unless doc.respond_to?(:_parent_document=)
|
|
31
|
+
doc._parent_document = owner
|
|
35
32
|
end
|
|
36
33
|
end
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
end
|
|
34
|
+
|
|
35
|
+
def instantiate_target(*args)
|
|
36
|
+
doc = super
|
|
37
|
+
assign_references(doc)
|
|
38
|
+
doc
|
|
43
39
|
end
|
|
44
|
-
|
|
40
|
+
|
|
45
41
|
end
|
|
46
42
|
end
|
|
47
43
|
end
|
|
48
|
-
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
require 'ripple'
|
|
15
|
+
|
|
16
|
+
module Ripple
|
|
17
|
+
module Document
|
|
18
|
+
module Associations
|
|
19
|
+
module Instantiators
|
|
20
|
+
|
|
21
|
+
def build(attrs={})
|
|
22
|
+
instantiate_target(:new, attrs)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def create(attrs={})
|
|
26
|
+
instantiate_target(:create, attrs)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def create!(attrs={})
|
|
30
|
+
instantiate_target(:create!, attrs)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
protected
|
|
34
|
+
def instantiate_target
|
|
35
|
+
raise NotImplementedError
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -11,19 +11,22 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
-
require '
|
|
14
|
+
require 'ripple'
|
|
15
15
|
|
|
16
|
-
module
|
|
17
|
-
module
|
|
18
|
-
module
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
module Ripple
|
|
17
|
+
module Document
|
|
18
|
+
module Associations
|
|
19
|
+
module Linked
|
|
20
|
+
|
|
21
|
+
def create(attrs={})
|
|
22
|
+
instantiate_target(:create, attrs)
|
|
23
|
+
end
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
def create!(attrs={})
|
|
26
|
+
instantiate_target(:create!, attrs)
|
|
27
|
+
end
|
|
28
|
+
|
|
25
29
|
end
|
|
26
30
|
end
|
|
27
31
|
end
|
|
28
|
-
end
|
|
29
|
-
|
|
32
|
+
end
|