riagent 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27288ed232ba0816f1d3801edbb0d254f9afddf3
4
- data.tar.gz: 734ec9dcfb6fc9816660d911e0cfd93a348b3e0a
3
+ metadata.gz: 5d1d7a96d9c29d8889bf4a5dcf4203e8356a7f67
4
+ data.tar.gz: bec969e749fe0625dc02521c851cf8c5ecbc738d
5
5
  SHA512:
6
- metadata.gz: dcc0206d55b66b3db10d0ed0fd1131232fd5979bbf61a60d177850198d30a20a8d6b3a658d7c72790bf054cf470e6aeb6d2b57c34d7abbb2d31d1d66fc56ce8e
7
- data.tar.gz: e834529f89a4755b803b926055565e1345f8a57c4529973e5e7acef529825e321138662ec65c1f3e64ddc4d76d8c02fd42757e744016d78a771a984037fe8fd8
6
+ metadata.gz: cd088e4272e939b1a01d9ddc5dfcf656f739c31c22af2af59257e427a62886edd7bdb11fdedeb8758f3275a7a8ff1abd7d6f80fe939af193ab3a3d3135b52912
7
+ data.tar.gz: 3c051e911034f36d1b546644f6321dbcb05155cb1204ce3e85abb2384953b2247ac34e6e8eb5114714b8afd3d5647c4261d0d9ffb1867a8b986e040f0cf86fe5
data/Gemfile.lock CHANGED
@@ -1,20 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- riagent (0.0.2)
4
+ riagent (0.0.3)
5
5
  activemodel (~> 4.0)
6
6
  activesupport (~> 4.0)
7
- riagent-document
8
- riak-client (~> 2.0.0.rc1)
9
- riak_json
7
+ riagent-document (= 0.0.1)
8
+ riak-client (~> 2.2.1)
10
9
 
11
10
  GEM
12
11
  remote: https://rubygems.org/
13
12
  specs:
14
- activemodel (4.0.9)
15
- activesupport (= 4.0.9)
13
+ activemodel (4.0.13)
14
+ activesupport (= 4.0.13)
16
15
  builder (~> 3.1.0)
17
- activesupport (4.0.9)
16
+ activesupport (4.0.13)
18
17
  i18n (~> 0.6, >= 0.6.9)
19
18
  minitest (~> 4.2)
20
19
  multi_json (~> 1.3)
@@ -24,44 +23,33 @@ GEM
24
23
  descendants_tracker (~> 0.0.4)
25
24
  ice_nine (~> 0.11.0)
26
25
  thread_safe (~> 0.3, >= 0.3.1)
27
- beefcake (1.0.0.pre2)
26
+ beefcake (1.1.0)
28
27
  builder (3.1.4)
28
+ cert_validator (0.0.1)
29
29
  coercible (1.0.0)
30
30
  descendants_tracker (~> 0.0.1)
31
31
  descendants_tracker (0.0.4)
32
32
  thread_safe (~> 0.3, >= 0.3.1)
33
- equalizer (0.0.9)
34
- i18n (0.6.11)
35
- ice_nine (0.11.0)
33
+ equalizer (0.0.11)
34
+ i18n (0.7.0)
35
+ ice_nine (0.11.1)
36
36
  innertube (1.0.2)
37
- json (1.8.1)
38
- mime-types (2.3)
39
37
  minitest (4.7.0)
40
38
  minitest-spec-context (0.0.3)
41
- multi_json (1.10.1)
42
- netrc (0.7.7)
43
- r509 (0.10.0)
44
- r509-cert-validator (0.0.4)
45
- r509 (~> 0.10.0)
39
+ multi_json (1.11.2)
46
40
  rake (10.3.2)
47
- rest-client (1.7.2)
48
- mime-types (>= 1.16, < 3.0)
49
- netrc (~> 0.7)
50
41
  riagent-document (0.0.1)
51
42
  activesupport (~> 4.0)
52
43
  virtus
53
- riak-client (2.0.0.rc1)
54
- beefcake (>= 1.0.0.pre1)
44
+ riak-client (2.2.1)
45
+ beefcake (~> 1.1)
46
+ cert_validator (~> 0.0.1)
55
47
  i18n (>= 0.4.0)
56
48
  innertube (~> 1.0.2)
57
49
  multi_json (~> 1.0)
58
- r509-cert-validator (~> 0.0.4)
59
- riak_json (0.0.4)
60
- json
61
- rest-client
62
- thread_safe (0.3.4)
63
- tzinfo (0.3.41)
64
- virtus (1.0.3)
50
+ thread_safe (0.3.5)
51
+ tzinfo (0.3.44)
52
+ virtus (1.0.5)
65
53
  axiom-types (~> 0.1)
66
54
  coercible (~> 1.0)
67
55
  descendants_tracker (~> 0.0, >= 0.0.3)
data/README.md CHANGED
@@ -5,16 +5,11 @@ Object Document Mapper for [Riak](http://basho.com/products/riak-kv/)
5
5
  Sinatra.
6
6
 
7
7
  ## Requirements
8
- - Ruby 1.9+
8
+ - Ruby 2+
9
9
  - [Riak](http://basho.com/products/riak-kv/) version 2.0 or later
10
- - [RiakJson](https://github.com/basho-labs/riak_json_ruby_client) Ruby Client
11
- gem installed locally
12
- - [riagent-document](https://github.com/dmitrizagidulin/riagent-document) gem
13
- installed locally
14
10
 
15
11
  ## Motivation
16
12
  *a.k.a. Why not just use a plain
17
- [riak_json client](https://github.com/basho-labs/riak_json_ruby_client) or a
18
13
  [riak-ruby-client](https://github.com/basho/riak-ruby-client)?*
19
14
 
20
15
  A Riak client just answers the question "How do I store stuff in Riak?".
@@ -30,7 +25,7 @@ a developer must answer further questions:
30
25
 
31
26
  Riagent attempts to provide answers to those questions, to encode recommended
32
27
  best-practice Riak query patterns, and in general to aid rapid application
33
- development by working with Riak's strenghts while respecting its limitations.
28
+ development by working with Riak's strengths while respecting its limitations.
34
29
  It is intended as a spiritual successor to
35
30
  [Ripple](https://github.com/basho-labs/ripple).
36
31
 
@@ -69,16 +64,16 @@ Search/Solr integration?
69
64
  Riagent provides a set of high-level notations and functionality that allows
70
65
  developers create collections and associations on Riak, either via plain K/V
71
66
  operations when possible, or via advanced mechanisms such as
72
- Solr/[RiakJson](https://github.com/basho-labs/riak_json) queries when necessary.
67
+ Solr queries when necessary.
73
68
 
74
69
  ```ruby
75
70
  class User
76
71
  include Riagent::ActiveDocument
77
72
 
78
- collection_type :riak_json # Persist to a RiakJson::Collection
73
+ collection_type :riak_kv
79
74
 
80
- attribute :username, String, search_index: { as: :text }
81
- attribute :email, String, search_index: { as: :string }
75
+ attribute :username, String
76
+ attribute :email, String
82
77
  attribute :language, String, default: 'en'
83
78
 
84
79
  # Associations
@@ -104,8 +99,6 @@ Riagent and ActiveDocuments are integrated into the usual Rails workflow.
104
99
  - Provides ```before_save``` / ```after_save``` type Callback functionality
105
100
  - Provides a custom Query capability (to Riak/Solr), for searches, range
106
101
  queries, aggregations and more
107
- - Derives RiakJson/Solr search schemas from annotated document attributes (see
108
- Schemas below)
109
102
 
110
103
  ## Usage
111
104
  ### Adding Riagent to a Rails App
@@ -182,70 +175,6 @@ ActiveDocument currently supports ```before_*``` and ```after_*``` [callbacks](h
182
175
  for the following events:
183
176
  ```[:create, :update, :save, :destroy]```
184
177
 
185
- ### Search and Querying
186
- See the Querying sections of [RJ Ruby Client](https://github.com/basho-labs/riak_json_ruby_client#querying-riakjson---find_one-and-find)
187
- and [RiakJson itself](https://github.com/basho-labs/riak_json/blob/master/docs/query.md)
188
- ```ruby
189
- # All matching instances
190
- us_users = User.where({ country: 'USA' }) # => array of US user instances
191
- # One instance (the first)
192
- user = User.find_one({ username: 'HieronymusBosch' })
193
- ```
194
-
195
- ## Search Schema Definition
196
- RiakJson uses Solr/Yokozuna to provide indexing and search capability for its
197
- collections. If you do not specify a collection schema explicitly, RiakJson
198
- creates one when you insert the first document to that collection (it [infers
199
- the
200
- schema](https://github.com/basho-labs/riak_json/blob/master/docs/architecture.md#inferred-schemas)
201
- based on the basic data types of the field values in the JSON). However, if you
202
- do not want to use this default schema behavior (for example, because RJ tries
203
- to index all of the fields), you can define and set a collection schema
204
- yourself, using RJ Ruby Client's [schema
205
- administration](https://github.com/basho-labs/riak_json_ruby_client#schema-administration)
206
- API.
207
-
208
- To make the process of schema definition even easier for developers,
209
- ActiveDocument provides the ```search_index``` attribute option. This annotation
210
- allows you to specify which document fields you want added to your search
211
- schema, as well as the Solr field type that will be used to index it.
212
-
213
- For example, the following model:
214
- ```ruby
215
- class User
216
- include Riagent::ActiveDocument
217
-
218
- attribute :username, String, required: true, search_index: { :as => :text }
219
- attribute :email, String, search_index: { :as => :string }
220
- attribute :country, String, default: 'USA'
221
- end
222
- ```
223
- will enable you to construct the following schema:
224
- ```ruby
225
- User.schema # =>
226
- # [{
227
- # :name => "username",
228
- # :type => "text",
229
- # :require => true
230
- # }, {
231
- # :name => "email",
232
- # :type => "string",
233
- # :require => false
234
- # }
235
- # ]
236
- # # Note that 'country' is not included in this schema, and so will not be indexed.
237
- ```
238
-
239
- ### Schema Administration
240
- Note that if you use the ```search_index``` attribute annotations above, you
241
- will have to explicitly notify RiakJson of your intent to save the schema. You
242
- will have to call the ```set_schema()``` collection method before you start
243
- inserting documents (for example, in a ```db:setup``` Rake task).
244
-
245
- ```ruby
246
- User.collection.set_schema(User.schema)
247
- ```
248
-
249
178
  ## Testing the Riagent gem
250
179
  First, set up the Riak config file for (and make sure it's pointing to a running
251
180
  Riak instance)
@@ -1,4 +1,4 @@
1
- # Configure Riak and RiakJson connections for the client, by environment
1
+ # Configure Riak connections for the client, by environment
2
2
  development:
3
3
  http_port: 8098
4
4
  pb_port: 8097 # Protocol Buffer port
@@ -25,7 +25,6 @@ require 'riagent/document'
25
25
  require 'riagent/conversion'
26
26
  require 'riagent/persistence'
27
27
  require 'riagent/associations'
28
- require 'riagent/search_schema'
29
28
 
30
29
  module Riagent
31
30
  module ActiveDocument
@@ -45,7 +44,7 @@ module Riagent
45
44
 
46
45
  module ClassMethods
47
46
  # Returns string representation for the collection name
48
- # Used to determine the RiakJson::Collection name, or the Riak Bucket name
47
+ # Used to determine the Riak Bucket name
49
48
  # Uses ActiveModel::Naming functionality to derive the name
50
49
  def collection_name
51
50
  self.model_name.plural
@@ -1,6 +1,6 @@
1
1
  ## -------------------------------------------------------------------
2
2
  ##
3
- ## Copyright (c) "2014" Dmitri Zagidulin and Basho Technologies, Inc.
3
+ ## Copyright (c) "2014-2015" Dmitri Zagidulin and Basho Technologies, Inc.
4
4
  ##
5
5
  ## This file is provided to you under the Apache License,
6
6
  ## Version 2.0 (the "License"); you may not use this file
@@ -37,7 +37,7 @@ module Riagent
37
37
  end
38
38
 
39
39
  # Create a has_many association where the collection will be loaded
40
- # via RiakJson Solr queries.
40
+ # via Solr queries.
41
41
  def has_many_using_solr(name, target_class, query_type, options)
42
42
  target_getter_method = "#{name}".to_sym
43
43
 
@@ -1,6 +1,6 @@
1
1
  ## -------------------------------------------------------------------
2
2
  ##
3
- ## Copyright (c) "2014" Dmitri Zagidulin and Basho Technologies, Inc.
3
+ ## Copyright (c) "2014-2015" Dmitri Zagidulin and Basho Technologies, Inc.
4
4
  ##
5
5
  ## This file is provided to you under the Apache License,
6
6
  ## Version 2.0 (the "License"); you may not use this file
@@ -20,6 +20,7 @@
20
20
 
21
21
  require "active_support/concern"
22
22
  require "riak"
23
+ require "erb"
23
24
 
24
25
  module Riagent
25
26
  module Configuration
@@ -47,12 +48,6 @@ module Riagent
47
48
  env_config
48
49
  end
49
50
 
50
- # @param [Hash] env_config Configuration hash for a given environment
51
- def init_riak_json_client(env_config)
52
- client = RiakJson::Client.new(env_config['host'], env_config['http_port'])
53
- self.riak_json_client = client
54
- end
55
-
56
51
  # @param [Hash] env_config Configuration hash for a given environment
57
52
  def init_riak_client(env_config)
58
53
  # client = Riak::Client.new host: env_config['host'], pb_port: env_config['pb_port'], protocol: 'pbc'
@@ -67,7 +62,6 @@ module Riagent
67
62
  # @param [Symbol] environment
68
63
  def init_clients(environment=:development)
69
64
  env_config = self.config_for(environment)
70
- self.init_riak_json_client(env_config)
71
65
  self.init_riak_client(env_config)
72
66
  end
73
67
 
@@ -91,20 +85,5 @@ module Riagent
91
85
  def riak_client=(value)
92
86
  Thread.current[:riak_client] = value
93
87
  end
94
-
95
- # @return [RiakJson::Client] The RiakJson client for the current thread.
96
- def riak_json_client
97
- unless Thread.current[:riak_json_client]
98
- # Re-initialize client
99
- self.init_riak_json_client(self.config_for(Rails.env))
100
- end
101
- Thread.current[:riak_json_client]
102
- end
103
-
104
- # Sets the RiakJson client for the current thread.
105
- # @param [RiakJson::Client] value the client
106
- def riak_json_client=(value)
107
- Thread.current[:riak_json_client] = value
108
- end
109
88
  end
110
89
  end
@@ -44,7 +44,7 @@ module Riagent
44
44
  @persisted = true
45
45
  end
46
46
 
47
- # Has this document been saved to RiakJson?
47
+ # Has this document been saved to Riak?
48
48
  # Required by ActiveModel::Conversion API
49
49
  # @return [Boolean]
50
50
  def persisted?
@@ -1,6 +1,6 @@
1
1
  ## -------------------------------------------------------------------
2
2
  ##
3
- ## Copyright (c) "2014" Dmitri Zagidulin
3
+ ## Copyright (c) "2014-2015" Dmitri Zagidulin
4
4
  ##
5
5
  ## This file is provided to you under the Apache License,
6
6
  ## Version 2.0 (the "License"); you may not use this file
@@ -18,8 +18,6 @@
18
18
  ##
19
19
  ## -------------------------------------------------------------------
20
20
 
21
- require "riak_json"
22
-
23
21
  module Riagent
24
22
  module Persistence
25
23
  # Riagent document persistence strategy
@@ -64,7 +64,7 @@ module Riagent
64
64
 
65
65
  # Insert a document into the collection.
66
66
  # Also inserts the document's key into the key list set.
67
- # @param [RiakJson::ActiveDocument] document Document to be inserted
67
+ # @param [Riagent::ActiveDocument] document Document to be inserted
68
68
  # @return [String] Document key
69
69
  def insert(document)
70
70
  doc_key = super
@@ -74,7 +74,7 @@ module Riagent
74
74
  active_doc_instance
75
75
  end
76
76
 
77
- # @param [RiakJson::ActiveDocument] document Document to be inserted
77
+ # @param [Riagent::ActiveDocument] document Document to be inserted
78
78
  # @return [String] Document key
79
79
  def insert(document)
80
80
  if document.key.present?
@@ -98,13 +98,13 @@ module Riagent
98
98
  end
99
99
 
100
100
  # Deletes the riak object that stores the document
101
- # @param [RiakJson::ActiveDocument] document Document to be deleted
101
+ # @param [Riagent::ActiveDocument] document Document to be deleted
102
102
  def remove(document)
103
103
  self.new_riak_object(document.key).delete
104
104
  document.source_object = nil
105
105
  end
106
106
 
107
- # @param [RiakJson::ActiveDocument] document Document to be updated
107
+ # @param [Riagent::ActiveDocument] document Document to be updated
108
108
  # @return [Integer] Document key
109
109
  def update(document)
110
110
  self.insert(document)
@@ -21,20 +21,18 @@
21
21
  require "active_support/concern"
22
22
  require "riagent/persistence/persistence_strategy"
23
23
  require "riagent/persistence/riak_dt_set_strategy"
24
- require "riagent/persistence/riak_json_strategy"
25
24
  require "riagent/persistence/riak_no_index_strategy"
26
25
 
27
26
  module Riagent
28
- # Provides a common persistence API for RiakJson Documents.
27
+ # Provides a common persistence API for Riagent Documents.
29
28
  # Most persistence calls are delegated to the Collection class instance,
30
29
  # which are implemented in persistence/*_strategy.rb modules.
31
30
  module Persistence
32
31
  extend ActiveSupport::Concern
33
32
 
34
- COLLECTION_TYPES = [:riak_json, :riak_kv]
33
+ COLLECTION_TYPES = [:riak_kv]
35
34
 
36
35
  # Key Listing strategies for +:riak_kv+ collections
37
- # (the :riak_json collection type uses an implied solr query strategy)
38
36
  VALID_KEY_LISTS = [:streaming_list_keys, :riak_dt_set]
39
37
 
40
38
  included do
@@ -113,7 +111,8 @@ module Riagent
113
111
  # <code>
114
112
  # class SomeModel
115
113
  # include Riagent::ActiveDocument
116
- # collection_type :riak_json # persist to a RiakJson::Collection
114
+ # collection_type :riak_kv, # Persist to a Riak::Bucket
115
+ # list_keys_using: :riak_dt_set #keep track of keys in a Set CRDT data type
117
116
  # end
118
117
  # </code>
119
118
  def collection_type(coll_type, options={})
@@ -122,8 +121,6 @@ module Riagent
122
121
  end
123
122
  @collection_type = coll_type
124
123
  case @collection_type
125
- when :riak_json
126
- self.persistence = Riagent::Persistence::RiakJsonStrategy.new(self)
127
124
  when :riak_kv
128
125
  self.persistence = Riagent::Persistence::RiakKVStrategy.new(self)
129
126
  if options.has_key? :list_keys_using
@@ -19,7 +19,6 @@
19
19
  ## -------------------------------------------------------------------
20
20
 
21
21
  require 'rails/railtie'
22
- require 'riak_json'
23
22
 
24
23
  module Riagent
25
24
  # Railtie for Rails integration and initialization
@@ -19,5 +19,5 @@
19
19
  ## -------------------------------------------------------------------
20
20
 
21
21
  module Riagent
22
- VERSION = "0.0.3"
22
+ VERSION = "0.1.0"
23
23
  end
data/riagent.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  ## -------------------------------------------------------------------
3
3
  ##
4
- ## Copyright (c) "2014" Dmitri Zagidulin and Basho Technologies, Inc.
4
+ ## Copyright (c) "2014-2015" Dmitri Zagidulin and Basho Technologies, Inc.
5
5
  ##
6
6
  ## This file is provided to you under the Apache License,
7
7
  ## Version 2.0 (the "License"); you may not use this file
@@ -38,9 +38,8 @@ Gem::Specification.new do |spec|
38
38
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
39
39
  spec.require_paths = ["lib"]
40
40
 
41
- spec.add_runtime_dependency "riak_json"
42
- spec.add_runtime_dependency "riak-client", "~> 2.0.0.rc1"
43
- spec.add_runtime_dependency "riagent-document"
41
+ spec.add_runtime_dependency "riak-client", "~> 2.2"
42
+ spec.add_runtime_dependency "riagent-document", "0.0.1"
44
43
  spec.add_runtime_dependency "activemodel", "~> 4.0"
45
44
  spec.add_runtime_dependency "activesupport", "~> 4.0"
46
45
 
@@ -1,7 +1,7 @@
1
1
  # Sample riak.yml config file for running integration tests
2
2
  # Be sure to 'cp riak.yml.example riak.yml' before testing
3
3
 
4
- # Configure Riak and RiakJson connections for the client, by environment
4
+ # Configure Riak connections for the client, by environment
5
5
  development:
6
6
  http_port: 8098
7
7
  pb_port: 8087 # Protocol Buffer port
@@ -1,6 +1,6 @@
1
1
  ## -------------------------------------------------------------------
2
2
  ##
3
- ## Copyright (c) "2014" Dmitri Zagidulin and Basho Technologies, Inc.
3
+ ## Copyright (c) "2014-2015" Dmitri Zagidulin and Basho Technologies, Inc.
4
4
  ##
5
5
  ## This file is provided to you under the Apache License,
6
6
  ## Version 2.0 (the "License"); you may not use this file
@@ -26,7 +26,7 @@ require_relative 'contact'
26
26
  class AddressBook
27
27
  include Riagent::ActiveDocument
28
28
 
29
- collection_type :riak_json # Persist to a RiakJson::Collection
29
+ collection_type :riak_kv
30
30
 
31
31
  attribute :contacts, Set[Contact]
32
32
  end
@@ -1,6 +1,6 @@
1
1
  ## -------------------------------------------------------------------
2
2
  ##
3
- ## Copyright (c) "2014" Dmitri Zagidulin and Basho Technologies, Inc.
3
+ ## Copyright (c) "2014-2015" Dmitri Zagidulin and Basho Technologies, Inc.
4
4
  ##
5
5
  ## This file is provided to you under the Apache License,
6
6
  ## Version 2.0 (the "License"); you may not use this file
@@ -21,11 +21,11 @@
21
21
  class BlogPost
22
22
  include Riagent::ActiveDocument
23
23
 
24
- collection_type :riak_json # Persist to a RiakJson::Collection
24
+ collection_type :riak_kv
25
25
 
26
26
  # Explicit attributes
27
27
  # key is an implied attribute, present in all ActiveDocument instances
28
- attribute :title, String, search_index: { as: :text }
29
- attribute :description, String, search_index: { as: :text }
30
- attribute :body, String, search_index: { as: :text }
28
+ attribute :title, String
29
+ attribute :description, String
30
+ attribute :body, String
31
31
  end
@@ -1,6 +1,6 @@
1
1
  ## -------------------------------------------------------------------
2
2
  ##
3
- ## Copyright (c) "2014" Dmitri Zagidulin and Basho Technologies, Inc.
3
+ ## Copyright (c) "2014-2015" Dmitri Zagidulin and Basho Technologies, Inc.
4
4
  ##
5
5
  ## This file is provided to you under the Apache License,
6
6
  ## Version 2.0 (the "License"); you may not use this file
@@ -24,12 +24,12 @@ require_relative 'blog_post'
24
24
  class User
25
25
  include Riagent::ActiveDocument
26
26
 
27
- collection_type :riak_json # Persist to a RiakJson::Collection
27
+ collection_type :riak_kv
28
28
 
29
29
  # Explicit attributes
30
30
  # key is an implied attribute, present in all ActiveDocument instances
31
- attribute :username, String, search_index: { as: :text }
32
- attribute :email, String, search_index: { as: :string }, default: ''
31
+ attribute :username, String
32
+ attribute :email, String, default: ''
33
33
  attribute :language, String, default: 'en'
34
34
 
35
35
  # Associations
data/test/test_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  ## -------------------------------------------------------------------
2
2
  ##
3
- ## Copyright (c) "2014" Dmitri Zagidulin and Basho Technologies, Inc.
3
+ ## Copyright (c) "2014-2015" Dmitri Zagidulin and Basho Technologies, Inc.
4
4
  ##
5
5
  ## This file is provided to you under the Apache License,
6
6
  ## Version 2.0 (the "License"); you may not use this file
@@ -22,6 +22,7 @@ require 'minitest/autorun'
22
22
  require 'minitest-spec-context'
23
23
  require 'riagent'
24
24
  require 'examples/models/address_book'
25
+ require 'examples/models/blog_post'
25
26
  require 'examples/models/category'
26
27
  require 'examples/models/contact'
27
28
  require 'examples/models/user'
@@ -26,17 +26,10 @@ describe "Riagent" do
26
26
  Riagent.config.wont_be_empty # The config file was initialized by test_helper.rb
27
27
  Riagent.must_respond_to :load_config_file
28
28
  Riagent.must_respond_to :init_clients
29
- Riagent.must_respond_to :init_riak_json_client
30
- Riagent.must_respond_to :riak_json_client
31
29
  Riagent.must_respond_to :init_riak_client
32
30
  Riagent.must_respond_to :riak_client
33
31
  end
34
32
 
35
- it "initializes a RiakJson client" do
36
- # This should have been initialized from config file in test_helper.rb
37
- Riagent.riak_json_client.must_be_kind_of RiakJson::Client
38
- end
39
-
40
33
  it "initializes a Riak ruby client" do
41
34
  # This should have been initialized from config file in test_helper.rb
42
35
  Riagent.riak_client.must_be_kind_of Riak::Client
@@ -25,29 +25,13 @@ describe "a Riagent::ActiveDocument has Persistence options" do
25
25
  lambda { User.collection_type :invalid }.must_raise ArgumentError
26
26
  end
27
27
 
28
- it "#:riak_json collection_type" do
29
- # Adding the line +collection_type :riak_json+ to a model
30
- # means that it will be persisted to a RiakJson::Collection
31
- User.get_collection_type.must_equal :riak_json
32
- User.persistence.must_be_kind_of Riagent::Persistence::RiakJsonStrategy
33
-
34
- # It also grants access to a RiakJson::Client instance, to the model class
35
- User.persistence.client.must_be_kind_of RiakJson::Client
36
-
37
- User.persistence.collection.must_be_kind_of RiakJson::Collection
38
- User.persistence.collection_name.must_equal 'users'
39
-
40
- # Check to see if the RiakJson persistence strategy supports querying
41
- assert User.persistence.allows_query?
42
- end
43
-
44
28
  it "#:riak_kv collection type" do
45
29
  # Adding the line +collection_type :riak_kv+ to a model
46
30
  # means that it will be persisted as a Riak object with no indices (k/v operations only)
47
31
  UserPreference.get_collection_type.must_equal :riak_kv
48
32
  UserPreference.persistence.class.must_equal Riagent::Persistence::RiakKVStrategy
49
33
 
50
- # It also grants access to a RiakJson::Client instance, to the model class
34
+ # It also grants access to a Riak::Client instance, to the model class
51
35
  UserPreference.persistence.client.must_be_kind_of Riak::Client
52
36
 
53
37
  UserPreference.persistence.collection_name.must_equal 'user_preferences'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riagent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitri Zagidulin
@@ -10,48 +10,34 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: riak_json
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: riak-client
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: 2.0.0.rc1
19
+ version: '2.2'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: 2.0.0.rc1
26
+ version: '2.2'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: riagent-document
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ">="
31
+ - - '='
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: 0.0.1
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ">="
38
+ - - '='
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: 0.0.1
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: activemodel
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -161,11 +147,9 @@ files:
161
147
  - lib/riagent/persistence.rb
162
148
  - lib/riagent/persistence/persistence_strategy.rb
163
149
  - lib/riagent/persistence/riak_dt_set_strategy.rb
164
- - lib/riagent/persistence/riak_json_strategy.rb
165
150
  - lib/riagent/persistence/riak_kv_strategy.rb
166
151
  - lib/riagent/persistence/riak_no_index_strategy.rb
167
152
  - lib/riagent/railtie.rb
168
- - lib/riagent/search_schema.rb
169
153
  - lib/riagent/version.rb
170
154
  - riagent.gemspec
171
155
  - test/config/riak.yml.example
@@ -176,7 +160,6 @@ files:
176
160
  - test/examples/models/user.rb
177
161
  - test/examples/models/user_preference.rb
178
162
  - test/integration/persistence_riak_dt_set_integration_test.rb
179
- - test/integration/persistence_riak_json_integration_test.rb
180
163
  - test/integration/persistence_riak_kv_integration_test.rb
181
164
  - test/seeds.rb
182
165
  - test/test_helper.rb
@@ -187,11 +170,9 @@ files:
187
170
  - test/unit/config_test.rb
188
171
  - test/unit/embedded_test.rb
189
172
  - test/unit/persistence_riak_dt_set_test.rb
190
- - test/unit/persistence_riak_json_test.rb
191
173
  - test/unit/persistence_riak_kv_test.rb
192
174
  - test/unit/persistence_riak_no_index_test.rb
193
175
  - test/unit/persistence_test.rb
194
- - test/unit/search_schema_test.rb
195
176
  - test/unit/validation_test.rb
196
177
  homepage: https://github.com/dmitrizagidulin/riagent
197
178
  licenses:
@@ -226,7 +207,6 @@ test_files:
226
207
  - test/examples/models/user.rb
227
208
  - test/examples/models/user_preference.rb
228
209
  - test/integration/persistence_riak_dt_set_integration_test.rb
229
- - test/integration/persistence_riak_json_integration_test.rb
230
210
  - test/integration/persistence_riak_kv_integration_test.rb
231
211
  - test/seeds.rb
232
212
  - test/test_helper.rb
@@ -237,9 +217,7 @@ test_files:
237
217
  - test/unit/config_test.rb
238
218
  - test/unit/embedded_test.rb
239
219
  - test/unit/persistence_riak_dt_set_test.rb
240
- - test/unit/persistence_riak_json_test.rb
241
220
  - test/unit/persistence_riak_kv_test.rb
242
221
  - test/unit/persistence_riak_no_index_test.rb
243
222
  - test/unit/persistence_test.rb
244
- - test/unit/search_schema_test.rb
245
223
  - test/unit/validation_test.rb
@@ -1,121 +0,0 @@
1
- ## -------------------------------------------------------------------
2
- ##
3
- ## Copyright (c) "2014" Dmitri Zagidulin and Basho Technologies, Inc.
4
- ##
5
- ## This file is provided to you under the Apache License,
6
- ## Version 2.0 (the "License"); you may not use this file
7
- ## except in compliance with the License. You may obtain
8
- ## a copy of the License at
9
- ##
10
- ## http://www.apache.org/licenses/LICENSE-2.0
11
- ##
12
- ## Unless required by applicable law or agreed to in writing,
13
- ## software distributed under the License is distributed on an
14
- ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- ## KIND, either express or implied. See the License for the
16
- ## specific language governing permissions and limitations
17
- ## under the License.
18
- ##
19
- ## -------------------------------------------------------------------
20
-
21
- require "riak_json"
22
- require "riagent/persistence/persistence_strategy"
23
-
24
- module Riagent
25
- module Persistence
26
- class RiakJsonStrategy < PersistenceStrategy
27
- attr_writer :collection
28
-
29
- # Return all the documents in the collection
30
- # @param [Integer] results_limit Number of results returned
31
- # @return [Array|nil] of ActiveDocument instances
32
- def all(results_limit=1000)
33
- result = self.collection.all(results_limit)
34
- if result.present?
35
- result.documents.map do |doc|
36
- self.from_rj_document(doc, persisted=true)
37
- end
38
- end
39
- end
40
-
41
- # @return [Boolean] Does this persistence strategy support querying?
42
- def allows_query?
43
- true
44
- end
45
-
46
- # @return [RiakJson::Client] RiakJson client for this persistence strategy (lazy initialize)
47
- def client
48
- @client ||= Riagent.riak_json_client # See lib/configuration.rb
49
- end
50
-
51
- # @return [RiakJson::Collection] instance for this persistence strategy (lazy initialize)
52
- def collection
53
- @collection ||= self.client.collection(self.collection_name)
54
- end
55
-
56
- # Fetch a document by key.
57
- # @param [String] key
58
- # @return [ActiveDocument|nil]
59
- def find(key)
60
- return nil if key.nil? or key.empty?
61
- doc = self.collection.find_by_key(key)
62
- self.from_rj_document(doc, persisted=true)
63
- end
64
-
65
- # Return the first document that matches the query
66
- # @param [String] query RiakJson query, in JSON string form
67
- def find_one(query)
68
- if query.kind_of? Hash
69
- query = query.to_json
70
- end
71
- doc = self.collection.find_one(query)
72
- if doc.present?
73
- self.from_rj_document(doc, persisted=true)
74
- end
75
- end
76
-
77
- # Converts from a RiakJson::Document instance to an instance of ActiveDocument
78
- # @return [ActiveDocument|nil] ActiveDocument instance, or nil if the Document is nil
79
- def from_rj_document(doc, persisted=false)
80
- return nil if doc.nil?
81
- active_doc_instance = self.model_class.instantiate(doc.attributes)
82
- active_doc_instance.key = doc.key
83
- if persisted
84
- active_doc_instance.persist! # Mark as persisted / not new
85
- end
86
- active_doc_instance
87
- end
88
-
89
- # @param [RiakJson::ActiveDocument] doc Document to be inserted
90
- # @return [Integer] Document key
91
- def insert(doc)
92
- self.collection.insert(doc)
93
- end
94
-
95
- # @param [RiakJson::ActiveDocument] doc Document to be deleted
96
- def remove(doc)
97
- self.collection.remove(doc)
98
- end
99
-
100
- # @param [RiakJson::ActiveDocument] doc Document to be updated
101
- # @return [Integer] Document key
102
- def update(doc)
103
- self.collection.update(doc)
104
- end
105
-
106
- # Return all documents that match the query
107
- # @param [String] query RiakJson query, in JSON string form
108
- def where(query)
109
- if query.kind_of? Hash
110
- query = query.to_json
111
- end
112
- result = self.collection.find_all(query)
113
- if result.present?
114
- result.documents.map do |doc|
115
- self.from_rj_document(doc, persisted=true)
116
- end
117
- end
118
- end
119
- end
120
- end
121
- end
@@ -1,58 +0,0 @@
1
- ## -------------------------------------------------------------------
2
- ##
3
- ## Copyright (c) "2014" Dmitri Zagidulin and Basho Technologies, Inc.
4
- ##
5
- ## This file is provided to you under the Apache License,
6
- ## Version 2.0 (the "License"); you may not use this file
7
- ## except in compliance with the License. You may obtain
8
- ## a copy of the License at
9
- ##
10
- ## http://www.apache.org/licenses/LICENSE-2.0
11
- ##
12
- ## Unless required by applicable law or agreed to in writing,
13
- ## software distributed under the License is distributed on an
14
- ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- ## KIND, either express or implied. See the License for the
16
- ## specific language governing permissions and limitations
17
- ## under the License.
18
- ##
19
- ## -------------------------------------------------------------------
20
-
21
- module Riagent
22
- # Generates RiakJson::CollectionSchema objects (translated into Solr schemas by RiakJson)
23
- # from annotated document attributes.
24
- # Usage:
25
- # <code>
26
- # class SampleModel
27
- # include Riagent::ActiveDocument
28
- # collection_type :riak_json
29
- # attribute :name, required: true, search_index: { as: :text }
30
- # end
31
- # puts SampleModel.schema.inspect
32
- # # => <RiakJson::CollectionSchema:0x000001050eef10 @fields=[{:name=>"name", :type=>"text", :require=>true}]>
33
- #
34
- # SampleModel.save_solr_schema() # sets that schema for the collection
35
- # </code>
36
- module SearchSchema
37
- # Returns a CollectionSchema instance, derived from the document attributes
38
- def schema
39
- schema = RiakJson::CollectionSchema.new
40
- self.attribute_set.each do | attribute |
41
- if attribute.options.include? :search_index
42
- field_type = attribute.options[:search_index][:as]
43
- schema.add_field(field_type, attribute.options[:name], attribute.options[:required])
44
- end
45
- end
46
- schema
47
- end
48
-
49
- # Saves the generated Solr indexing schema to RiakJson.
50
- # Usage:
51
- # <code>
52
- # SampleModel.save_solr_schema()
53
- # </code>
54
- def save_solr_schema
55
- self.persistence.collection.set_schema(self.schema)
56
- end
57
- end
58
- end
@@ -1,76 +0,0 @@
1
- ## -------------------------------------------------------------------
2
- ##
3
- ## Copyright (c) "2014" Dmitri Zagidulin and Basho Technologies, Inc.
4
- ##
5
- ## This file is provided to you under the Apache License,
6
- ## Version 2.0 (the "License"); you may not use this file
7
- ## except in compliance with the License. You may obtain
8
- ## a copy of the License at
9
- ##
10
- ## http://www.apache.org/licenses/LICENSE-2.0
11
- ##
12
- ## Unless required by applicable law or agreed to in writing,
13
- ## software distributed under the License is distributed on an
14
- ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- ## KIND, either express or implied. See the License for the
16
- ## specific language governing permissions and limitations
17
- ## under the License.
18
- ##
19
- ## -------------------------------------------------------------------
20
-
21
- require 'test_helper'
22
-
23
- TEST_USERNAME = 'earl'
24
- TEST_USERNAME_2 = 'count'
25
-
26
- def test_user(test_key='earl-123')
27
- user = User.new username: TEST_USERNAME, email: 'earl@desandwich.com'
28
- user.key = test_key
29
- user
30
- end
31
-
32
- describe "a Riagent::ActiveDocument's Persistence Layer" do
33
- it "can save a document and generate a key" do
34
- user = User.new username: TEST_USERNAME
35
- generated_key = user.save
36
-
37
- generated_key.wont_be_nil "Key not generated from document.save"
38
- generated_key.wont_be_empty "Key not generated from document.save"
39
- generated_key.must_be_kind_of String
40
- user.key.must_equal generated_key
41
-
42
- refute user.new_record?, "Document should not be marked as new after saving"
43
- assert user.persisted?, "Document should be marked as persisted after saving"
44
-
45
- # Clean up
46
- user.destroy
47
- end
48
-
49
- it "can read, update and delete a document" do
50
- test_key = 'george-123'
51
- new_user = User.new username: 'george', email: 'george@washington.com'
52
- new_user.key = test_key
53
- new_user.save
54
-
55
- found_user = User.find(test_key) # Load User by key
56
- found_user.must_be_kind_of User
57
- found_user.key.must_equal test_key
58
- refute found_user.new_record?, "A loaded by key user object is not new"
59
- assert found_user.persisted?, "A loaded by key user object should be markes as persisted"
60
-
61
- new_attributes = {username: 'henry', email: 'henry@gmail.com' }
62
- found_user.update(new_attributes) # Also saves
63
-
64
- updated_user = User.find(test_key)
65
- updated_user.username.must_equal 'henry'
66
-
67
- found_user.destroy
68
- assert found_user.destroyed?
69
- end
70
-
71
- it "returns an empty array for queries that return no results" do
72
- query = { username: 'nonexistent' }
73
- result = User.where(query)
74
- result.must_be_empty
75
- end
76
- end
@@ -1,141 +0,0 @@
1
- ## -------------------------------------------------------------------
2
- ##
3
- ## Copyright (c) "2014" Dmitri Zagidulin and Basho Technologies, Inc.
4
- ##
5
- ## This file is provided to you under the Apache License,
6
- ## Version 2.0 (the "License"); you may not use this file
7
- ## except in compliance with the License. You may obtain
8
- ## a copy of the License at
9
- ##
10
- ## http://www.apache.org/licenses/LICENSE-2.0
11
- ##
12
- ## Unless required by applicable law or agreed to in writing,
13
- ## software distributed under the License is distributed on an
14
- ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- ## KIND, either express or implied. See the License for the
16
- ## specific language governing permissions and limitations
17
- ## under the License.
18
- ##
19
- ## -------------------------------------------------------------------
20
-
21
- require 'test_helper'
22
-
23
- describe "a Riagent::ActiveDocument that persists to RiakJson" do
24
- it "#model persistence instance methods" do
25
- user = User.new
26
-
27
- # Adding the line +collection_type :riak_json+ to a model
28
- # exposes the usual array of persistence methods
29
- user.must_respond_to :save
30
- user.must_respond_to :save!
31
- user.must_respond_to :update
32
- user.must_respond_to :update_attributes # alias for update()
33
- user.must_respond_to :update!
34
- user.must_respond_to :destroy
35
- end
36
-
37
- it "#model persistence class methods" do
38
- User.must_respond_to :all
39
- User.must_respond_to :find
40
- User.must_respond_to :find_one
41
- User.must_respond_to :where
42
- end
43
-
44
- it "saves via collection.insert()" do
45
- user = User.new
46
- User.persistence.collection = MiniTest::Mock.new
47
- User.persistence.collection.expect :insert, nil, [user]
48
-
49
- # Calling model.save() should result in a collection.insert() call
50
- user.save({:validate => false})
51
- User.persistence.collection.verify
52
-
53
- # Reset
54
- User.persistence.collection = nil
55
- end
56
-
57
- it "updates via collection.update()" do
58
- user = User.new username: 'TestUserInitial'
59
- user.persist! # Updates only make sense for a persisted document
60
- User.persistence.collection = MiniTest::Mock.new
61
- User.persistence.collection.expect :update, nil, [user]
62
-
63
- # model.update() is implemented as a save() call (with updated attributes)
64
- user.update({ username: 'TestUserNewName'} )
65
- User.persistence.collection.verify
66
-
67
- # Reset
68
- User.persistence.collection = nil
69
- end
70
-
71
- it "destroys via collection.remove()" do
72
- user = User.new
73
- user.key = 'user123'
74
- user.persist! # Remove can only be called on persisted objects that have a key
75
- User.persistence.collection = MiniTest::Mock.new
76
- User.persistence.collection.expect :remove, nil, [user]
77
-
78
- # Calling model.destroy() should result in a collection.remove() call
79
- user.destroy
80
- User.persistence.collection.verify
81
-
82
- # Reset
83
- User.persistence.collection = nil
84
- end
85
-
86
- it "returns nil when doing a find() for nil or empty key" do
87
- User.find(nil).must_be_nil
88
- User.find('').must_be_nil
89
- end
90
-
91
- it "performs a find() via collection.find_by_key()" do
92
- test_key = 'user123'
93
- User.persistence.collection = MiniTest::Mock.new
94
- User.persistence.collection.expect :find_by_key, nil, [test_key]
95
-
96
- # Calling Model class find() should result in a collection.find_by_key()
97
- User.find(test_key)
98
- User.persistence.collection.verify
99
-
100
- # Reset
101
- User.persistence.collection = nil
102
- end
103
-
104
- it "performs an all() listing via collection.all()" do
105
- User.persistence.collection = MiniTest::Mock.new
106
- User.persistence.collection.expect :all, [], [1000] # default results limit of 1000
107
-
108
- # Calling Model class where() should result in a collection.all()
109
- User.all()
110
- User.persistence.collection.verify
111
-
112
- # Reset
113
- User.persistence.collection = nil
114
- end
115
-
116
- it "performs a where() via collection.find_all()" do
117
- User.persistence.collection = MiniTest::Mock.new
118
- query = { country: 'USA' }
119
- User.persistence.collection.expect :find_all, [], [query.to_json]
120
-
121
- # Calling Model class where() should result in a collection.find_all()
122
- User.where(query)
123
- User.persistence.collection.verify
124
-
125
- # Reset
126
- User.persistence.collection = nil
127
- end
128
-
129
- it "performs a find_one() via collection.find_one()" do
130
- User.persistence.collection = MiniTest::Mock.new
131
- query = { username: 'TestUser' }
132
- User.persistence.collection.expect :find_one, [], [query.to_json]
133
-
134
- # Calling Model class find_one() should result in a collection.find_one()
135
- User.find_one(query)
136
- User.persistence.collection.verify
137
-
138
- # Reset
139
- User.persistence.collection = nil
140
- end
141
- end
@@ -1,29 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe "an Active Document" do
4
- it "can build a RiakJson schema from the annotated attributes" do
5
- schema = User.schema
6
- schema.must_be_kind_of RiakJson::CollectionSchema
7
- schema.fields.wont_be_empty
8
- schema.fields.count.must_equal 2
9
- schema.fields[0][:name].to_s.must_equal 'username'
10
- schema.fields[0][:type].must_equal 'text'
11
- schema.fields[0][:require].must_equal true
12
- schema.fields[1][:name].to_s.must_equal 'email'
13
- schema.fields[1][:type].must_equal 'string'
14
- schema.fields[1][:require].must_equal true
15
- end
16
-
17
- it "can save the Solr indexing schema to RiakJson" do
18
- schema = User.schema
19
- User.persistence.collection = MiniTest::Mock.new
20
-
21
- # Ensure that calling User.save_solr_schema() results in a call to collection.set_schema()
22
- User.persistence.collection.expect :set_schema, nil, [RiakJson::CollectionSchema]
23
- User.save_solr_schema
24
- User.persistence.collection.verify
25
-
26
- # Reset
27
- User.persistence.collection = nil
28
- end
29
- end