dynamoid 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/Dynamoid.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "dynamoid"
8
- s.version = "0.3.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Josh Symonds"]
12
- s.date = "2012-03-28"
12
+ s.date = "2012-04-13"
13
13
  s.description = "Dynamoid is an ORM for Amazon's DynamoDB that supports offline development, associations, querying, and everything else you'd expect from an ActiveRecord-style replacement."
14
14
  s.email = "josh@joshsymonds.com"
15
15
  s.extra_rdoc_files = [
@@ -147,7 +147,6 @@ Gem::Specification.new do |s|
147
147
  s.add_development_dependency(%q<rspec>, [">= 0"])
148
148
  s.add_development_dependency(%q<bundler>, [">= 0"])
149
149
  s.add_development_dependency(%q<jeweler>, [">= 0"])
150
- s.add_development_dependency(%q<rcov>, [">= 0"])
151
150
  s.add_development_dependency(%q<yard>, [">= 0"])
152
151
  s.add_development_dependency(%q<redcarpet>, ["= 1.17.2"])
153
152
  s.add_development_dependency(%q<github-markup>, [">= 0"])
@@ -160,7 +159,6 @@ Gem::Specification.new do |s|
160
159
  s.add_dependency(%q<rspec>, [">= 0"])
161
160
  s.add_dependency(%q<bundler>, [">= 0"])
162
161
  s.add_dependency(%q<jeweler>, [">= 0"])
163
- s.add_dependency(%q<rcov>, [">= 0"])
164
162
  s.add_dependency(%q<yard>, [">= 0"])
165
163
  s.add_dependency(%q<redcarpet>, ["= 1.17.2"])
166
164
  s.add_dependency(%q<github-markup>, [">= 0"])
@@ -174,7 +172,6 @@ Gem::Specification.new do |s|
174
172
  s.add_dependency(%q<rspec>, [">= 0"])
175
173
  s.add_dependency(%q<bundler>, [">= 0"])
176
174
  s.add_dependency(%q<jeweler>, [">= 0"])
177
- s.add_dependency(%q<rcov>, [">= 0"])
178
175
  s.add_dependency(%q<yard>, [">= 0"])
179
176
  s.add_dependency(%q<redcarpet>, ["= 1.17.2"])
180
177
  s.add_dependency(%q<github-markup>, [">= 0"])
data/Gemfile CHANGED
@@ -15,7 +15,6 @@ group :development do
15
15
  gem "rspec"
16
16
  gem "bundler"
17
17
  gem "jeweler"
18
- gem "rcov"
19
18
  gem "yard"
20
19
  gem "redcarpet", '1.17.2'
21
20
  gem 'github-markup'
data/Gemfile.lock CHANGED
@@ -32,7 +32,6 @@ GEM
32
32
  multi_xml (0.4.1)
33
33
  nokogiri (1.5.0)
34
34
  rake (0.9.2.2)
35
- rcov (0.9.11)
36
35
  redcarpet (1.17.2)
37
36
  rspec (2.8.0)
38
37
  rspec-core (~> 2.8.0)
@@ -57,7 +56,6 @@ DEPENDENCIES
57
56
  jeweler
58
57
  mocha
59
58
  rake
60
- rcov
61
59
  redcarpet (= 1.17.2)
62
60
  rspec
63
61
  tzinfo
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -80,8 +80,7 @@ module Dynamoid
80
80
  #
81
81
  # @since 0.2.0
82
82
  def delete_item(table_name, key, range_key = nil)
83
- table = @@connection.tables[table_name]
84
- table.load_schema
83
+ table = get_table(table_name)
85
84
  result = if table.composite_key?
86
85
  table.items.at(key, range_key)
87
86
  else
@@ -113,8 +112,7 @@ module Dynamoid
113
112
  #
114
113
  # @since 0.2.0
115
114
  def get_item(table_name, key, range_key = nil)
116
- table = @@connection.tables[table_name]
117
- table.load_schema
115
+ table = get_table(table_name)
118
116
  result = if table.composite_key?
119
117
  table.items.at(key, range_key)
120
118
  else
@@ -141,8 +139,7 @@ module Dynamoid
141
139
  #
142
140
  # @since 0.2.0
143
141
  def put_item(table_name, object)
144
- table = @@connection.tables[table_name]
145
- table.load_schema
142
+ table = get_table(table_name)
146
143
  table.items.create(object.delete_if{|k, v| v.nil? || (v.respond_to?(:empty?) && v.empty?)})
147
144
  end
148
145
 
@@ -163,8 +160,7 @@ module Dynamoid
163
160
  #
164
161
  # @since 0.2.0
165
162
  def query(table_name, opts = {})
166
- table = @@connection.tables[table_name]
167
- table.load_schema
163
+ table = get_table(table_name)
168
164
 
169
165
  if table.composite_key?
170
166
  results = []
@@ -185,8 +181,7 @@ module Dynamoid
185
181
  #
186
182
  # @since 0.2.0
187
183
  def scan(table_name, scan_hash)
188
- table = @@connection.tables[table_name]
189
- table.load_schema
184
+ table = get_table(table_name)
190
185
  results = []
191
186
  table.items.where(scan_hash).select do |data|
192
187
  results << data.attributes.symbolize_keys!
@@ -197,6 +192,19 @@ module Dynamoid
197
192
  # @todo Add an UpdateItem method.
198
193
 
199
194
  # @todo Add an UpdateTable method.
195
+
196
+ def get_table(table_name)
197
+ unless table = table_cache[table_name]
198
+ table = @@connection.tables[table_name]
199
+ table.load_schema
200
+ table_cache[table_name] = table
201
+ end
202
+ table
203
+ end
204
+
205
+ def table_cache
206
+ @table_cache ||= {}
207
+ end
200
208
  end
201
209
  end
202
210
  end
@@ -13,7 +13,7 @@ module Dynamoid #:nodoc:
13
13
 
14
14
  include Enumerable
15
15
  # Delegate methods to the records the association represents.
16
- delegate :first, :last, :empty?, :size, :to => :records
16
+ delegate :first, :last, :empty?, :size, :class, :to => :records
17
17
 
18
18
  # The records associated to the source.
19
19
  #
@@ -4,6 +4,7 @@ module Dynamoid #:nodoc:
4
4
  module Associations
5
5
  module SingleAssociation
6
6
 
7
+ delegate :class, :to => :target
7
8
 
8
9
  def setter(object)
9
10
  delete
@@ -59,6 +60,7 @@ module Dynamoid #:nodoc:
59
60
  #
60
61
  # @since 0.2.0
61
62
  def target
63
+ return if source_ids.empty?
62
64
  target_class.find(source_ids.first)
63
65
  end
64
66
  end
@@ -38,7 +38,8 @@ module Dynamoid
38
38
  #
39
39
  # @since 0.2.0
40
40
  def undump(incoming = nil)
41
- (incoming ||= {}).symbolize_keys!
41
+ incoming ||= {}
42
+ incoming = incoming.symbolize_keys
42
43
  Hash.new.tap do |hash|
43
44
  self.attributes.each do |attribute, options|
44
45
  hash[attribute] = undump_field(incoming[attribute], options[:type])
@@ -167,4 +167,14 @@ describe "Dynamoid::Associations::Association" do
167
167
  Subscription.all.should be_empty
168
168
  end
169
169
 
170
+ it 'delegates class to the association object' do
171
+ @magazine.sponsor.class.should == nil.class
172
+ @magazine.sponsor.create
173
+ @magazine.sponsor.class.should == Sponsor
174
+
175
+ @magazine.subscriptions.class.should == Array
176
+ @magazine.subscriptions.create
177
+ @magazine.subscriptions.class.should == Array
178
+ end
179
+
170
180
  end
@@ -94,6 +94,9 @@ describe "Dynamoid::Indexes::Index" do
94
94
  @index = Dynamoid::Indexes::Index.new(User, :name)
95
95
  @user = User.create(:name => 'Josh', :password => 'test123', :last_logged_in_at => @time, :id => 'test123')
96
96
 
97
+ Dynamoid::Adapter.read("dynamoid_tests_index_user_names", 'Josh')[:ids].should == Set['test123']
98
+ Dynamoid::Adapter.read("dynamoid_tests_index_user_names", 'Justin').should be_nil
99
+
97
100
  @user.update_attributes(:name => 'Justin')
98
101
 
99
102
  Dynamoid::Adapter.read("dynamoid_tests_index_user_names", 'Josh')[:ids].should be_nil
@@ -138,5 +138,11 @@ describe "Dynamoid::Persistence" do
138
138
 
139
139
  @address.city_was.should == 'Chicago'
140
140
  end
141
+
142
+ it 'works with a HashWithIndifferentAccess' do
143
+ hash = ActiveSupport::HashWithIndifferentAccess.new("test" => "hi", "hello" => "there")
144
+
145
+ lambda {Address.create(hash)}.should_not raise_error
146
+ end
141
147
 
142
148
  end
data/spec/spec_helper.rb CHANGED
@@ -34,8 +34,7 @@ RSpec.configure do |config|
34
34
  config.before(:each) do
35
35
  Dynamoid::Adapter.list_tables.each do |table|
36
36
  if table =~ /^#{Dynamoid::Config.namespace}/
37
- table = Dynamoid::Adapter.connection.tables[table]
38
- table.load_schema
37
+ table = Dynamoid::Adapter.get_table(table)
39
38
  table.items.each {|i| i.delete}
40
39
  end
41
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-28 00:00:00.000000000 Z
12
+ date: 2012-04-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -139,22 +139,6 @@ dependencies:
139
139
  - - ! '>='
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
- - !ruby/object:Gem::Dependency
143
- name: rcov
144
- requirement: !ruby/object:Gem::Requirement
145
- none: false
146
- requirements:
147
- - - ! '>='
148
- - !ruby/object:Gem::Version
149
- version: '0'
150
- type: :development
151
- prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
155
- - - ! '>='
156
- - !ruby/object:Gem::Version
157
- version: '0'
158
142
  - !ruby/object:Gem::Dependency
159
143
  name: yard
160
144
  requirement: !ruby/object:Gem::Requirement
@@ -339,7 +323,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
339
323
  version: '0'
340
324
  segments:
341
325
  - 0
342
- hash: 3564635141636457738
326
+ hash: -3469435930432077068
343
327
  required_rubygems_version: !ruby/object:Gem::Requirement
344
328
  none: false
345
329
  requirements: