rdy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+ gem "aws-sdk", ">= 1.3.2"
3
+ group :development do
4
+ gem "shoulda", ">= 0"
5
+ gem "bundler", "~> 1.0.0"
6
+ gem "jeweler", "~> 1.6.4"
7
+ gem "rcov", ">= 0"
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ aws-sdk (1.3.2)
5
+ httparty (~> 0.7)
6
+ json (~> 1.4)
7
+ nokogiri (>= 1.4.4)
8
+ uuidtools (~> 2.1)
9
+ git (1.2.5)
10
+ httparty (0.8.1)
11
+ multi_json
12
+ multi_xml
13
+ jeweler (1.6.4)
14
+ bundler (~> 1.0)
15
+ git (>= 1.2.5)
16
+ rake
17
+ json (1.6.5)
18
+ multi_json (1.0.4)
19
+ multi_xml (0.4.1)
20
+ nokogiri (1.5.0)
21
+ rake (0.9.2.2)
22
+ rcov (1.0.0)
23
+ shoulda (2.11.3)
24
+ uuidtools (2.1.2)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ aws-sdk (>= 1.3.2)
31
+ bundler (~> 1.0.0)
32
+ jeweler (~> 1.6.4)
33
+ rcov
34
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Oliver Kiessler
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # rdy
2
+
3
+ Fun little ruby client for Amazon DynamoDB.
4
+
5
+ rdy = Rdy.new("your_table", "your_hash_value")
6
+ rdy.any_attribute = "nice!"
7
+ rdy.foo = "bar"
8
+ rdy.save("1")
9
+
10
+ rdy.foo = "bar2"
11
+ rdy.save
12
+
13
+ rdy.any_attribute = nil
14
+ rdy.save
15
+
16
+ rdy.find("1")
17
+ rdy.destroy
18
+
19
+ rdy.all
20
+
21
+ Advanced features like queries, scans etc. are not supported yet.
22
+
23
+ ## Contributing to rdy
24
+
25
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
26
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
27
+ * Fork the project
28
+ * Start a feature/bugfix branch
29
+ * Commit and push until you are happy with your contribution
30
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
31
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
32
+
33
+ ## Copyright
34
+
35
+ Copyright (c) 2012 Oliver Kiessler. See LICENSE.txt for
36
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rdy"
18
+ gem.homepage = "http://github.com/okiess/rdy"
19
+ gem.license = "MIT"
20
+ gem.summary = "Simple ruby client for Amazon DynamoDB"
21
+ gem.description = "Wrapper class for the DynamoDB AWS-SDK"
22
+ gem.email = "kiessler@inceedo.com"
23
+ gem.authors = ["Oliver Kiessler"]
24
+ gem.add_runtime_dependency 'aws-sdk'
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "rdy #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/rdy.rb ADDED
@@ -0,0 +1,65 @@
1
+ require "rubygems"
2
+ gem "aws-sdk"
3
+ require "aws-sdk"
4
+
5
+ class Rdy
6
+ RESERVED = ["attributes", "hash_value", "hash_key", "is_new?", "all", "find", "save",
7
+ "create", "table", "table=", "destroy"]
8
+
9
+ def initialize(table, hash_key)
10
+ @attributes = {}
11
+ @table = table
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]
19
+ @_table.status
20
+ end
21
+
22
+ def table=(value); @table = value; end
23
+ def table; @table; end
24
+ def attributes; @attributes; end
25
+ def hash_value; @hash_value; end
26
+ def hash_key; @hash_key; end
27
+ def is_new?; @is_new; end
28
+ def all; @_table.items.collect {|i| i.attributes.to_h }; end
29
+ def find(hash_value)
30
+ it = @_table.items[hash_value]
31
+ @attributes.clear
32
+ it.attributes.to_h.each {|k, v| self.send("#{k}=".to_sym, v) unless k == @hash_key }
33
+ @hash_value = hash_value; @is_new = false
34
+ @attributes
35
+ end
36
+
37
+ def save(hash_value = nil)
38
+ raise "missing hash value" if hash_value.nil? and is_new?
39
+ @_item = item = @_table.items.create(@hash_key.to_sym => hash_value) if is_new?
40
+ if @_item
41
+ @_item.attributes.set(@attributes)
42
+ @is_new = false; @hash_value = hash_value
43
+ @_item.attributes.to_h
44
+ end
45
+ end
46
+
47
+ def destroy
48
+ unless is_new?
49
+ @_item.delete
50
+ @hash_value = nil; @is_new = true
51
+ end
52
+ end
53
+
54
+ def method_missing(method, *args, &block)
55
+ if RESERVED.include?(method.to_s)
56
+ self.send(method.to_sym, *args, &block)
57
+ else
58
+ if method.to_s.include?("=")
59
+ @attributes[method.to_s.gsub("=","")] = args.first
60
+ else
61
+ @attributes[method.to_s]
62
+ end
63
+ end
64
+ end
65
+ end
data/rdy.sample.yml ADDED
@@ -0,0 +1,2 @@
1
+ access_key_id: "YOUR KEY"
2
+ secret_access_key: "YOUR SECRET"
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'rdy'
16
+
17
+ class Test::Unit::TestCase
18
+ end
data/test/test_rdy.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRdy < Test::Unit::TestCase
4
+ should "test this thing" do
5
+ # TODO
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdy
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Oliver Kiessler
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-01-22 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: aws-sdk
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 31
29
+ segments:
30
+ - 1
31
+ - 3
32
+ - 2
33
+ version: 1.3.2
34
+ prerelease: false
35
+ type: :runtime
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: shoulda
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ prerelease: false
49
+ type: :development
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: bundler
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 23
59
+ segments:
60
+ - 1
61
+ - 0
62
+ - 0
63
+ version: 1.0.0
64
+ prerelease: false
65
+ type: :development
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: jeweler
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 7
75
+ segments:
76
+ - 1
77
+ - 6
78
+ - 4
79
+ version: 1.6.4
80
+ prerelease: false
81
+ type: :development
82
+ requirement: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ name: rcov
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ prerelease: false
95
+ type: :development
96
+ requirement: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ name: aws-sdk
99
+ version_requirements: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ prerelease: false
109
+ type: :runtime
110
+ requirement: *id006
111
+ description: Wrapper class for the DynamoDB AWS-SDK
112
+ email: kiessler@inceedo.com
113
+ executables: []
114
+
115
+ extensions: []
116
+
117
+ extra_rdoc_files:
118
+ - LICENSE.txt
119
+ - README.md
120
+ files:
121
+ - .document
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - VERSION
128
+ - lib/rdy.rb
129
+ - rdy.sample.yml
130
+ - test/helper.rb
131
+ - test/test_rdy.rb
132
+ has_rdoc: true
133
+ homepage: http://github.com/okiess/rdy
134
+ licenses:
135
+ - MIT
136
+ post_install_message:
137
+ rdoc_options: []
138
+
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ requirements: []
160
+
161
+ rubyforge_project:
162
+ rubygems_version: 1.5.3
163
+ signing_key:
164
+ specification_version: 3
165
+ summary: Simple ruby client for Amazon DynamoDB
166
+ test_files: []
167
+