orm_adapter_aws 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ spec/support/aws_init.rb
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in orm_adapter_aws.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jeremy Green
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # OrmAdapterAws
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'orm_adapter_aws'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install orm_adapter_aws
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,12 @@
1
+ require "orm_adapter_aws/version"
2
+ require "orm_adapter"
3
+ module OrmAdapterAws
4
+ # Your code goes here...
5
+ end
6
+
7
+ puts "!!!!!!!"
8
+ if defined?(AWS::Record::Model)
9
+ require 'orm_adapter_aws/adapters/simple_db'
10
+ else
11
+ puts "can't load our stuff!!!!!!"
12
+ end
@@ -0,0 +1,117 @@
1
+ module OrmAdapterAws
2
+ class SimpleDB < ::OrmAdapter::Base
3
+
4
+ # Return list of column/property names
5
+ def column_names
6
+ klass.attributes.keys
7
+ end
8
+
9
+ # @see OrmAdapter::Base#get!
10
+ def get!(id)
11
+ klass.find(wrap_key(id))
12
+ end
13
+
14
+ # @see OrmAdapter::Base#get
15
+ def get(id)
16
+ klass.find(wrap_key(id))
17
+ rescue AWS::Record::RecordNotFound => rnf
18
+ nil
19
+ end
20
+
21
+ # @see OrmAdapter::Base#find_first
22
+ def find_first(options = {})
23
+ conditions, order = extract_conditions!(options)
24
+ id = nil
25
+ if conditions.keys.include? :id
26
+ id = conditions.delete(:id)
27
+ obj = get(id)
28
+ compare_obj_to_conditions(obj,conditions)
29
+ else
30
+ scope = klass.where(conditions_to_fields(conditions))
31
+ scope = scope.order(*order_munge(order)) if !order.nil? && order.size > 0
32
+ obj = scope.first
33
+ end
34
+ end
35
+
36
+ # @see OrmAdapter::Base#find_all
37
+ def find_all(options = {})
38
+ conditions, order, limit, offset = extract_conditions!(options)
39
+ scope = klass.where(conditions_to_fields(conditions))
40
+ scope = scope.order(*order_munge(order)) if !order.nil? && order.size > 0
41
+ scope = scope.limit(limit) if !limit.nil?
42
+ #.offset(offset).all
43
+ scope.all.to_a
44
+ end
45
+
46
+ # @see OrmAdapter::Base#create!
47
+ def create!(attributes = {})
48
+ unless attributes.is_a?(Hash) || valid_object?(attributes)
49
+ raise "#{attributes.class} is not a valid #{klass}."
50
+ end
51
+ obj = klass.new(attributes)
52
+ obj.save
53
+ obj
54
+ end
55
+
56
+ # @see OrmAdapter::Base#destroy
57
+ def destroy(object)
58
+ object.destroy && true if valid_object?(object)
59
+ end
60
+
61
+ protected
62
+ def compare_obj_to_conditions(obj,conditions)
63
+ return obj if obj.nil?
64
+ atts = obj.attributes
65
+ conditions.each_pair do |k,v|
66
+ return nil unless atts[k] == v
67
+ end
68
+ obj
69
+ end
70
+
71
+ # Introspects the klass to convert and objects in conditions into foreign key and type fields
72
+ def conditions_to_fields(conditions)
73
+ conditions.inject({}) do |fields, (key, value)|
74
+ fields.merge(key => value)
75
+ end
76
+ end
77
+
78
+ def order_munge(order)
79
+ mung = nil
80
+ if order.is_a?(Array) && order[0].is_a?(Array)
81
+ mung = order[0][0], order[0][1]
82
+ elsif order.is_a? Array
83
+ mung = order[0],order[1]
84
+ else
85
+ mung = order
86
+ end
87
+ mung
88
+ #clause = order.map {|pair| "#{pair[0]} #{pair[1]}"}.join(",")
89
+ #puts "clause = #{clause} -------------"
90
+ #clause
91
+ end
92
+
93
+ end
94
+ end
95
+
96
+ AWS::Record::Model::OrmAdapter = OrmAdapterAws::SimpleDB
97
+ module AWS
98
+ module Record
99
+ class Model
100
+ extend ::OrmAdapter::ToAdapter
101
+
102
+ #def create!(attributes = nil, options = {}, &block)
103
+ #if attributes.is_a?(Array)
104
+ #attributes.collect { |attr| create!(attr, options, &block) }
105
+ #else
106
+ #object = new(attributes, options)
107
+ #yield(object) if block_given?
108
+ #object.save!
109
+ #object
110
+ #end
111
+ #end
112
+
113
+ end
114
+ end
115
+ end
116
+
117
+
@@ -0,0 +1,3 @@
1
+ module OrmAdapterAws
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'orm_adapter_aws/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "orm_adapter_aws"
8
+ gem.version = OrmAdapterAws::VERSION
9
+ gem.authors = ["Jeremy Green"]
10
+ gem.email = ["jeremy@octolabs.com"]
11
+ gem.description = %q{A SimpleDB adapter for the orm_adapter gem.}
12
+ gem.summary = %q{A SimpleDB adapter for the orm_adapter gem.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "aws-sdk", "~> 1.8.0"
21
+ gem.add_dependency "orm_adapter", "~> 0.4.0"
22
+ gem.add_development_dependency "rspec", ">= 2.0.0"
23
+
24
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+ require 'orm_adapter/../../spec/orm_adapter/example_app_shared'
3
+ # !!!!!!!!!!!!!!!!!!!!!
4
+ # Not all features in the orm_adapter/example_app_shared spec are supported by SimpleDB.
5
+ # Tests that are known to fail are
6
+ # example_app_shared.rb:100 # no associations
7
+ # example_app_shared.rb:115 # can only sort by one column
8
+ # example_app_shared.rb:151 # no associations
9
+ # example_app_shared.rb:160 # can only sort by one column
10
+ # example_app_shared.rb:188 # no offset for collections
11
+ # example_app_shared.rb:209 # no associations
12
+ # example_app_shared.rb:215 # no associations
13
+
14
+
15
+ if !defined?(AWS::Record::Model) #|| !(Mongo::Connection.new.db('orm_adapter_spec') rescue nil)
16
+ puts "** require 'aws-sdk' to run the specs in #{__FILE__}"
17
+ else
18
+
19
+ #Mongoid.configure do |config|
20
+ #config.master = Mongo::Connection.new.db('orm_adapter_spec')
21
+ #end
22
+ class TestBase < AWS::Record::Model
23
+ ## We have to override == so that we can do comparisons correctly
24
+ def ==(other)
25
+ self.attributes == other.attributes
26
+ end
27
+
28
+ def save
29
+ super
30
+ sleep(2) # allow a couple of seconds for SimpleDB to propogate
31
+ end
32
+
33
+ def destroy
34
+ super
35
+ sleep(2) # allow a couple of secons for SimpleDB to propogate
36
+ end
37
+ end
38
+
39
+ class User < TestBase
40
+ string_attr :name
41
+ integer_attr :rating
42
+ #has_many_related :notes, :foreign_key => :owner_id, :class_name => 'MongoidOrmSpec::Note'
43
+ end
44
+
45
+ class Note < TestBase
46
+ string_attr :body #, :default => "made by orm"
47
+ string_attr :owner_id
48
+ #belongs_to_related :owner, :class_name => 'MongoidOrmSpec::User'
49
+
50
+ def owner=(owner)
51
+ owner_id = owner.id
52
+ save
53
+ end
54
+
55
+ end
56
+
57
+ # here be the specs!
58
+ describe AWS::Record::Model::OrmAdapter do
59
+ before do
60
+ User.create_domain
61
+ Note.create_domain
62
+ User.each{|u| u.destroy }
63
+ Note.each{|n| n.destroy }
64
+ sleep(2)
65
+ end
66
+
67
+ it_should_behave_like "example app with orm_adapter" do
68
+ let(:user_class) { User }
69
+ let(:note_class) { Note }
70
+ def create_model(klass, attrs = {})
71
+ if klass == User
72
+ attrs = {:name => "Test User"}.merge(attrs)
73
+ elsif klass == Note
74
+ attrs = {:body => "made by orm"}.merge(attrs)
75
+ end
76
+ model = klass.new(attrs)
77
+ model.save
78
+ model
79
+ end
80
+
81
+ def reload_model(model)
82
+ model.class.find(model.id)
83
+ end
84
+ end
85
+ end
86
+
87
+ end
@@ -0,0 +1,22 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'aws-sdk'
9
+ require "#{File.dirname(__FILE__)}/../lib/orm_adapter_aws"
10
+ require 'support/aws_init'
11
+
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ #config.order = 'random'
22
+ end
@@ -0,0 +1,4 @@
1
+ AWS_SECRET_KEY_ID='abc'
2
+ AWS_SECRET_KEY ='123'
3
+ AWS.config({:access_key_id => AWS_SECRET_KEY_ID, :secret_access_key => AWS_SECRET_KEY})
4
+ AWS::Record.domain_prefix = "orm_adapter_aws_test-"
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: orm_adapter_aws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy Green
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aws-sdk
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.8.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.8.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: orm_adapter
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.4.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.4.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 2.0.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.0
62
+ description: A SimpleDB adapter for the orm_adapter gem.
63
+ email:
64
+ - jeremy@octolabs.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - lib/orm_adapter_aws.rb
76
+ - lib/orm_adapter_aws/adapters/simple_db.rb
77
+ - lib/orm_adapter_aws/version.rb
78
+ - orm_adapter_aws.gemspec
79
+ - spec/orm_adapter_aws/adapters/simple_db_spec.rb
80
+ - spec/spec_helper.rb
81
+ - spec/support/aws_init.rb.example
82
+ homepage: ''
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.24
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: A SimpleDB adapter for the orm_adapter gem.
106
+ test_files:
107
+ - spec/orm_adapter_aws/adapters/simple_db_spec.rb
108
+ - spec/spec_helper.rb
109
+ - spec/support/aws_init.rb.example