store-active_record 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -21
- data/config/database.yml.sample +2 -8
- data/lib/store/active_record/version.rb +1 -1
- data/lib/store/active_record.rb +4 -3
- data/spec/helper.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7abe63975f357775d815d41143e4f528a280769
|
4
|
+
data.tar.gz: b00ea1ffb17681a143da988ce78e12b00faa2f78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79a510dc34f35d82d56eb613e0dc42efd9271dc1d0e7e749f16b79b351224d0decbae888298ae4dca7fe7c8d3ce5c5f775c29548078fab4d923512ed833280f5
|
7
|
+
data.tar.gz: bb5b035a0ff2f45efe7f0fc209ecc78023708f961d0482e922c2ddec1fc0a19b358815fbcc840b248be8ded94c17d4e023378aac85a676f8531e3c10249a7741
|
data/README.md
CHANGED
@@ -47,29 +47,13 @@ end
|
|
47
47
|
|
48
48
|
```
|
49
49
|
|
50
|
-
|
51
|
-
require 'store/active_record'
|
50
|
+
Establish connection to the database
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
class ActiveRecord < Store::DataMapper::ActiveRecord
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
table = 'users'
|
52
|
+
```
|
53
|
+
require 'activerecord'
|
61
54
|
|
62
|
-
spec =
|
63
|
-
:adapter => sqlite3
|
64
|
-
:encoding => utf8
|
65
|
-
:collation => utf8_general_ci
|
66
|
-
:reconnect => false
|
67
|
-
:database => database_name
|
68
|
-
}
|
55
|
+
spec = YAML.load_file(path_to_your_database_yml)['production']
|
69
56
|
|
70
|
-
# or load it from your database.yml
|
71
|
-
# spec = YAML.load_file(path_to_your_database_yml)['production']
|
72
|
-
#
|
73
57
|
# database.yml
|
74
58
|
#
|
75
59
|
# development:
|
@@ -88,7 +72,20 @@ spec = {
|
|
88
72
|
#
|
89
73
|
# production: development
|
90
74
|
|
91
|
-
|
75
|
+
ActiveRecord::Base.establish_connection(spec)
|
76
|
+
```
|
77
|
+
|
78
|
+
```
|
79
|
+
require 'store/active_record'
|
80
|
+
|
81
|
+
module DataMapper
|
82
|
+
module User
|
83
|
+
class ActiveRecord < Store::DataMapper::ActiveRecord
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
DataMapper::User::ActiveRecord.new('users')
|
92
89
|
```
|
93
90
|
|
94
91
|
## Tests
|
data/config/database.yml.sample
CHANGED
@@ -1,15 +1,9 @@
|
|
1
1
|
development:
|
2
2
|
adapter: sqlite3
|
3
|
-
|
4
|
-
collation: utf8_general_ci
|
5
|
-
reconnect: false
|
6
|
-
database: store_active_record
|
3
|
+
database: ":memory:"
|
7
4
|
|
8
5
|
test:
|
9
6
|
adapter: sqlite3
|
10
|
-
|
11
|
-
collation: utf8_general_ci
|
12
|
-
reconnect: false
|
13
|
-
database: store_active_record_test
|
7
|
+
database: ":memory:"
|
14
8
|
|
15
9
|
production: development
|
data/lib/store/active_record.rb
CHANGED
@@ -13,7 +13,9 @@ class Store
|
|
13
13
|
|
14
14
|
def insert(data)
|
15
15
|
entity = cls.create(data)
|
16
|
-
entity.id.to_s
|
16
|
+
id = entity.id.to_s
|
17
|
+
entity.update_attributes(data.merge('uid' => id))
|
18
|
+
id
|
17
19
|
end
|
18
20
|
|
19
21
|
def update(id, data)
|
@@ -53,8 +55,7 @@ class Store
|
|
53
55
|
|
54
56
|
def to_hash
|
55
57
|
attributes.tap do |a|
|
56
|
-
a.delete('id')
|
57
|
-
a['uid'] = uid
|
58
|
+
a.delete('id') # ActiveRecord detail
|
58
59
|
end
|
59
60
|
end
|
60
61
|
end
|
data/spec/helper.rb
CHANGED
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.4
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|