commutator 0.1.1 → 0.2.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: 48ccc3f1fbd5002ddd24c28e9ac78c1e9768c123
4
- data.tar.gz: 60eac8308078a21d24cc45112c3093ced30116f8
3
+ metadata.gz: dffefbc083f0f661a472dc48a7f9eb973e0cf42c
4
+ data.tar.gz: b8f9ef383327ba1f1c8fcd106b6708bfa2e1011b
5
5
  SHA512:
6
- metadata.gz: f1e28a291d82044addad086e6715819711c0a1c01e57ebabdd56b4d88a2daa32d38ffcbc375611cea8dd1c5f95e7db3a5eee52f4ea0c79cfd22cb3b0edbd76b6
7
- data.tar.gz: d77480d5eec6b8be9be9e77636a83422bbe81ad6011a94c6d9e9671baf2d04e673e0a56ad626c675e13121e245f7878c9be9951a5831766219faff41dd3e1180
6
+ metadata.gz: e08de421af87b4f1e44b015d4fba944842103d604104cad7920317c80aef3a493e3651738819954bebc82aef73d80ad39888b4604b9c887a63ebc948129fbdb1
7
+ data.tar.gz: 1b3fa727463ae2bcf2962447cb49944cb782c1c985716b6ccf3afda4cf72fd879028b7efaca89bf7384c80d3b23a405b50fa5820a3e7b059c2cddb37df18b481
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /Gemfile-custom
11
+ /spec/examples.txt
@@ -1,7 +1,18 @@
1
1
  ### Development
2
- [Full Changelog](http://github.com/tablexi/commutator/compare/v0.1.1...master)
2
+ [Full Changelog](http://github.com/tablexi/commutator/compare/v0.2.0...master)
3
3
 
4
- ### Development
4
+ ### 0.2.0 / 2016-03-07
5
+
6
+ Features:
7
+
8
+ * Can configure table name at the instance level. (Bradley Schaefer)
9
+ * Port over a ton of Ben Kimpel's tests (Bradley Schaefer)
10
+
11
+ Bug fixes:
12
+
13
+ * Resolve a concurrency bug involving lazy instantiation (Bradley Schaefer)
14
+
15
+ ### 0.1.1 / 2016-01-15
5
16
  [Full Changelog](http://github.com/tablexi/commutator/compare/v0.1.0...v0.1.1)
6
17
 
7
18
  Features:
data/README.md CHANGED
@@ -71,7 +71,12 @@ Color.create(name: "Black", hex_color: "#000000")
71
71
 
72
72
  ## Development
73
73
 
74
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
74
+ After checking out the repo, run `bin/setup` to install dependencies.
75
+
76
+ DynamoDB Local is also required for running tests [tagged with :dynamo => true](/spec/spec_helper#L6). Check the
77
+ [Amazon Documentation for Downloading and Running DynamoDB Local](http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tools.DynamoDBLocal.html#Tools.DynamoDBLocal.DownloadingAndRunning).
78
+
79
+ Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
75
80
 
76
81
  To install this gem onto your local machine, run `bundle exec rake install`.
77
82
 
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency "activemodel", "~> 4.0"
27
27
  spec.add_dependency "aws-sdk", "~> 2.1"
28
28
  spec.add_dependency "ice_nine"
29
+ spec.add_dependency "concurrent-ruby", "~> 1.0"
29
30
  end
@@ -1,7 +1,8 @@
1
1
  require "aws-sdk"
2
2
 
3
- require "active_model"
3
+ require "concurrent/map"
4
4
 
5
+ require "active_model"
5
6
  require "active_support"
6
7
  require "active_support/core_ext"
7
8
 
@@ -50,6 +50,9 @@ module Commutator
50
50
  class_attribute :collection_item_modifiers, instance_accessor: false
51
51
  class_attribute :client
52
52
  self.client = ::Commutator::SimpleClient.new
53
+
54
+ class_attribute :scoped_options, instance_accessor: false
55
+ self.scoped_options = options_cache_class
53
56
  end
54
57
 
55
58
  delegate :options_class, to: 'self.class'
@@ -139,6 +142,7 @@ module Commutator
139
142
  subclass.table_name(table_name)
140
143
  subclass.primary_key(hash: primary_key_hash_name,
141
144
  range: primary_key_range_name)
145
+ subclass.scoped_options = option_class_cache
142
146
 
143
147
  scopes = const_defined?("Scopes", false) ? const_get("Scopes") : nil
144
148
  subclass.const_set("Scopes", Module.new { include scopes }) if scopes
@@ -184,12 +188,7 @@ module Commutator
184
188
  end
185
189
 
186
190
  def options_class(operation)
187
- @scoped_options ||= Hash.new do |h, k|
188
- scopes = self.const_defined?("Scopes", false) ? self.const_get("Scopes") : nil
189
- const_name = k.to_s.camelize
190
- h[k] = enhance_options(const_name, scopes)
191
- end
192
- @scoped_options[operation]
191
+ scoped_options[operation]
193
192
  end
194
193
 
195
194
  def method_missing(method, *args)
@@ -203,13 +202,27 @@ module Commutator
203
202
 
204
203
  private
205
204
 
205
+ def options_cache_class
206
+ Concurrent::Map.new do |h, k|
207
+ scopes = self.const_defined?("Scopes", false) ? self.const_get("Scopes") : nil
208
+ h.compute_if_absent(k) do
209
+ const_name = k.to_s.camelize
210
+ enhance_options(const_name, scopes)
211
+ end
212
+ end
213
+ end
214
+
206
215
  def enhance_options(const_name, scopes = nil)
207
- Class.new(Options.const_get(const_name)) do
216
+ Class.new(Options.const_get(const_name, false)) do
208
217
  include ::Commutator::Util::Fluent
209
218
  include scopes if scopes && %w[Query Scan].include?(const_name)
210
219
 
211
220
  fluent_accessor :_proxy
212
221
  delegate :context, to: :_proxy
222
+
223
+ def inspect
224
+ "#{const_name}Proxy (#{(public_methods.sort - Object.methods).join(", ")})"
225
+ end
213
226
  end
214
227
  end
215
228
 
@@ -16,8 +16,17 @@ module Commutator
16
16
  send(primary_key_range_name) if primary_key_range_name.present?
17
17
  end
18
18
 
19
- def table_name
20
- self.class.table_name
19
+ included do
20
+ class_attribute :table_name
21
+
22
+ class << self
23
+ prepend(Module.new do
24
+ def table_name(*args)
25
+ return super if args.size == 0
26
+ send("table_name=", *args)
27
+ end
28
+ end)
29
+ end
21
30
  end
22
31
 
23
32
  # :nodoc:
@@ -1,3 +1,3 @@
1
1
  module Commutator
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commutator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bradley Schaefer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-01-15 00:00:00.000000000 Z
12
+ date: 2016-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -109,6 +109,20 @@ dependencies:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: concurrent-ruby
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '1.0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '1.0'
112
126
  description: Model object interface for Amazon DynamoDB.
113
127
  email:
114
128
  - bradley.schaefer@gmail.com