rdy 0.1.2 → 0.1.3
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.
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/rdy.rb +12 -14
- data/test/helper.rb +3 -0
- data/test/test_rdy.rb +92 -2
- metadata +11 -13
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/rdy.rb
CHANGED
@@ -3,9 +3,6 @@ gem "aws-sdk"
|
|
3
3
|
require "aws-sdk"
|
4
4
|
|
5
5
|
class Rdy
|
6
|
-
RESERVED = ["attributes", "hash_value", "hash_key", "is_new?", "all", "find", "save",
|
7
|
-
"create_table", "table", "table=", "destroy", "dynamodb"]
|
8
|
-
|
9
6
|
def initialize(table, hash_key)
|
10
7
|
@attributes = {}; @table = table; @hash_key = hash_key; @is_new = true
|
11
8
|
@_table = Rdy.dynamo_db.tables[@table]
|
@@ -33,8 +30,12 @@ class Rdy
|
|
33
30
|
raise "missing hash value" if hash_value.nil?
|
34
31
|
@_item = @_table.items[hash_value]
|
35
32
|
@attributes.clear
|
36
|
-
@_item.attributes.
|
37
|
-
|
33
|
+
if @_item.attributes.any?
|
34
|
+
@_item.attributes.to_h.each {|k, v| self.send("#{k}=".to_sym, v) unless k == @hash_key }
|
35
|
+
@hash_value = hash_value; @is_new = false
|
36
|
+
else
|
37
|
+
@hash_value = nil
|
38
|
+
end
|
38
39
|
@attributes
|
39
40
|
end
|
40
41
|
|
@@ -44,7 +45,8 @@ class Rdy
|
|
44
45
|
@_item = @_table.items.create(@hash_key.to_sym => hash_value) if is_new?
|
45
46
|
if @_item
|
46
47
|
@_item.attributes.set(@attributes)
|
47
|
-
@
|
48
|
+
@hash_value = hash_value if is_new?
|
49
|
+
@is_new = false
|
48
50
|
@_item.attributes.to_h
|
49
51
|
end
|
50
52
|
end
|
@@ -58,14 +60,10 @@ class Rdy
|
|
58
60
|
|
59
61
|
private
|
60
62
|
def method_missing(method, *args, &block)
|
61
|
-
if
|
62
|
-
|
63
|
+
if method.to_s[-1, 1] == '='
|
64
|
+
@attributes[method.to_s.gsub('=', '')] = args.first
|
63
65
|
else
|
64
|
-
|
65
|
-
@attributes[method.to_s.gsub('=', '')] = args.first
|
66
|
-
else
|
67
|
-
@attributes[method.to_s]
|
68
|
-
end
|
66
|
+
@attributes[method.to_s]
|
69
67
|
end
|
70
68
|
end
|
71
|
-
end
|
69
|
+
end
|
data/test/helper.rb
CHANGED
@@ -14,5 +14,8 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
14
14
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
15
|
require 'rdy'
|
16
16
|
|
17
|
+
puts "Setting up test table for Rdy..."
|
18
|
+
Rdy.create_table("rdy_test", 10, 5, :id => :string)
|
19
|
+
|
17
20
|
class Test::Unit::TestCase
|
18
21
|
end
|
data/test/test_rdy.rb
CHANGED
@@ -1,7 +1,97 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestRdy < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
4
|
+
def rdy
|
5
|
+
@rdy = Rdy.new('rdy_test', 'id')
|
6
|
+
end
|
7
|
+
|
8
|
+
should "create an Rdy instance" do
|
9
|
+
rdy = Rdy.new('rdy_test', 'id')
|
10
|
+
assert_equal rdy.table, 'rdy_test'
|
11
|
+
assert_equal rdy.hash_key, 'id'
|
12
|
+
assert_nil rdy.hash_value, nil
|
13
|
+
end
|
14
|
+
|
15
|
+
context "Attributes" do
|
16
|
+
setup do
|
17
|
+
rdy
|
18
|
+
end
|
19
|
+
|
20
|
+
should "create assign a value to an attribute" do
|
21
|
+
@rdy.foo = "bar"
|
22
|
+
@rdy.bar = 23
|
23
|
+
@rdy.flag = true
|
24
|
+
assert_equal @rdy.foo, "bar"
|
25
|
+
assert_equal @rdy.bar, 23
|
26
|
+
assert @rdy.flag
|
27
|
+
end
|
28
|
+
|
29
|
+
should "have values in attributes hash" do
|
30
|
+
assert @rdy.attributes.empty?
|
31
|
+
@rdy.foo = "bar"
|
32
|
+
assert_equal @rdy.foo, "bar"
|
33
|
+
assert_equal @rdy.attributes.size, 1
|
34
|
+
assert_equal @rdy.attributes['foo'], 'bar'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "Creating" do
|
39
|
+
setup do
|
40
|
+
rdy
|
41
|
+
end
|
42
|
+
|
43
|
+
should "save an item" do
|
44
|
+
assert @rdy.is_new?
|
45
|
+
@rdy.foo = "bar"
|
46
|
+
assert_equal @rdy.foo, "bar"
|
47
|
+
assert_equal @rdy.table, "rdy_test"
|
48
|
+
assert_nil @rdy.hash_value
|
49
|
+
attributes = @rdy.save('1')
|
50
|
+
assert_equal @rdy.hash_value, '1'
|
51
|
+
assert_equal attributes.size, 2
|
52
|
+
assert attributes.keys.include?('id')
|
53
|
+
assert attributes.keys.include?('foo')
|
54
|
+
assert !@rdy.is_new?
|
55
|
+
@rdy.destroy
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "Updating" do
|
60
|
+
setup do
|
61
|
+
rdy
|
62
|
+
end
|
63
|
+
|
64
|
+
should "update an item" do
|
65
|
+
@rdy.foo = "bar"
|
66
|
+
attributes = @rdy.save("2")
|
67
|
+
assert !@rdy.is_new?
|
68
|
+
assert_equal @rdy.hash_value, "2"
|
69
|
+
assert_equal @rdy.foo, "bar"
|
70
|
+
assert_equal attributes['foo'], "bar"
|
71
|
+
@rdy.foo = "bar2"
|
72
|
+
attributes = @rdy.save
|
73
|
+
assert !@rdy.is_new?
|
74
|
+
assert_equal @rdy.hash_value, "2"
|
75
|
+
assert_equal @rdy.foo, "bar2"
|
76
|
+
assert_equal attributes['foo'], "bar2"
|
77
|
+
@rdy.destroy
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "Destroying" do
|
82
|
+
setup do
|
83
|
+
rdy
|
84
|
+
end
|
85
|
+
|
86
|
+
should "destroy an item" do
|
87
|
+
@rdy.foo = "bar"
|
88
|
+
attributes = @rdy.save("3")
|
89
|
+
@rdy.find("3")
|
90
|
+
assert_not_nil @rdy.foo
|
91
|
+
assert_equal @rdy.foo, "bar"
|
92
|
+
@rdy.destroy
|
93
|
+
@rdy.find("3")
|
94
|
+
assert_nil @rdy.hash_value
|
95
|
+
end
|
6
96
|
end
|
7
97
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Oliver Kiessler
|
@@ -15,11 +15,9 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
19
|
-
default_executable:
|
18
|
+
date: 2012-02-13 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
|
-
name: aws-sdk
|
23
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
22
|
none: false
|
25
23
|
requirements:
|
@@ -31,11 +29,11 @@ dependencies:
|
|
31
29
|
- 3
|
32
30
|
- 2
|
33
31
|
version: 1.3.2
|
32
|
+
name: aws-sdk
|
34
33
|
prerelease: false
|
35
34
|
type: :runtime
|
36
35
|
requirement: *id001
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
|
-
name: shoulda
|
39
37
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
38
|
none: false
|
41
39
|
requirements:
|
@@ -45,11 +43,11 @@ dependencies:
|
|
45
43
|
segments:
|
46
44
|
- 0
|
47
45
|
version: "0"
|
46
|
+
name: shoulda
|
48
47
|
prerelease: false
|
49
48
|
type: :development
|
50
49
|
requirement: *id002
|
51
50
|
- !ruby/object:Gem::Dependency
|
52
|
-
name: bundler
|
53
51
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
52
|
none: false
|
55
53
|
requirements:
|
@@ -61,11 +59,11 @@ dependencies:
|
|
61
59
|
- 0
|
62
60
|
- 0
|
63
61
|
version: 1.0.0
|
62
|
+
name: bundler
|
64
63
|
prerelease: false
|
65
64
|
type: :development
|
66
65
|
requirement: *id003
|
67
66
|
- !ruby/object:Gem::Dependency
|
68
|
-
name: jeweler
|
69
67
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
70
68
|
none: false
|
71
69
|
requirements:
|
@@ -77,11 +75,11 @@ dependencies:
|
|
77
75
|
- 6
|
78
76
|
- 4
|
79
77
|
version: 1.6.4
|
78
|
+
name: jeweler
|
80
79
|
prerelease: false
|
81
80
|
type: :development
|
82
81
|
requirement: *id004
|
83
82
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: rcov
|
85
83
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
86
84
|
none: false
|
87
85
|
requirements:
|
@@ -91,11 +89,11 @@ dependencies:
|
|
91
89
|
segments:
|
92
90
|
- 0
|
93
91
|
version: "0"
|
92
|
+
name: rcov
|
94
93
|
prerelease: false
|
95
94
|
type: :development
|
96
95
|
requirement: *id005
|
97
96
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: aws-sdk
|
99
97
|
version_requirements: &id006 !ruby/object:Gem::Requirement
|
100
98
|
none: false
|
101
99
|
requirements:
|
@@ -105,6 +103,7 @@ dependencies:
|
|
105
103
|
segments:
|
106
104
|
- 0
|
107
105
|
version: "0"
|
106
|
+
name: aws-sdk
|
108
107
|
prerelease: false
|
109
108
|
type: :runtime
|
110
109
|
requirement: *id006
|
@@ -129,7 +128,6 @@ files:
|
|
129
128
|
- rdy.sample.yml
|
130
129
|
- test/helper.rb
|
131
130
|
- test/test_rdy.rb
|
132
|
-
has_rdoc: true
|
133
131
|
homepage: http://github.com/okiess/rdy
|
134
132
|
licenses:
|
135
133
|
- MIT
|
@@ -159,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
157
|
requirements: []
|
160
158
|
|
161
159
|
rubyforge_project:
|
162
|
-
rubygems_version: 1.
|
160
|
+
rubygems_version: 1.8.15
|
163
161
|
signing_key:
|
164
162
|
specification_version: 3
|
165
163
|
summary: Simple ruby client for Amazon DynamoDB
|