rdy 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -5
- data/VERSION +1 -1
- data/lib/rdy.rb +17 -11
- metadata +3 -3
data/README.md
CHANGED
@@ -5,18 +5,23 @@ Fun little ruby client for Amazon DynamoDB.
|
|
5
5
|
rdy = Rdy.new("your_table", "your_hash_value")
|
6
6
|
rdy.any_attribute = "nice!"
|
7
7
|
rdy.foo = "bar"
|
8
|
-
rdy.save("1")
|
8
|
+
rdy.save("1") # hash key value
|
9
9
|
|
10
10
|
rdy.foo = "bar2"
|
11
|
-
rdy.save
|
11
|
+
rdy.save # update
|
12
12
|
|
13
13
|
rdy.any_attribute = nil
|
14
|
-
rdy.save
|
14
|
+
rdy.save # delete an attribute
|
15
15
|
|
16
|
-
rdy.find("1")
|
17
|
-
rdy.destroy
|
16
|
+
rdy.find("1") # find by hash key value
|
17
|
+
rdy.destroy # delete item
|
18
18
|
|
19
19
|
rdy.all
|
20
|
+
|
21
|
+
read_capacity_units = 10
|
22
|
+
write_capacity_units = 5
|
23
|
+
Rdy.create_table("rdy", read_capacity_units, write_capacity_units, :id => :string) # hash key only
|
24
|
+
Rdy.create_table("rdy2", read_capacity_units, write_capacity_units, {:id => :string}, {:comment_id => :number}) # hash and range key
|
20
25
|
|
21
26
|
Advanced features like queries, scans etc. are not supported yet.
|
22
27
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/rdy.rb
CHANGED
@@ -4,18 +4,11 @@ require "aws-sdk"
|
|
4
4
|
|
5
5
|
class Rdy
|
6
6
|
RESERVED = ["attributes", "hash_value", "hash_key", "is_new?", "all", "find", "save",
|
7
|
-
"
|
7
|
+
"create_table", "table", "table=", "destroy", "dynamodb"]
|
8
8
|
|
9
9
|
def initialize(table, hash_key)
|
10
|
-
@attributes = {}
|
11
|
-
@
|
12
|
-
@hash_key = hash_key
|
13
|
-
config = YAML.load(File.read("#{ENV['HOME']}/.rdy.yml"))
|
14
|
-
raise "Config file expected in ~/.rdy.yml" unless config
|
15
|
-
@dynamo_db = AWS::DynamoDB.new(:access_key_id => config['access_key_id'],
|
16
|
-
:secret_access_key => config['secret_access_key'])
|
17
|
-
@is_new = true
|
18
|
-
@_table = @dynamo_db.tables[@table]
|
10
|
+
@attributes = {}; @table = table; @hash_key = hash_key; @is_new = true
|
11
|
+
@_table = Rdy.dynamo_db.tables[@table]
|
19
12
|
@_table.status
|
20
13
|
end
|
21
14
|
|
@@ -24,7 +17,19 @@ class Rdy
|
|
24
17
|
def attributes; @attributes; end
|
25
18
|
def hash_value; @hash_value; end
|
26
19
|
def hash_key; @hash_key; end
|
27
|
-
|
20
|
+
|
21
|
+
def self.dynamo_db
|
22
|
+
config = YAML.load(File.read("#{ENV['HOME']}/.rdy.yml"))
|
23
|
+
raise "Config file expected in ~/.rdy.yml" unless config
|
24
|
+
@@dynamo_db = AWS::DynamoDB.new(:access_key_id => config['access_key_id'],
|
25
|
+
:secret_access_key => config['secret_access_key'])
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.create_table(table, read_capacity_units, write_capacity_units, hash_key, range_key = nil)
|
29
|
+
dynamo_db.tables.create(table, read_capacity_units, write_capacity_units,
|
30
|
+
:hash_key => hash_key, :range_key => range_key)
|
31
|
+
end
|
32
|
+
|
28
33
|
def all; @_table.items.collect {|i| i.attributes.to_h }; end
|
29
34
|
def find(hash_value)
|
30
35
|
it = @_table.items[hash_value]
|
@@ -34,6 +39,7 @@ class Rdy
|
|
34
39
|
@attributes
|
35
40
|
end
|
36
41
|
|
42
|
+
def is_new?; @is_new; end
|
37
43
|
def save(hash_value = nil)
|
38
44
|
raise "missing hash value" if hash_value.nil? and is_new?
|
39
45
|
@_item = item = @_table.items.create(@hash_key.to_sym => hash_value) if is_new?
|
metadata
CHANGED