store-active_record 0.0.2 → 0.0.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +49 -2
- data/lib/store/active_record/version.rb +1 -1
- data/lib/store/active_record.rb +11 -16
- data/spec/active_record_spec.rb +17 -21
- data/spec/helper.rb +33 -0
- metadata +2 -3
- data/.rvmrc +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ed03bc3ce06165f5a57e2b101a4615e3b50b37a
|
4
|
+
data.tar.gz: cafff8805390a11ea7001fd97d232a058aa8650c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1c02ecc0f6a32ec1ae002e5ec24863e21125de0a8d79dc2c60e5f15ae5f72de8f79b7ebe500ba9254ffd3167e53c399b2681a83c0112bd72701bc09b9bf267d
|
7
|
+
data.tar.gz: 0dc22af510ea697d1dec8c95672fd25fc6dcdb04787a2e86546701f92bd217ebd87e0e76c41f3a9710223097684949d4c83881de666b0823b389785b125a6ef5
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -22,17 +22,43 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
+
Each table needs at least a uid column.
|
26
|
+
|
27
|
+
With Rails
|
28
|
+
|
29
|
+
```
|
30
|
+
class CreateUsers < ActiveRecord::Migration
|
31
|
+
def change
|
32
|
+
create_table :users do |t|
|
33
|
+
t.string :uid
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
rake db:migrate
|
39
|
+
```
|
40
|
+
|
41
|
+
Without Rails
|
42
|
+
|
43
|
+
```
|
44
|
+
ActiveRecord::Migration.create_table('users') do |t|
|
45
|
+
t.string :uid
|
46
|
+
end
|
47
|
+
|
48
|
+
```
|
49
|
+
|
25
50
|
```
|
26
51
|
require 'store/active_record'
|
27
52
|
|
28
53
|
module DataMapper
|
29
54
|
module User
|
30
|
-
class ActiveRecord < Store::ActiveRecord
|
55
|
+
class ActiveRecord < Store::DataMapper::ActiveRecord
|
31
56
|
end
|
32
57
|
end
|
33
58
|
end
|
34
59
|
|
35
|
-
table = '
|
60
|
+
table = 'users'
|
61
|
+
|
36
62
|
spec = {
|
37
63
|
:adapter => sqlite3
|
38
64
|
:encoding => utf8
|
@@ -41,6 +67,27 @@ spec = {
|
|
41
67
|
:database => database_name
|
42
68
|
}
|
43
69
|
|
70
|
+
# or load it from your database.yml
|
71
|
+
# spec = YAML.load_file(path_to_your_database_yml)['production']
|
72
|
+
#
|
73
|
+
# database.yml
|
74
|
+
#
|
75
|
+
# development:
|
76
|
+
# adapter: sqlite3
|
77
|
+
# encoding: utf8
|
78
|
+
# collation: utf8_general_ci
|
79
|
+
# reconnect: false
|
80
|
+
# database: database_name
|
81
|
+
#
|
82
|
+
# test:
|
83
|
+
# adapter: sqlite3
|
84
|
+
# encoding: utf8
|
85
|
+
# collation: utf8_general_ci
|
86
|
+
# reconnect: false
|
87
|
+
# database: database_name_test
|
88
|
+
#
|
89
|
+
# production: development
|
90
|
+
|
44
91
|
DataMapper::User::ActiveRecord.new(table, spec)
|
45
92
|
```
|
46
93
|
|
data/lib/store/active_record.rb
CHANGED
@@ -6,11 +6,9 @@ class Store
|
|
6
6
|
class DataMapper
|
7
7
|
class ActiveRecord < Store::DataMapper
|
8
8
|
|
9
|
-
def initialize(table_name
|
9
|
+
def initialize(table_name)
|
10
10
|
@table_name = table_name
|
11
|
-
@spec = spec
|
12
11
|
build_class
|
13
|
-
establish_connection
|
14
12
|
end
|
15
13
|
|
16
14
|
def insert(data)
|
@@ -48,13 +46,12 @@ class Store
|
|
48
46
|
|
49
47
|
private
|
50
48
|
|
51
|
-
|
52
|
-
|
53
|
-
@cls.table_name = @table_name
|
54
|
-
@cls.send(:define_method, :uid) do
|
49
|
+
class StoredEntity < ::ActiveRecord::Base
|
50
|
+
def uid
|
55
51
|
id.to_s
|
56
52
|
end
|
57
|
-
|
53
|
+
|
54
|
+
def to_hash
|
58
55
|
attributes.tap do |a|
|
59
56
|
a.delete('id')
|
60
57
|
a['uid'] = uid
|
@@ -62,16 +59,14 @@ class Store
|
|
62
59
|
end
|
63
60
|
end
|
64
61
|
|
65
|
-
def
|
66
|
-
@
|
67
|
-
|
68
|
-
|
69
|
-
def establish_connection
|
70
|
-
base.establish_connection(@spec)
|
62
|
+
def build_class
|
63
|
+
StoredEntity.table_name = @table_name
|
64
|
+
StoredEntity.inheritance_column = 'sti_deactivated'
|
65
|
+
@cls = Class.new(StoredEntity)
|
71
66
|
end
|
72
67
|
|
73
|
-
def
|
74
|
-
|
68
|
+
def cls
|
69
|
+
@cls
|
75
70
|
end
|
76
71
|
|
77
72
|
def find_by_id(id)
|
data/spec/active_record_spec.rb
CHANGED
@@ -3,31 +3,27 @@ require 'yaml'
|
|
3
3
|
require 'store/spec'
|
4
4
|
require "active_record"
|
5
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
6
|
|
19
7
|
describe Store::DataMapper::ActiveRecord do
|
20
|
-
spec = YAML.load_file("#{File.dirname(__FILE__)}/../config/database.yml.sample")['test']
|
21
|
-
table = 'Bar'
|
22
8
|
|
23
|
-
|
9
|
+
describe 'with active connection' do
|
24
10
|
|
25
|
-
|
26
|
-
|
27
|
-
end
|
11
|
+
establish_connection
|
12
|
+
recreate_table
|
28
13
|
|
29
|
-
|
30
|
-
instance_eval &Store::Spec::Specs
|
14
|
+
before { empty_table }
|
31
15
|
|
32
|
-
|
16
|
+
subject { Store::DataMapper::ActiveRecord.new(table) }
|
17
|
+
|
18
|
+
it 'exists a active connection' do
|
19
|
+
assert ::ActiveRecord::Base.connected?
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'deactivates sti for the moment' do
|
23
|
+
assert_equal 'sti_deactivated', subject.send(:cls).inheritance_column
|
24
|
+
end
|
33
25
|
|
26
|
+
run_subject_against_store_spec_gem
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/spec/helper.rb
CHANGED
@@ -1,3 +1,36 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'minitest/spec'
|
3
3
|
require 'store/active_record'
|
4
|
+
|
5
|
+
def establish_connection
|
6
|
+
::ActiveRecord::Base.establish_connection(spec)
|
7
|
+
end
|
8
|
+
|
9
|
+
def recreate_table
|
10
|
+
begin
|
11
|
+
::ActiveRecord::Migration.drop_table(table)
|
12
|
+
rescue
|
13
|
+
ensure
|
14
|
+
::ActiveRecord::Migration.create_table(table) do |t|
|
15
|
+
t.string :foo
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def empty_table
|
21
|
+
::ActiveRecord::Base.connection.execute("DELETE FROM #{table};")
|
22
|
+
end
|
23
|
+
|
24
|
+
def run_subject_against_store_spec_gem
|
25
|
+
instance_eval &Store::Spec::Specs
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def spec
|
31
|
+
@spec ||= YAML.load_file("#{File.dirname(__FILE__)}/../config/database.yml.sample")['test']
|
32
|
+
end
|
33
|
+
|
34
|
+
def table
|
35
|
+
'Bar'
|
36
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: store-active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Owiesniak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -116,7 +116,6 @@ extensions: []
|
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
118
|
- .gitignore
|
119
|
-
- .rvmrc
|
120
119
|
- .travis.yml
|
121
120
|
- Gemfile
|
122
121
|
- LICENSE.txt
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use 2.0.0@store-active_record --create
|