store-active_record 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rvmrc +1 -0
- data/.travis.yaml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +53 -0
- data/Rakefile +12 -0
- data/config/database.yml.sample +15 -0
- data/lib/store/active_record/version.rb +5 -0
- data/lib/store/active_record.rb +79 -0
- data/spec/active_record_spec.rb +33 -0
- data/spec/helper.rb +3 -0
- data/store-active_record.gemspec +29 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0130c9a748dcea63ea6c1bb1acc5f2a97b03a911
|
4
|
+
data.tar.gz: df19da24294e0eda97550232c71359abb660cc2b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 477e0c05c59fffe892be280a7cf679cc083b99c671a133b2bcf6919fbb40d2709fb0a66bdb3e127cab100356268f8cf0d89e6b5c851861befafa35ac0768cc3d
|
7
|
+
data.tar.gz: 610525c58ff8df0ceb8e99b64572775c5ca05ca6e8ebbef178773a3967b014f91ead97e6b2f24519e09cd819dd139b655cb6b119bf1fd5b7d3a5c9a949377eec
|
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
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
|
+
*.swp
|
19
|
+
*.swo
|
20
|
+
config/database.yml
|
21
|
+
store_active_record_test
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 2.0.0@store-active_record --create
|
data/.travis.yaml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jan Owiesniak
|
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,53 @@
|
|
1
|
+
# Store::ActiveRecord
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/store-active_record.png)](http://badge.fury.io/rb/store-active_record) [![Build Status](https://travis-ci.org/janowiesniak/store-active_record.png?branch=master)](https://travis-ci.org/janowiesniak/store-active_record) [![Code Climate](https://codeclimate.com/github/janowiesniak/store-active_record.png)](https://codeclimate.com/github/janowiesniak/store-active_record)
|
4
|
+
|
5
|
+
ActiveRecord DataMapper for [Store](https://github.com/holderbaum/store).
|
6
|
+
|
7
|
+
It implements basic features such as insert, update, delete, single_find, bulk_find and count.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'store-active_record'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install store-active_record
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```
|
26
|
+
require 'store/active_record'
|
27
|
+
|
28
|
+
module DataMapper
|
29
|
+
module User
|
30
|
+
class ActiveRecord < Store::ActiveRecord
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
table = 'User'
|
36
|
+
spec = {
|
37
|
+
:adapter => sqlite3
|
38
|
+
:encoding => utf8
|
39
|
+
:collation => utf8_general_ci
|
40
|
+
:reconnect => false
|
41
|
+
:database => database_name
|
42
|
+
}
|
43
|
+
|
44
|
+
DataMapper::User::ActiveRecord.new(table, spec)
|
45
|
+
```
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
development:
|
2
|
+
adapter: sqlite
|
3
|
+
encoding: utf8
|
4
|
+
collation: utf8_general_ci
|
5
|
+
reconnect: false
|
6
|
+
database: store_active_record
|
7
|
+
|
8
|
+
test:
|
9
|
+
adapter: sqlite
|
10
|
+
encoding: utf8
|
11
|
+
collation: utf8_general_ci
|
12
|
+
reconnect: false
|
13
|
+
database: store_active_record_test
|
14
|
+
|
15
|
+
production: development
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require "store/active_record/version"
|
2
|
+
require "store"
|
3
|
+
require "active_record"
|
4
|
+
|
5
|
+
class Store
|
6
|
+
class DataMapper
|
7
|
+
class ActiveRecord < Store::DataMapper
|
8
|
+
|
9
|
+
def initialize(table_name, spec)
|
10
|
+
@table_name = table_name
|
11
|
+
@spec = spec
|
12
|
+
build_class
|
13
|
+
establish_connection
|
14
|
+
end
|
15
|
+
|
16
|
+
def insert(data)
|
17
|
+
entity = @cls.create(data)
|
18
|
+
entity.id.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def update(id, data)
|
22
|
+
find_by_id(id).update_attributes(data)
|
23
|
+
id
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete(id)
|
27
|
+
find_by_id(id).delete
|
28
|
+
id
|
29
|
+
end
|
30
|
+
|
31
|
+
def single_find(id)
|
32
|
+
find_by_id(id).to_hash
|
33
|
+
rescue ::ActiveRecord::RecordNotFound
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def bulk_find(ids)
|
38
|
+
entities = @cls.where(:id => ids).to_a
|
39
|
+
ordered_entities = ids.map do |id|
|
40
|
+
entities.detect {|entity| entity.id == id.to_i }
|
41
|
+
end
|
42
|
+
ordered_entities.map(&:to_hash)
|
43
|
+
end
|
44
|
+
|
45
|
+
def count
|
46
|
+
@cls.count
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def build_class
|
52
|
+
@cls = Class.new(base)
|
53
|
+
@cls.table_name = @table_name
|
54
|
+
@cls.send(:define_method, :uid) do
|
55
|
+
id.to_s
|
56
|
+
end
|
57
|
+
@cls.send(:define_method, :to_hash) do
|
58
|
+
attributes.tap do |a|
|
59
|
+
a.delete('id')
|
60
|
+
a['uid'] = uid
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def establish_connection
|
66
|
+
base.establish_connection(@spec)
|
67
|
+
end
|
68
|
+
|
69
|
+
def base
|
70
|
+
::ActiveRecord::Base
|
71
|
+
end
|
72
|
+
|
73
|
+
def find_by_id(id)
|
74
|
+
@cls.find_by_id(id)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'yaml'
|
3
|
+
require 'store/spec'
|
4
|
+
require "active_record"
|
5
|
+
|
6
|
+
def create_test_table(table, spec)
|
7
|
+
::ActiveRecord::Base.establish_connection(spec)
|
8
|
+
begin
|
9
|
+
::ActiveRecord::Migration.drop_table(table)
|
10
|
+
rescue
|
11
|
+
ensure
|
12
|
+
::ActiveRecord::Migration.create_table(table) do |t|
|
13
|
+
t.string :foo
|
14
|
+
end
|
15
|
+
end
|
16
|
+
::ActiveRecord::Base.connection.close
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Store::DataMapper::ActiveRecord do
|
20
|
+
spec = YAML.load_file("#{File.dirname(__FILE__)}/../config/database.yml")['test']
|
21
|
+
table = 'Bar'
|
22
|
+
|
23
|
+
create_test_table(table, spec)
|
24
|
+
|
25
|
+
before do
|
26
|
+
ActiveRecord::Base.connection.execute("DELETE FROM #{table};")
|
27
|
+
end
|
28
|
+
|
29
|
+
subject { Store::DataMapper::ActiveRecord.new(table, spec) }
|
30
|
+
instance_eval &Store::Spec::Specs
|
31
|
+
|
32
|
+
end
|
33
|
+
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'store/active_record/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "store-active_record"
|
8
|
+
spec.version = Store::ActiveRecord::VERSION
|
9
|
+
spec.authors = ["Jan Owiesniak"]
|
10
|
+
spec.email = ["jowiesniak@gmail.com"]
|
11
|
+
spec.description = %q{Basic ActiveRecord DataMapper for Store.}
|
12
|
+
spec.summary = %q{Basic ActiveRecord DataMapper for Store.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "minitest"
|
24
|
+
spec.add_development_dependency "store-spec"
|
25
|
+
spec.add_development_dependency "sqlite3"
|
26
|
+
|
27
|
+
spec.add_dependency "store"
|
28
|
+
spec.add_dependency "activerecord"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: store-active_record
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Owiesniak
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: store-spec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: store
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activerecord
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Basic ActiveRecord DataMapper for Store.
|
112
|
+
email:
|
113
|
+
- jowiesniak@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .rvmrc
|
120
|
+
- .travis.yaml
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- config/database.yml.sample
|
126
|
+
- lib/store/active_record.rb
|
127
|
+
- lib/store/active_record/version.rb
|
128
|
+
- spec/active_record_spec.rb
|
129
|
+
- spec/helper.rb
|
130
|
+
- store-active_record.gemspec
|
131
|
+
homepage: ''
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.0.3
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Basic ActiveRecord DataMapper for Store.
|
155
|
+
test_files:
|
156
|
+
- spec/active_record_spec.rb
|
157
|
+
- spec/helper.rb
|