ripple 0.8.0.beta2 → 0.8.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.
Files changed (47) hide show
  1. data/lib/rails/generators/ripple/model/model_generator.rb +14 -0
  2. data/lib/rails/generators/ripple_generator.rb +17 -0
  3. data/lib/ripple.rb +7 -1
  4. data/lib/ripple/associations.rb +35 -0
  5. data/lib/ripple/attribute_methods.rb +0 -6
  6. data/lib/ripple/callbacks.rb +5 -0
  7. data/lib/ripple/conversion.rb +5 -0
  8. data/lib/ripple/core_ext.rb +13 -0
  9. data/lib/ripple/document.rb +9 -0
  10. data/lib/ripple/document/finders.rb +1 -1
  11. data/lib/ripple/document/key.rb +49 -0
  12. data/lib/ripple/document/persistence.rb +1 -1
  13. data/lib/ripple/embedded_document.rb +3 -1
  14. data/lib/ripple/embedded_document/finders.rb +1 -0
  15. data/lib/ripple/embedded_document/persistence.rb +15 -5
  16. data/lib/ripple/inspection.rb +1 -0
  17. data/lib/ripple/property_type_mismatch.rb +2 -0
  18. data/lib/ripple/railtie.rb +2 -0
  19. data/lib/ripple/timestamps.rb +5 -0
  20. data/lib/ripple/translation.rb +2 -0
  21. data/lib/ripple/validations.rb +7 -2
  22. data/spec/ripple/conversion_spec.rb +6 -6
  23. data/spec/ripple/core_ext_spec.rb +13 -0
  24. data/spec/ripple/document_spec.rb +30 -0
  25. data/spec/ripple/finders_spec.rb +6 -1
  26. data/spec/ripple/key_spec.rb +43 -0
  27. data/spec/ripple/timestamps_spec.rb +14 -0
  28. data/spec/support/associations/proxies.rb +15 -1
  29. data/spec/support/mocks.rb +15 -1
  30. data/spec/support/models/address.rb +15 -1
  31. data/spec/support/models/box.rb +14 -1
  32. data/spec/support/models/cardboard_box.rb +14 -1
  33. data/spec/support/models/clock.rb +14 -1
  34. data/spec/support/models/customer.rb +14 -1
  35. data/spec/support/models/email.rb +14 -1
  36. data/spec/support/models/family.rb +14 -1
  37. data/spec/support/models/favorite.rb +14 -1
  38. data/spec/support/models/invoice.rb +14 -1
  39. data/spec/support/models/late_invoice.rb +13 -0
  40. data/spec/support/models/note.rb +14 -1
  41. data/spec/support/models/page.rb +14 -1
  42. data/spec/support/models/paid_invoice.rb +14 -1
  43. data/spec/support/models/tasks.rb +14 -0
  44. data/spec/support/models/tree.rb +15 -1
  45. data/spec/support/models/user.rb +15 -1
  46. data/spec/support/models/widget.rb +13 -0
  47. metadata +10 -11
@@ -1,3 +1,17 @@
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
  require 'rails/generators/ripple_generator'
2
16
 
3
17
  module Ripple
@@ -1,8 +1,23 @@
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.
1
14
  require "rails/generators/named_base"
2
15
  require "rails/generators/active_model"
3
16
 
4
17
  module Ripple
18
+ # ActiveModel generators for use in a Rails project.
5
19
  module Generators
20
+ # @private
6
21
  class Base < ::Rails::Generators::NamedBase
7
22
 
8
23
  def self.source_root
@@ -11,6 +26,7 @@ module Ripple
11
26
  end
12
27
  end
13
28
 
29
+ # Generator for a {Ripple::Document} model
14
30
  class ActiveModel < ::Rails::Generators::ActiveModel
15
31
  def self.all(klass)
16
32
  "#{klass}.all"
@@ -47,6 +63,7 @@ module Ripple
47
63
  end
48
64
  end
49
65
 
66
+ # @private
50
67
  module Rails
51
68
  module Generators
52
69
  class GeneratedAttribute #:nodoc:
@@ -57,15 +57,19 @@ module Ripple
57
57
  Thread.current[:ripple_client] = value
58
58
  end
59
59
 
60
+ # Sets the global Ripple configuration.
60
61
  def config=(hash)
61
62
  self.client = nil
62
63
  @config = hash.symbolize_keys
63
64
  end
64
65
 
66
+ # Reads the global Ripple configuration.
65
67
  def config
66
68
  @config ||= {}
67
69
  end
68
70
 
71
+ # Loads the Ripple configuration from a given YAML file.
72
+ # Evaluates the configuration with ERB before loading.
69
73
  def load_configuration(config_file, config_keys = [:ripple])
70
74
  config_file = File.expand_path(config_file)
71
75
  config_hash = YAML.load(ERB.new(File.read(config_file)).result).with_indifferent_access
@@ -76,7 +80,9 @@ module Ripple
76
80
  end
77
81
  alias_method :load_config, :load_configuration
78
82
  end
79
-
83
+
84
+ # Exception raised when the path passed to
85
+ # {Ripple::load_configuration} does not point to a existing file.
80
86
  class MissingConfiguration < StandardError
81
87
  include Translation
82
88
  def initialize(file_path)
@@ -14,6 +14,38 @@
14
14
  require 'ripple'
15
15
 
16
16
  module Ripple
17
+ # Adds associations via links and embedding to {Ripple::Document}
18
+ # models. Examples:
19
+ #
20
+ # # Documents can contain embedded documents, and link to other standalone documents
21
+ # # via associations using the many and one class methods.
22
+ # class Person
23
+ # include Ripple::Document
24
+ # property :name, String
25
+ # many :addresses
26
+ # many :friends, :class_name => "Person"
27
+ # one :account
28
+ # end
29
+ #
30
+ # # Account and Address are embeddable documents
31
+ # class Account
32
+ # include Ripple::EmbeddedDocument
33
+ # property :paid_until, Time
34
+ # embedded_in :person # Adds "person" method to get parent document
35
+ # end
36
+ #
37
+ # class Address
38
+ # include Ripple::EmbeddedDocument
39
+ # property :street, String
40
+ # property :city, String
41
+ # property :state, String
42
+ # property :zip, String
43
+ # end
44
+ #
45
+ # person = Person.find("adamhunter")
46
+ # person.friends << Person.find("seancribbs") # Links to people/seancribbs with tag "friend"
47
+ # person.addresses << Address.new(:street => "100 Main Street") # Adds an embedded address
48
+ # person.account.paid_until = 3.months.from_now
17
49
  module Associations
18
50
  extend ActiveSupport::Concern
19
51
  extend ActiveSupport::Autoload
@@ -100,6 +132,8 @@ module Ripple
100
132
  end
101
133
  end
102
134
 
135
+ # The "reflection" for an association - metadata about how it is
136
+ # configured.
103
137
  class Association
104
138
  include Ripple::Translation
105
139
  attr_reader :type, :name, :options
@@ -210,6 +244,7 @@ module Ripple
210
244
  end
211
245
  end
212
246
 
247
+ # @private
213
248
  def type_matches?(value)
214
249
  case
215
250
  when polymorphic?
@@ -49,8 +49,6 @@ module Ripple
49
49
  end
50
50
 
51
51
  module InstanceMethods
52
- attr_accessor :key
53
-
54
52
  # A copy of the values of all attributes in the Document. The result
55
53
  # is not memoized, so use sparingly. This does not include associated objects,
56
54
  # nor embedded documents.
@@ -76,10 +74,6 @@ module Ripple
76
74
  end
77
75
  end
78
76
 
79
- def key=(value)
80
- @key = value.to_s
81
- end
82
-
83
77
  # @private
84
78
  def initialize(attrs={})
85
79
  super()
@@ -14,6 +14,8 @@
14
14
  require 'ripple'
15
15
 
16
16
  module Ripple
17
+ # Adds lifecycle callbacks to {Ripple::Document} models, in the typical
18
+ # ActiveModel fashion.
17
19
  module Callbacks
18
20
  extend ActiveSupport::Concern
19
21
 
@@ -24,6 +26,7 @@ module Ripple
24
26
  end
25
27
 
26
28
  module ClassMethods
29
+ # Defines a callback to be run before validations.
27
30
  def before_validation(*args, &block)
28
31
  options = args.last
29
32
  if options.is_a?(Hash) && options[:on]
@@ -33,6 +36,7 @@ module Ripple
33
36
  set_callback(:validation, :before, *args, &block)
34
37
  end
35
38
 
39
+ # Defines a callback to be run after validations.
36
40
  def after_validation(*args, &block)
37
41
  options = args.extract_options!
38
42
  options[:prepend] = true
@@ -43,6 +47,7 @@ module Ripple
43
47
  end
44
48
  end
45
49
 
50
+ # @private
46
51
  module InstanceMethods
47
52
  # @private
48
53
  def save(*args, &block)
@@ -14,21 +14,26 @@
14
14
  require 'ripple'
15
15
 
16
16
  module Ripple
17
+ # Provides ActionPack compatibility for {Ripple::Document} models.
17
18
  module Conversion
18
19
  include ActiveModel::Conversion
19
20
 
21
+ # True if this is a new document
20
22
  def new_record?
21
23
  new?
22
24
  end
23
25
 
26
+ # True if this is not a new document
24
27
  def persisted?
25
28
  !new?
26
29
  end
27
30
 
31
+ # Converts to a view key
28
32
  def to_key
29
33
  new? ? nil : [key]
30
34
  end
31
35
 
36
+ # Converts to a URL parameter
32
37
  def to_param
33
38
  key
34
39
  end
@@ -1 +1,14 @@
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.
1
14
  require 'ripple/core_ext/casting'
@@ -44,11 +44,13 @@ module Ripple
44
44
 
45
45
  autoload :BucketAccess
46
46
  autoload :Finders
47
+ autoload :Key
47
48
  autoload :Persistence
48
49
 
49
50
  included do
50
51
  extend ActiveModel::Naming
51
52
  extend BucketAccess
53
+ include Ripple::Document::Key
52
54
  include Ripple::Document::Persistence
53
55
  extend Ripple::Properties
54
56
  include Ripple::AttributeMethods
@@ -71,6 +73,13 @@ module Ripple
71
73
  def _root_document
72
74
  self
73
75
  end
76
+
77
+ # Returns true if the +comparison_object+ is the same object, or is of the same type and has the same key.
78
+ def ==(comparison_object)
79
+ comparison_object.equal?(self) ||
80
+ (comparison_object.class < Document && (comparison_object.instance_of?(self.class) || comparison_object.class.bucket.name == self.class.bucket.name) &&
81
+ comparison_object.key == key && !comparison_object.new?)
82
+ end
74
83
  end
75
84
  end
76
85
  end
@@ -56,7 +56,7 @@ module Ripple
56
56
  # @return [Array<Document>] a list of found documents, including nil for missing documents
57
57
  def find(*args)
58
58
  args.flatten!
59
- return nil if args.empty?
59
+ return nil if args.empty? || args.all?(&:blank?)
60
60
  return find_one(args.first) if args.one?
61
61
  args.map {|key| find_one(key) }
62
62
  end
@@ -0,0 +1,49 @@
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 Key
19
+ extend ActiveSupport::Concern
20
+
21
+ module ClassMethods
22
+ # Defines the key to be derived from a property.
23
+ # @param [String,Symbol] prop the property to derive the key from
24
+ def key_on(prop)
25
+ class_eval <<-CODE
26
+ def key
27
+ #{prop}.to_s
28
+ end
29
+ def key=(value)
30
+ self.#{prop} = value
31
+ end
32
+ CODE
33
+ end
34
+ end
35
+
36
+ module InstanceMethods
37
+ # Reads the key for this Document.
38
+ def key
39
+ @key
40
+ end
41
+
42
+ # Sets the key for this Document.
43
+ def key=(value)
44
+ @key = value.to_s
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -23,7 +23,7 @@ module Ripple
23
23
 
24
24
  # Instantiates a new record, applies attributes from a block, and saves it
25
25
  def create(attrs={}, &block)
26
- new(attrs, &block).tap {|s| s.save}
26
+ new(attrs, &block).tap {|s| s.save }
27
27
  end
28
28
 
29
29
  # Destroys all records one at a time.
@@ -14,11 +14,13 @@
14
14
  require 'ripple'
15
15
 
16
16
  module Ripple
17
+ # Represents a document model that is composed into or stored in a parent
18
+ # Document. Embedded documents may also embed other documents, have
19
+ # callbacks and validations, but are solely dependent on the parent Document.
17
20
  module EmbeddedDocument
18
21
  extend ActiveSupport::Concern
19
22
  extend ActiveSupport::Autoload
20
23
 
21
- autoload :Conversion
22
24
  autoload :Finders
23
25
  autoload :Persistence
24
26
  include Translation
@@ -15,6 +15,7 @@ require 'ripple'
15
15
 
16
16
  module Ripple
17
17
  module EmbeddedDocument
18
+ # @private
18
19
  module Finders
19
20
  extend ActiveSupport::Concern
20
21
 
@@ -14,6 +14,8 @@
14
14
  require 'ripple'
15
15
 
16
16
  module Ripple
17
+ # Exception raised when save is called on an EmbeddedDocument that
18
+ # is not attached to a root Document.
17
19
  class NoRootDocument < StandardError
18
20
  include Translation
19
21
  def initialize(doc, method)
@@ -22,18 +24,24 @@ module Ripple
22
24
  end
23
25
 
24
26
  module EmbeddedDocument
27
+ # Adds methods to {Ripple::EmbeddedDocument} that delegate storage
28
+ # operations to the parent document.
25
29
  module Persistence
26
30
  extend ActiveSupport::Concern
27
31
 
28
32
  module ClassMethods
33
+ # Creates a method that points to the parent document.
29
34
  def embedded_in(parent)
30
35
  define_method(parent) { @_parent_document }
31
36
  end
32
37
  end
33
38
 
34
39
  module InstanceMethods
35
- attr_reader :_parent_document
40
+ # The parent document to this embedded document. This may be a
41
+ # {Ripple::Document} or another {Ripple::EmbeddedDocument}.
42
+ attr_accessor :_parent_document
36
43
 
44
+ # Whether the root document is unsaved.
37
45
  def new?
38
46
  if _root_document
39
47
  _root_document.new?
@@ -42,16 +50,20 @@ module Ripple
42
50
  end
43
51
  end
44
52
 
53
+ # Sets this embedded documents attributes and saves the root document.
45
54
  def update_attributes(attrs)
46
55
  self.attributes = attrs
47
56
  save
48
57
  end
49
58
 
59
+ # Updates this embedded document's attribute and saves the
60
+ # root document, skipping validations.
50
61
  def update_attribute(attribute, value)
51
62
  send("#{attribute}=", value)
52
63
  save(:validate => false)
53
64
  end
54
65
 
66
+ # Saves this embedded document by delegating to the root document.
55
67
  def save(*args)
56
68
  if _root_document
57
69
  _root_document.save(*args)
@@ -60,17 +72,15 @@ module Ripple
60
72
  end
61
73
  end
62
74
 
75
+ # @private
63
76
  def attributes_for_persistence
64
77
  attributes.merge("_type" => self.class.name)
65
78
  end
66
79
 
80
+ # The root {Ripple::Document} to which this embedded document belongs.
67
81
  def _root_document
68
82
  @_parent_document.try(:_root_document)
69
83
  end
70
-
71
- def _parent_document=(value)
72
- @_parent_document = value
73
- end
74
84
  end
75
85
  end
76
86
  end
@@ -17,6 +17,7 @@ require 'ripple'
17
17
  module Ripple
18
18
  # Makes IRB and other inspect output a bit friendlier
19
19
  module Inspection
20
+ # A human-readable version of the {Ripple::Document} or {Ripple::EmbeddedDocument}
20
21
  def inspect
21
22
  attribute_list = attributes_for_persistence.except("_type").map {|k,v| "#{k}=#{v.inspect}" }.join(' ')
22
23
  identifier = self.class.embeddable? ? "" : ":#{key || '[new]'}"
@@ -14,6 +14,8 @@
14
14
  require 'ripple'
15
15
 
16
16
  module Ripple
17
+ # Exception raised when the value assigned to a document property
18
+ # cannot be coerced into the property's defined type.
17
19
  class PropertyTypeMismatch < StandardError
18
20
  include Translation
19
21
  def initialize(klass, value)
@@ -14,6 +14,8 @@
14
14
  require 'ripple'
15
15
 
16
16
  module Ripple
17
+ # Railtie for automatic initialization of the Ripple framework
18
+ # during Rails initialization.
17
19
  class Railtie < Rails::Railtie
18
20
  initializer "ripple.configure_rails_initialization" do
19
21
  Ripple.load_configuration Rails.root.join('config', 'ripple.yml'), [Rails.env]
@@ -14,10 +14,14 @@
14
14
  require 'ripple'
15
15
 
16
16
  module Ripple
17
+ # Adds automatic creation and update timestamps to a
18
+ # {Ripple::Document} model.
17
19
  module Timestamps
18
20
  extend ActiveSupport::Concern
19
21
 
20
22
  module ClassMethods
23
+ # Adds the :created_at and :updated_at timestamp properties to
24
+ # the document.
21
25
  def timestamps!
22
26
  property :created_at, Time, :default => proc { Time.now.utc }
23
27
  property :updated_at, Time
@@ -26,6 +30,7 @@ module Ripple
26
30
  end
27
31
 
28
32
  module InstanceMethods
33
+ # Sets the :updated_at attribute before saving the document.
29
34
  def touch
30
35
  self.updated_at = Time.now.utc
31
36
  end
@@ -14,9 +14,11 @@
14
14
  require 'ripple'
15
15
 
16
16
  module Ripple
17
+ # Adds i18n translation/string-lookup capabilities.
17
18
  module Translation
18
19
  include Riak::Util::Translation
19
20
 
21
+ # The scope of i18n keys to search (:ripple).
20
22
  def i18n_scope
21
23
  :ripple
22
24
  end
@@ -14,7 +14,6 @@
14
14
  require 'ripple'
15
15
 
16
16
  module Ripple
17
-
18
17
  # Raised by <tt>save!</tt> when the document is invalid. Use the
19
18
  # +document+ method to retrieve the document which did not validate.
20
19
  # begin
@@ -32,6 +31,8 @@ module Ripple
32
31
  end
33
32
  end
34
33
 
34
+ # Adds validations to {Ripple::Document} models. Validations are
35
+ # executed before saving the document.
35
36
  module Validations
36
37
  extend ActiveSupport::Concern
37
38
  extend ActiveSupport::Autoload
@@ -60,11 +61,15 @@ module Ripple
60
61
  return false if options[:validate] && !valid?
61
62
  super()
62
63
  end
63
-
64
+
65
+ # Saves the document and raises {DocumentInvalid} exception if
66
+ # validations fail.
64
67
  def save!
65
68
  (raise Ripple::DocumentInvalid.new(self) unless save) || true
66
69
  end
67
70
 
71
+ # Sets the passed attributes and saves the document, raising a
72
+ # {DocumentInvalid} exception if the validations fail.
68
73
  def update_attributes!(attrs)
69
74
  self.attributes = attrs
70
75
  save!
@@ -14,22 +14,22 @@
14
14
  require File.expand_path("../../spec_helper", __FILE__)
15
15
 
16
16
  describe Ripple::Conversion do
17
- require 'support/models/address'
17
+ require 'support/models/box'
18
18
 
19
19
  before :each do
20
- @addr = Address.new { |a| a.key = 'some-key' }
21
- @addr.stub!(:new?).and_return(false)
20
+ @box = Box.new { |a| a.key = 'some-key' }
21
+ @box.stub!(:new?).and_return(false)
22
22
  end
23
23
 
24
24
  it "should return the key as an array for to_key" do
25
- @addr.to_key.should == ['some-key']
25
+ @box.to_key.should == ['some-key']
26
26
  end
27
27
 
28
28
  it "should be able to be converted to a param" do
29
- @addr.to_param.should == 'some-key'
29
+ @box.to_param.should == 'some-key'
30
30
  end
31
31
 
32
32
  it "should be able to be converted to a model" do
33
- @addr.to_model.should == @addr
33
+ @box.to_model.should == @box
34
34
  end
35
35
  end
@@ -1,3 +1,16 @@
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.
1
14
  require File.expand_path("../../spec_helper", __FILE__)
2
15
 
3
16
  describe Time do
@@ -27,6 +27,36 @@ describe Ripple::Document do
27
27
  Page.should_not be_embeddable
28
28
  end
29
29
 
30
+ describe "equivalence" do
31
+ before do
32
+ class Homepage < Page; end
33
+ class ErrorPage; include Ripple::Document; self.bucket_name = "pages"; end
34
+ @doc = Page.new
35
+ @doc2 = Page.new
36
+ @sub = Homepage.new
37
+ @error = ErrorPage.new
38
+ [@doc,@doc2,@sub,@error].each {|d| d.key = "root"; d.stub!(:new?).and_return(false) }
39
+ end
40
+
41
+ it "should be equal if the same object" do
42
+ @doc.should == @doc
43
+ end
44
+
45
+ it "should be equal if instance of same class and key" do
46
+ @doc.should == @doc2
47
+ @doc.should == @sub
48
+ end
49
+
50
+ it "should be equal if of the same bucket and key" do
51
+ @doc.should == @error
52
+ end
53
+
54
+ it "should not be equal if new record" do
55
+ @doc2.stub!(:new?).and_return(true)
56
+ @doc.should_not == @doc2
57
+ end
58
+ end
59
+
30
60
  describe "ActiveModel compatibility" do
31
61
  include ActiveModel::Lint::Tests
32
62
 
@@ -25,10 +25,15 @@ describe Ripple::Document::Finders do
25
25
  Box.stub!(:bucket).and_return(@bucket)
26
26
  end
27
27
 
28
- it "should return an empty array if no keys are passed to find" do
28
+ it "should return nil if no keys are passed to find" do
29
29
  Box.find().should be_nil
30
30
  end
31
31
 
32
+ it "should return nil if no valid keys are passed to find" do
33
+ Box.find(nil).should be_nil
34
+ Box.find("").should be_nil
35
+ end
36
+
32
37
  it "should raise Ripple::DocumentNotFound if an empty array is passed to find!" do
33
38
  lambda { Box.find!() }.should raise_error(Ripple::DocumentNotFound, "Couldn't find document without a key")
34
39
  end
@@ -0,0 +1,43 @@
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 File.expand_path("../spec_helper", File.dirname(__FILE__))
15
+
16
+ describe Ripple::Document::Key do
17
+ require 'support/models/box'
18
+ before do
19
+ @box = Box.new
20
+ end
21
+
22
+ it "should define key getter and setter" do
23
+ @box.should respond_to(:key)
24
+ @box.should respond_to(:key=)
25
+ end
26
+
27
+ it "should stringify the assigned key" do
28
+ @box.key = 2
29
+ @box.key.should == "2"
30
+ end
31
+
32
+ it "should use a property as the key" do
33
+ class ShapedBox < Box
34
+ key_on :shape
35
+ end
36
+ @box = ShapedBox.new
37
+ @box.key = "square"
38
+ @box.key.should == "square"
39
+ @box.shape.should == "square"
40
+ @box.shape = "oblong"
41
+ @box.key.should == "oblong"
42
+ end
43
+ end
@@ -1,3 +1,17 @@
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
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
16
 
3
17
  describe Ripple::Timestamps do
@@ -1,4 +1,18 @@
1
- # yet another filch from mongo mapper
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
+
2
16
  class FakeNilProxy < Ripple::Associations::Proxy
3
17
  def find_target; nil end
4
18
  end
@@ -1,3 +1,17 @@
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
  def mock_response(overrides={})
2
16
  {:headers => {"content-type" => ["application/json"]}, :body => '{}'}.merge(overrides)
3
- end
17
+ end
@@ -1,3 +1,17 @@
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
  require 'support/models/note'
2
16
 
3
17
  class Address
@@ -5,4 +19,4 @@ class Address
5
19
  property :street, String, :presence => true
6
20
  many :notes
7
21
  embedded_in :user
8
- end
22
+ end
@@ -1,6 +1,19 @@
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.
1
14
 
2
15
  class Box
3
16
  include Ripple::Document
4
17
  property :shape, String
5
18
  timestamps!
6
- end
19
+ end
@@ -1,3 +1,16 @@
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.
1
14
 
2
15
  class CardboardBox < Box
3
- end
16
+ end
@@ -1,6 +1,19 @@
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.
1
14
 
2
15
 
3
16
  class Clock
4
17
  include Ripple::Document
5
18
  timestamps!
6
- end
19
+ end
@@ -1,4 +1,17 @@
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.
1
14
 
2
15
  class Customer
3
16
  include Ripple::Document
4
- end
17
+ end
@@ -1,4 +1,17 @@
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.
1
14
 
2
15
  class Email
3
16
  include Ripple::Document
4
- end
17
+ end
@@ -1,3 +1,16 @@
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.
1
14
  class Parent
2
15
  include Ripple::Document
3
16
  one :child
@@ -11,4 +24,4 @@ end
11
24
 
12
25
  class Grandchild
13
26
  include Ripple::EmbeddedDocument
14
- end
27
+ end
@@ -1,4 +1,17 @@
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.
1
14
 
2
15
  class Favorite
3
16
  include Ripple::EmbeddedDocument
4
- end
17
+ end
@@ -1,6 +1,19 @@
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.
1
14
 
2
15
  class Invoice
3
16
  include Ripple::Document
4
17
  one :customer
5
18
  one :note
6
- end
19
+ end
@@ -1,3 +1,16 @@
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.
1
14
 
2
15
  class LateInvoice < Invoice
3
16
  end
@@ -1,4 +1,17 @@
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.
1
14
 
2
15
  class Note
3
16
  include Ripple::EmbeddedDocument
4
- end
17
+ end
@@ -1,4 +1,17 @@
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.
1
14
 
2
15
  class Page
3
16
  include Ripple::Document
4
- end
17
+ end
@@ -1,4 +1,17 @@
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.
1
14
 
2
15
  class PaidInvoice < Invoice
3
16
  self.bucket_name = "paid"
4
- end
17
+ end
@@ -1,3 +1,17 @@
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
  class Person
2
16
  include Ripple::Document
3
17
  many :tasks
@@ -1,3 +1,17 @@
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
  class Leaf; end;
2
16
  class Branch; end;
3
- class Trunk; end
17
+ class Trunk; end
@@ -1,6 +1,20 @@
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
  require 'support/models/address'
2
16
 
3
17
  class User
4
18
  include Ripple::Document
5
19
  many :addresses
6
- end
20
+ end
@@ -1,3 +1,16 @@
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.
1
14
 
2
15
  class Widget
3
16
  include Ripple::Document
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripple
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ prerelease: false
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
8
  - 0
9
- - beta2
10
- version: 0.8.0.beta2
9
+ version: 0.8.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Sean Cribbs
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-08-29 00:00:00 -04:00
17
+ date: 2010-08-31 00:00:00 -04:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -47,8 +46,7 @@ dependencies:
47
46
  - 0
48
47
  - 8
49
48
  - 0
50
- - beta2
51
- version: 0.8.0.beta2
49
+ version: 0.8.0
52
50
  type: :runtime
53
51
  version_requirements: *id002
54
52
  - !ruby/object:Gem::Dependency
@@ -115,6 +113,7 @@ files:
115
113
  - lib/ripple/core_ext.rb
116
114
  - lib/ripple/document/bucket_access.rb
117
115
  - lib/ripple/document/finders.rb
116
+ - lib/ripple/document/key.rb
118
117
  - lib/ripple/document/persistence.rb
119
118
  - lib/ripple/document.rb
120
119
  - lib/ripple/embedded_document/finders.rb
@@ -152,6 +151,7 @@ files:
152
151
  - spec/ripple/embedded_document_spec.rb
153
152
  - spec/ripple/finders_spec.rb
154
153
  - spec/ripple/inspection_spec.rb
154
+ - spec/ripple/key_spec.rb
155
155
  - spec/ripple/persistence_spec.rb
156
156
  - spec/ripple/properties_spec.rb
157
157
  - spec/ripple/ripple_spec.rb
@@ -197,13 +197,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
197
  required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  none: false
199
199
  requirements:
200
- - - ">"
200
+ - - ">="
201
201
  - !ruby/object:Gem::Version
202
202
  segments:
203
- - 1
204
- - 3
205
- - 1
206
- version: 1.3.1
203
+ - 0
204
+ version: "0"
207
205
  requirements: []
208
206
 
209
207
  rubyforge_project:
@@ -231,6 +229,7 @@ test_files:
231
229
  - spec/ripple/embedded_document_spec.rb
232
230
  - spec/ripple/finders_spec.rb
233
231
  - spec/ripple/inspection_spec.rb
232
+ - spec/ripple/key_spec.rb
234
233
  - spec/ripple/persistence_spec.rb
235
234
  - spec/ripple/properties_spec.rb
236
235
  - spec/ripple/ripple_spec.rb