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.
Files changed (110) hide show
  1. data/Rakefile +61 -48
  2. data/lib/ripple.rb +5 -1
  3. data/lib/ripple/core_ext/casting.rb +3 -0
  4. data/lib/ripple/document.rb +6 -2
  5. data/lib/ripple/document/associations.rb +154 -0
  6. data/lib/ripple/document/{persistence/callbacks.rb → associations/embedded.rb} +20 -24
  7. data/lib/ripple/document/associations/instantiators.rb +41 -0
  8. data/lib/{riak/util/translation.rb → ripple/document/associations/linked.rb} +14 -11
  9. data/lib/ripple/document/associations/many.rb +52 -0
  10. data/lib/ripple/document/associations/many_embedded_proxy.rb +49 -0
  11. data/lib/{riak/i18n.rb → ripple/document/associations/one.rb} +18 -2
  12. data/lib/ripple/document/associations/one_embedded_proxy.rb +41 -0
  13. data/lib/ripple/document/associations/proxy.rb +125 -0
  14. data/lib/ripple/document/attribute_methods.rb +8 -1
  15. data/lib/ripple/document/attribute_methods/read.rb +4 -0
  16. data/lib/ripple/document/attribute_methods/write.rb +4 -0
  17. data/lib/ripple/document/bucket_access.rb +1 -1
  18. data/lib/ripple/document/callbacks.rb +75 -0
  19. data/lib/ripple/document/finders.rb +50 -3
  20. data/lib/ripple/document/persistence.rb +14 -6
  21. data/lib/ripple/document/validations.rb +35 -7
  22. data/lib/ripple/document/validations/associated_validator.rb +37 -0
  23. data/lib/ripple/embedded_document.rb +8 -2
  24. data/lib/{riak/map_reduce_error.rb → ripple/embedded_document/conversion.rb} +19 -5
  25. data/lib/{riak/invalid_response.rb → ripple/embedded_document/finders.rb} +17 -8
  26. data/lib/ripple/embedded_document/persistence.rb +75 -13
  27. data/lib/ripple/locale/en.yml +7 -1
  28. data/{spec/riak/net_http_backend_spec.rb → lib/ripple/railtie.rb} +17 -13
  29. data/spec/fixtures/config.yml +3 -0
  30. data/spec/integration/ripple/associations_spec.rb +81 -0
  31. data/spec/integration/ripple/persistence_spec.rb +54 -0
  32. data/spec/ripple/associations/many_embedded_proxy_spec.rb +124 -0
  33. data/spec/ripple/associations/one_embedded_proxy_spec.rb +130 -0
  34. data/spec/ripple/associations/proxy_spec.rb +78 -0
  35. data/spec/ripple/associations_spec.rb +111 -0
  36. data/spec/ripple/attribute_methods_spec.rb +37 -16
  37. data/spec/ripple/bucket_access_spec.rb +3 -14
  38. data/spec/ripple/callbacks_spec.rb +53 -9
  39. data/spec/ripple/document_spec.rb +22 -6
  40. data/spec/ripple/embedded_document/conversion_spec.rb +35 -0
  41. data/spec/{riak/headers_spec.rb → ripple/embedded_document/finders_spec.rb} +17 -14
  42. data/spec/ripple/embedded_document/persistence_spec.rb +86 -0
  43. data/spec/ripple/embedded_document_spec.rb +1 -26
  44. data/spec/ripple/finders_spec.rb +66 -30
  45. data/spec/ripple/persistence_spec.rb +33 -21
  46. data/spec/ripple/properties_spec.rb +1 -7
  47. data/spec/ripple/ripple_spec.rb +10 -0
  48. data/spec/ripple/timestamps_spec.rb +12 -19
  49. data/spec/ripple/validations_spec.rb +48 -6
  50. data/spec/spec_helper.rb +4 -10
  51. data/spec/support/associations/proxies.rb +16 -0
  52. data/spec/support/integration.rb +4 -0
  53. data/spec/support/mocks.rb +3 -0
  54. data/spec/support/models/address.rb +8 -0
  55. data/spec/support/models/box.rb +6 -0
  56. data/spec/support/models/cardboard_box.rb +3 -0
  57. data/spec/support/models/clock.rb +6 -0
  58. data/spec/support/models/customer.rb +4 -0
  59. data/spec/support/models/email.rb +4 -0
  60. data/spec/support/models/family.rb +14 -0
  61. data/spec/support/models/favorite.rb +4 -0
  62. data/spec/support/models/invoice.rb +6 -0
  63. data/spec/support/models/late_invoice.rb +3 -0
  64. data/spec/support/models/note.rb +4 -0
  65. data/spec/support/models/page.rb +4 -0
  66. data/spec/support/models/paid_invoice.rb +4 -0
  67. data/spec/support/models/tree.rb +3 -0
  68. data/spec/support/models/user.rb +6 -0
  69. data/spec/support/models/widget.rb +6 -0
  70. metadata +111 -138
  71. data/.document +0 -5
  72. data/.gitignore +0 -26
  73. data/CONTRIBUTORS.textile +0 -5
  74. data/LICENSE +0 -13
  75. data/README.textile +0 -128
  76. data/RELEASE_NOTES.textile +0 -68
  77. data/VERSION +0 -1
  78. data/lib/riak.rb +0 -46
  79. data/lib/riak/bucket.rb +0 -157
  80. data/lib/riak/client.rb +0 -139
  81. data/lib/riak/client/curb_backend.rb +0 -82
  82. data/lib/riak/client/http_backend.rb +0 -209
  83. data/lib/riak/client/net_http_backend.rb +0 -49
  84. data/lib/riak/failed_request.rb +0 -37
  85. data/lib/riak/link.rb +0 -73
  86. data/lib/riak/locale/en.yml +0 -37
  87. data/lib/riak/map_reduce.rb +0 -248
  88. data/lib/riak/robject.rb +0 -258
  89. data/lib/riak/util/escape.rb +0 -12
  90. data/lib/riak/util/fiber1.8.rb +0 -48
  91. data/lib/riak/util/headers.rb +0 -44
  92. data/lib/riak/util/multipart.rb +0 -52
  93. data/lib/riak/walk_spec.rb +0 -117
  94. data/ripple.gemspec +0 -169
  95. data/spec/fixtures/cat.jpg +0 -0
  96. data/spec/fixtures/multipart-blank.txt +0 -7
  97. data/spec/fixtures/multipart-with-body.txt +0 -16
  98. data/spec/riak/bucket_spec.rb +0 -230
  99. data/spec/riak/client_spec.rb +0 -174
  100. data/spec/riak/curb_backend_spec.rb +0 -50
  101. data/spec/riak/escape_spec.rb +0 -17
  102. data/spec/riak/http_backend_spec.rb +0 -131
  103. data/spec/riak/link_spec.rb +0 -82
  104. data/spec/riak/map_reduce_spec.rb +0 -352
  105. data/spec/riak/multipart_spec.rb +0 -36
  106. data/spec/riak/object_spec.rb +0 -532
  107. data/spec/riak/walk_spec_spec.rb +0 -208
  108. data/spec/spec.opts +0 -1
  109. data/spec/support/http_backend_implementation_examples.rb +0 -215
  110. data/spec/support/mock_server.rb +0 -58
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,26 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
22
- _notes
23
- doc
24
- .yardoc
25
- create
26
- update-rails
@@ -1,5 +0,0 @@
1
- These developers have contributed code to Ripple:
2
-
3
- * Sean Cribbs - sean@basho.com
4
- * John Lynch - john@rigelgroupllc.com
5
- * Adam Hunter - adamhunter@me.com
data/LICENSE DELETED
@@ -1,13 +0,0 @@
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,128 +0,0 @@
1
- h1. ripple
2
-
3
- ripple is a rich Ruby client for Riak, Basho's distributed database. It includes two namespaces:
4
-
5
- * @Riak@ contains a basic wrapper around typical operations, including bucket manipulation, object CRUD, link-walking, and map-reduce.
6
- * @Ripple@ contains an ActiveModel-compatible modeling layer that is inspired by ActiveRecord, DataMapper, and MongoMapper.
7
-
8
- h2. Dependencies
9
-
10
- ripple requires Ruby 1.8.7 or later and versions 3 or above of ActiveModel and ActiveSupport (and their dependencies, including i18n). Please see the Rails 3 beta release notes for installing those gems. I highly recommend the "curb":http://curb.rubyforge.org/ gem for better HTTP client performance.
11
-
12
- In development, you will also need these gems:
13
-
14
- * jeweler
15
- * rspec >= 1.3
16
- * fakeweb >= 1.2
17
- * curb >= 0.6
18
- * rack >= 1.0
19
- * yard >= 0.5.2
20
-
21
- h2. Basic Example
22
-
23
- <notextile><pre>require 'riak'
24
-
25
- # Create a client interface
26
- client = Riak::Client.new
27
-
28
- # Retrieve a bucket
29
- bucket = client.bucket("doc") # a Riak::Bucket
30
-
31
- # Get an object from the bucket
32
- object = bucket.get("index.html") # a Riak::RObject
33
-
34
- # Change the object's data and save
35
- object.data = "<html><body>Hello, world!</body></html>"
36
- object.store
37
-
38
- # Reload an object you already have
39
- object.reload # Works if you have the key and vclock, using conditional GET
40
- object.reload :force => true # Reloads whether you have the vclock or not
41
-
42
- # Access more like a hash, client[bucket][key]
43
- client['doc']['index.html'] # the Riak::RObject
44
-
45
- # Create a new object
46
- new_one = Riak::RObject.new(bucket, "application.js")
47
- new_one.content_type = "application/javascript" # You must set the content type.
48
- new_one.data = "alert('Hello, World!')"
49
- new_one.store</pre></notextile>
50
-
51
- h2. Map-Reduce Example
52
-
53
- <notextile><pre>
54
-
55
- # Assuming you've already instantiated a client, get the album titles for The Beatles
56
- results = Riak::MapReduce.new(client).
57
- add("artists","Beatles").
58
- link(:bucket => "albums").
59
- map("function(v){ return [JSON.parse(v.values[0].data).title]; }", :keep => true).run
60
-
61
- p results # => ["Please Please Me", "With The Beatles", "A Hard Day's Night",
62
- # "Beatles For Sale", "Help!", "Rubber Soul",
63
- # "Revolver", "Sgt. Pepper's Lonely Hearts Club Band", "Magical Mystery Tour",
64
- # "The Beatles", "Yellow Submarine", "Abbey Road", "Let It Be"]</pre></notextile>
65
-
66
- h2. Document model Example
67
-
68
- <notextile><pre>
69
- require 'ripple'
70
-
71
- class Email
72
- include Ripple::Document
73
- property :from, String, :presence => true
74
- property :to, String, :presence => true
75
- property :sent, Time, :default => proc { Time.now }
76
- property :body, String
77
- end
78
-
79
- email = Email.find("37458abc752f8413e") # GET /riak/emails/37458abc752f8413e
80
- email.from = "someone@nowhere.net"
81
- email.save # PUT /riak/emails/37458abc752f8413e
82
-
83
- reply = Email.new
84
- reply.from = "justin@bashoooo.com"
85
- reply.to = "sean@geeemail.com"
86
- reply.body = "Riak is a good fit for scalable Ruby apps."
87
- reply.save # POST /riak/emails (Riak-assigned key)
88
- </pre></notextile>
89
-
90
- h2. How to Contribute
91
-
92
- * Fork the project on "Github":http://github.com/seancribbs/ripple. If you have already forked, use @git pull --rebase@ to reapply your changes on top of the mainline. Example:
93
- <notextile><pre>$ git checkout master
94
- $ git pull --rebase seancribbs master</pre></notextile>
95
- * Create a topic branch. If you've already created a topic branch, rebase it on top of changes from the mainline "master" branch. Examples:
96
- ** New branch:
97
- <pre>$ git checkout -b topic</pre>
98
- ** Existing branch:
99
- <pre>$ git rebase master</pre>
100
- * Write an RSpec example, set of examples, and/or Cucumber story that demonstrate the necessity and validity of your changes. *Patches without specs will most often be ignored. Just do it, you'll thank me later.* Documentation patches need no specs, of course.
101
- * Make your feature addition or bug fix. Make your specs and stories pass (green).
102
- * Run the suite using multiruby or rvm to ensure cross-version compatibility.
103
- * Cleanup any trailing whitespace in your code (try @whitespace-mode@ in Emacs, or "Remove Trailing Spaces in Document" in the "Text" bundle in Textmate).
104
- * Commit, do not mess with Rakefile or VERSION. If related to an existing issue in the "tracker":http://github.com/seancribbs/ripple/issues, include "Closes #X" in the commit message (where X is the issue number).
105
- * Send me a pull request.
106
-
107
- h2. License & Copyright
108
-
109
- Copyright &copy;2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
110
-
111
- Licensed under the Apache License, Version 2.0 (the "License");
112
- you may not use this file except in compliance with the License.
113
- You may obtain a copy of the License at
114
-
115
- "http://www.apache.org/licenses/LICENSE-2.0":http://www.apache.org/licenses/LICENSE-2.0
116
-
117
- Unless required by applicable law or agreed to in writing, software
118
- distributed under the License is distributed on an "AS IS" BASIS,
119
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120
- See the License for the specific language governing permissions and
121
- limitations under the License.
122
-
123
- h2. Auxillary Licenses
124
-
125
- The included photo (spec/fixtures/cat.jpg) is Copyright &copy;2009 "Sean Cribbs":http://seancribbs.com/, and is
126
- licensed under the "Creative Commons Attribution Non-Commercial 3.0":http://creativecommons.org/licenses/by-nc/3.0 license. !http://i.creativecommons.org/l/by-nc/3.0/88x31.png!
127
-
128
- The "Poor Man's Fibers" implementation (lib/riak/util/fiber1.8.rb) is Copyright &copy;2008 Aman Gupta.
@@ -1,68 +0,0 @@
1
- h1. Ripple Release Notes
2
-
3
- h2. 0.6.1 Patch Release - 2010-03-17
4
-
5
- This is a minor release with fixes for a few issues:
6
-
7
- * Riak::Link objects will now be unique when added to RObject#links
8
- Set. [John Lynch]
9
- * Attributes on Ripple::Document classes are no longer clone, which had
10
- prevented non-scalar properties from being modified directly (e.g. Array).
11
- * Buckets, keys, and walk specs are properly escaped in URLs
12
- (including slashes).
13
- * Time-related properties properly convert to string formats in JSON that
14
- they will work in the context of MapReduce jobs.
15
-
16
- h2. 0.6.0 Feature Release - 2010-03-05
17
-
18
- This release contains enhancements and bugfixes in preparation for the
19
- Riak 0.9 release.
20
-
21
- * The CurbBackend now uses fibers to prevent curl-handle corruption when
22
- a block is given to streaming operations.
23
- * The default prefix is now "/riak/" to match the latest version of Riak.
24
- * The client configuration for Ripple is now used.
25
- * Added Bucket#new and Bucket#get_or_new for easily creating new objects.
26
- * Added Bucket#allow_mult and Bucket#n_value accessors for more easily setting
27
- bucket properties.
28
- * Added timestamps! method for easily adding created_at/updated_at to documents.
29
- [Adam Hunter]
30
- * The 'links' collection on RObject is now a Set instead of an Array.
31
- * All literal messages are now stored in YAML localization files.
32
- * Object siblings (caused by concurrent updates when allow_mult is true) can now
33
- be accessed directly.
34
- * Map-reduce jobs now have timeouts (in parity with Riak).
35
-
36
- h2. 0.5.1 Patch Release - 2010-02-22
37
-
38
- This is a minor release with fixes for Ruby 1.9, bundler/edge Rails,
39
- and a minor feature addition. Changes:
40
-
41
- * Qualify namespaces for Ruby 1.9.
42
- * Decoupled a few specs that gave the appearance of failure.
43
- * Added "bucket" and "key" properties on Riak::Link objects. [John Lynch]
44
- * Fully-qualify the @JSON@ constant, using @ActiveSupport::JSON@ instead.
45
- * Adjusted gem specification to accommodate edge Rails. [Preston Marshall]
46
-
47
- h2. 0.5 Initial Release - 2010-02-10
48
-
49
- This is the first release of Ripple, which would not have been possible
50
- without the generous support of Sonian and Basho Technologies. Many thanks.
51
- It includes:
52
-
53
- * A robust basic client, @Riak@, with:
54
- ** multiple HTTP backends (curb, net/http)
55
- ** sensible client defaults (local, default port)
56
- ** bucket access and manipulation, including key-streaming
57
- ** object reading, storing, deleting and reloading
58
- ** automatic de-serialization of JSON, YAML, and Marshal (when given the right content type)
59
- ** streaming POST/PUT bodies (when given an IO)
60
- ** method-chained map-reduce job construction
61
- * A document-style modeling library, Ripple, with:
62
- ** ActiveModel 3.0 compatibility
63
- ** Property/attribute definition with automatic type-casting
64
- ** Bucket selection based on class name, with single-bucket inheritance (configurable)
65
- ** Validations
66
- ** Dirty-tracking
67
- ** Simple finders - all documents, by key
68
- ** Reloading
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.6.1
@@ -1,46 +0,0 @@
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
- $KCODE = "UTF8" if RUBY_VERSION < "1.9"
15
-
16
- require 'active_support/all'
17
- require 'active_support/json'
18
- require 'base64'
19
- require 'uri'
20
- require 'net/http'
21
- require 'yaml'
22
- require 'riak/i18n'
23
-
24
- # The Riak module contains all aspects of the HTTP client interface
25
- # to Riak.
26
- module Riak
27
- # Domain objects
28
- autoload :Bucket, "riak/bucket"
29
- autoload :Client, "riak/client"
30
- autoload :Link, "riak/link"
31
- autoload :WalkSpec, "riak/walk_spec"
32
- autoload :RObject, "riak/robject"
33
- autoload :MapReduce, "riak/map_reduce"
34
-
35
- # Exceptions
36
- autoload :FailedRequest, "riak/failed_request"
37
- autoload :InvalidResponse, "riak/invalid_response"
38
- autoload :MapReduceError, "riak/map_reduce_error"
39
-
40
- module Util
41
- autoload :Escape, "riak/util/escape"
42
- autoload :Headers, "riak/util/headers"
43
- autoload :Multipart, "riak/util/multipart"
44
- autoload :Translation, "riak/util/translation"
45
- end
46
- end
@@ -1,157 +0,0 @@
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 'riak'
15
-
16
- module Riak
17
- # Represents and encapsulates operations on a Riak bucket. You may retrieve a bucket
18
- # using {Client#bucket}, or create it manually and retrieve its meta-information later.
19
- class Bucket
20
- include Util::Translation
21
- include Util::Escape
22
-
23
- # @return [Riak::Client] the associated client
24
- attr_reader :client
25
-
26
- # @return [String] the bucket name
27
- attr_reader :name
28
-
29
- # @return [Hash] Internal Riak bucket properties.
30
- attr_reader :props
31
- alias_attribute :properties, :props
32
-
33
- # Create a Riak bucket manually.
34
- # @param [Client] client the {Riak::Client} for this bucket
35
- # @param [String] name the name of the bucket
36
- def initialize(client, name)
37
- raise ArgumentError, t("client_type", :client => client.inspect) unless Client === client
38
- raise ArgumentError, t("string_type", :string => name.inspect) unless String === name
39
- @client, @name, @props = client, name, {}
40
- end
41
-
42
- # Load information for the bucket from a response given by the {Riak::Client::HTTPBackend}.
43
- # Used mostly internally - use {Riak::Client#bucket} to get a {Bucket} instance.
44
- # @param [Hash] response a response from {Riak::Client::HTTPBackend}
45
- # @return [Bucket] self
46
- # @see Client#bucket
47
- def load(response={})
48
- unless response.try(:[], :headers).try(:[],'content-type').try(:first) =~ /json$/
49
- raise Riak::InvalidResponse.new({"content-type" => ["application/json"]}, response[:headers], t("loading_bucket", :name => name))
50
- end
51
- payload = ActiveSupport::JSON.decode(response[:body])
52
- @keys = payload['keys'].map {|k| URI.unescape(k) } if payload['keys']
53
- @props = payload['props'] if payload['props']
54
- self
55
- end
56
-
57
- # Accesses or retrieves a list of keys in this bucket.
58
- # If a block is given, keys will be streamed through
59
- # the block (useful for large buckets). When streaming,
60
- # results of the operation will not be retained in the local Bucket object.
61
- # @param [Hash] options extra options
62
- # @yield [Array<String>] a list of keys from the current chunk
63
- # @option options [Boolean] :reload (false) If present, will force reloading of the bucket's keys from Riak
64
- # @return [Array<String>] Keys in this bucket
65
- def keys(options={})
66
- if block_given?
67
- @client.http.get(200, @client.prefix, escape(name), {:props => false}, {}) do |chunk|
68
- obj = ActiveSupport::JSON.decode(chunk) rescue {}
69
- yield obj['keys'].map {|k| URI.unescape(k) } if obj['keys']
70
- end
71
- elsif @keys.nil? || options[:reload]
72
- response = @client.http.get(200, @client.prefix, escape(name), {:props => false}, {})
73
- load(response)
74
- end
75
- @keys
76
- end
77
-
78
- # Sets internal properties on the bucket
79
- # Note: this results in a request to the Riak server!
80
- # @param [Hash] properties new properties for the bucket
81
- # @return [Hash] the properties that were accepted
82
- # @raise [FailedRequest] if the new properties were not accepted by the Riak server
83
- def props=(properties)
84
- raise ArgumentError, t("hash_type", :hash => properties.inspect) unless Hash === properties
85
- body = {'props' => properties}.to_json
86
- @client.http.put(204, @client.prefix, escape(name), body, {"Content-Type" => "application/json"})
87
- @props = properties
88
- end
89
-
90
- # Retrieve an object from within the bucket.
91
- # @param [String] key the key of the object to retrieve
92
- # @param [Hash] options query parameters for the request
93
- # @option options [Fixnum] :r - the read quorum for the request - how many nodes should concur on the read
94
- # @return [Riak::RObject] the object
95
- # @raise [FailedRequest] if the object is not found or some other error occurs
96
- def get(key, options={})
97
- code = allow_mult ? [200,300] : 200
98
- response = @client.http.get(code, @client.prefix, escape(name), escape(key), options, {})
99
- RObject.new(self, key).load(response)
100
- end
101
- alias :[] :get
102
-
103
- # Create a new blank object
104
- # @param [String] key the key of the new object
105
- # @return [RObject] the new, unsaved object
106
- def new(key=nil)
107
- RObject.new(self, key).tap do |obj|
108
- obj.content_type = "application/json"
109
- end
110
- end
111
-
112
- # Fetches an object if it exists, otherwise creates a new one with the given key
113
- # @param [String] key the key to fetch or create
114
- # @return [RObject] the new or existing object
115
- def get_or_new(key, options={})
116
- begin
117
- get(key, options)
118
- rescue Riak::FailedRequest => fr
119
- if fr.code.to_i == 404
120
- new(key)
121
- else
122
- raise fr
123
- end
124
- end
125
- end
126
-
127
- # @return [true, false] whether the bucket allows divergent siblings
128
- def allow_mult
129
- props['allow_mult']
130
- end
131
-
132
- # Set the allow_mult property. *NOTE* This will result in a PUT request to Riak.
133
- # @param [true, false] value whether the bucket should allow siblings
134
- def allow_mult=(value)
135
- self.props = props.merge('allow_mult' => value)
136
- value
137
- end
138
-
139
- # @return [Fixnum] the N value, or number of replicas for this bucket
140
- def n_value
141
- props['n_val']
142
- end
143
-
144
- # Set the N value (number of replicas). *NOTE* This will result in a PUT request to Riak.
145
- # Setting this value after the bucket has objects stored in it may have unpredictable results.
146
- # @param [Fixnum] value the number of replicas the bucket should keep of each object
147
- def n_value=(value)
148
- self.props = props.merge('n_val' => value)
149
- value
150
- end
151
-
152
- # @return [String] a representation suitable for IRB and debugging output
153
- def inspect
154
- "#<Riak::Bucket #{client.http.path(client.prefix, escape(name)).to_s}#{" keys=[#{keys.join(',')}]" if defined?(@keys)}>"
155
- end
156
- end
157
- end