active_pstore 0.4.7 → 0.4.8
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/README.ja.md +42 -10
- data/README.md +42 -10
- data/lib/active_pstore/base.rb +16 -0
- data/lib/active_pstore/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d3f881a40805e586bbfff7fffb3c53e03096706
|
4
|
+
data.tar.gz: f5f3e9b34f0c810444f4acea18fa0d9e6f79bb66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7995748c2bba385ba293e2410b96a36db1ed4338b684e5f4fc3150f0c954fe210a974e133aab4fddd4f179b8d6cb4c28b76c69ed19a5b1f228b1136200fdcf11
|
7
|
+
data.tar.gz: 9958eb9579064313f2e81f55aa51012cad999bc12353255de8087a571d5c927aff1ab2868d16d087247a9860052c620d7fe0a028c39e1fb3e44101685d234e6c
|
data/README.ja.md
CHANGED
@@ -13,24 +13,38 @@
|
|
13
13
|
|
14
14
|
## SYNOPSIS
|
15
15
|
|
16
|
-
###
|
16
|
+
### データの保存先のファイルパス指定
|
17
17
|
|
18
18
|
```ruby
|
19
19
|
require 'active_pstore'
|
20
20
|
|
21
|
+
ActivePStore::Base.establish_connection(database: '/path/to/file')
|
22
|
+
```
|
23
|
+
|
24
|
+
### クラス定義
|
25
|
+
|
26
|
+
```ruby
|
21
27
|
class Artist < ActivePStore::Base
|
22
28
|
attr_accessor :name
|
23
29
|
end
|
30
|
+
```
|
31
|
+
|
32
|
+
### インスタンスの生成
|
24
33
|
|
34
|
+
```ruby
|
25
35
|
randy_rhoads = Artist.new(name: 'Randy Rhoads')
|
26
36
|
```
|
27
37
|
|
28
|
-
|
38
|
+
や
|
29
39
|
|
30
40
|
```ruby
|
31
|
-
Artist.
|
41
|
+
randy_rhoads = Artist.new {|a|
|
42
|
+
a.name = 'Randy Rhoads'
|
43
|
+
)
|
32
44
|
```
|
33
45
|
|
46
|
+
`ActivePStore::Base.new` メソッドと別名として `ActivePStore::Base.build` を使うこともできます。
|
47
|
+
|
34
48
|
### インスタンスの保存
|
35
49
|
|
36
50
|
```ruby
|
@@ -50,12 +64,30 @@ database = PStore.new('/path/to/file')
|
|
50
64
|
database.transaction {|db| artist = db['Artist'] } # fetch instances of Artist class.
|
51
65
|
```
|
52
66
|
|
67
|
+
### ID
|
68
|
+
|
53
69
|
保存時に[SecureRandom.hex](http://docs.ruby-lang.org/ja/2.2.0/class/SecureRandom.html#S_HEX)の値を使ったActivePStore::Base#idが付与されます。
|
54
70
|
|
55
71
|
```ruby
|
56
|
-
|
57
|
-
|
58
|
-
|
72
|
+
randy_rhoads = Artist.new(name: 'Randy Rhoads')
|
73
|
+
randy_rhoads.id # => nil
|
74
|
+
|
75
|
+
randy_rhoads.save
|
76
|
+
randy_rhoads.id # => "0b84ece5d5be3bce3ee2101c1c4f6fda"
|
77
|
+
```
|
78
|
+
|
79
|
+
### インスタンスの生成時に保存
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
randy_rhoads = Artist.create(name: 'Randy Rhoads')
|
83
|
+
```
|
84
|
+
|
85
|
+
や
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
randy_rhoads = Artist.create {|a|
|
89
|
+
a.name = 'Randy Rhoads'
|
90
|
+
}
|
59
91
|
```
|
60
92
|
|
61
93
|
### 検索系
|
@@ -110,10 +142,6 @@ require 'active_pstore'
|
|
110
142
|
|
111
143
|
* 誕生秘話 ... http://www.slideshare.net/koic/software-development-and-rubygems
|
112
144
|
|
113
|
-
## LICENCE
|
114
|
-
|
115
|
-
The MIT Licence
|
116
|
-
|
117
145
|
## Contributing
|
118
146
|
|
119
147
|
1. Fork it
|
@@ -121,3 +149,7 @@ The MIT Licence
|
|
121
149
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
122
150
|
4. Push to the branch (`git push origin my-new-feature`)
|
123
151
|
5. Create new Pull Request
|
152
|
+
|
153
|
+
## License
|
154
|
+
|
155
|
+
Active PStore is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/README.md
CHANGED
@@ -12,24 +12,38 @@ This library has [Active Record](https://github.com/rails/rails/tree/master/acti
|
|
12
12
|
|
13
13
|
## SYNOPSIS
|
14
14
|
|
15
|
-
###
|
15
|
+
### specify data store path
|
16
16
|
|
17
17
|
```ruby
|
18
18
|
require 'active_pstore'
|
19
19
|
|
20
|
+
ActivePStore::Base.establish_connection(database: '/path/to/file')
|
21
|
+
```
|
22
|
+
|
23
|
+
### class definition
|
24
|
+
|
25
|
+
```ruby
|
20
26
|
class Artist < ActivePStore::Base
|
21
27
|
attr_accessor :name
|
22
28
|
end
|
29
|
+
```
|
30
|
+
|
31
|
+
### instantiate
|
23
32
|
|
33
|
+
```ruby
|
24
34
|
randy_rhoads = Artist.new(name: 'Randy Rhoads')
|
25
35
|
```
|
26
36
|
|
27
|
-
|
37
|
+
or
|
28
38
|
|
29
39
|
```ruby
|
30
|
-
Artist.
|
40
|
+
randy_rhoads = Artist.new {|a|
|
41
|
+
a.name = 'Randy Rhoads'
|
42
|
+
)
|
31
43
|
```
|
32
44
|
|
45
|
+
`ActivePStore::Base.build` method the same as `ActivePStore::Base.new` method.
|
46
|
+
|
33
47
|
### save
|
34
48
|
|
35
49
|
```ruby
|
@@ -49,12 +63,30 @@ database = PStore.new('/path/to/file')
|
|
49
63
|
database.transaction {|db| artist = db['Artist'] } # fetch instances of Artist class.
|
50
64
|
```
|
51
65
|
|
66
|
+
### identifier
|
67
|
+
|
52
68
|
allocate value of ActivePStore::Base#id using [SecureRandom.hex](http://ruby-doc.org/stdlib-2.2.0/libdoc/securerandom//rdoc/SecureRandom.html#method-c-hex).
|
53
69
|
|
54
70
|
```ruby
|
55
|
-
|
56
|
-
|
57
|
-
|
71
|
+
randy_rhoads = Artist.new(name: 'Randy Rhoads')
|
72
|
+
randy_rhoads.id # => nil
|
73
|
+
|
74
|
+
randy_rhoads.save
|
75
|
+
randy_rhoads.id # => "0b84ece5d5be3bce3ee2101c1c4f6fda"
|
76
|
+
```
|
77
|
+
|
78
|
+
### instantiate with save
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
randy_rhoads = Artist.create(name: 'Randy Rhoads')
|
82
|
+
```
|
83
|
+
|
84
|
+
or
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
randy_rhoads = Artist.create {|a|
|
88
|
+
a.name = 'Randy Rhoads'
|
89
|
+
}
|
58
90
|
```
|
59
91
|
|
60
92
|
### find series
|
@@ -109,10 +141,6 @@ require 'active_pstore'
|
|
109
141
|
|
110
142
|
* The making of a story (Japanese text) ... http://www.slideshare.net/koic/software-development-and-rubygems
|
111
143
|
|
112
|
-
## LICENCE
|
113
|
-
|
114
|
-
The MIT Licence
|
115
|
-
|
116
144
|
## Contributing
|
117
145
|
|
118
146
|
1. Fork it
|
@@ -120,3 +148,7 @@ The MIT Licence
|
|
120
148
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
121
149
|
4. Push to the branch (`git push origin my-new-feature`)
|
122
150
|
5. Create new Pull Request
|
151
|
+
|
152
|
+
## License
|
153
|
+
|
154
|
+
Active PStore is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/lib/active_pstore/base.rb
CHANGED
@@ -19,6 +19,8 @@ module ActivePStore
|
|
19
19
|
raise "Unknown method, '#{attr}='"
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
yield self if block_given?
|
22
24
|
end
|
23
25
|
|
24
26
|
class << self
|
@@ -29,6 +31,20 @@ module ActivePStore
|
|
29
31
|
ActivePStore::Collection.new(connection[self.pstore_key] || [])
|
30
32
|
}
|
31
33
|
end
|
34
|
+
|
35
|
+
def create(attributes = {}, &block)
|
36
|
+
if attributes.is_a?(Array)
|
37
|
+
attributes.map {|a| create(a, &block) }
|
38
|
+
else
|
39
|
+
build(attributes, &block).tap do |obj|
|
40
|
+
obj.save
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def first_or_create(attributes = {}, &block)
|
46
|
+
first || create(attributes, &block)
|
47
|
+
end
|
32
48
|
end
|
33
49
|
end
|
34
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_pstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koichi ITO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codeclimate-test-reporter
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
85
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
86
|
+
rubygems_version: 2.5.0
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: This library has Active Record like interface. Use pstore to store data.
|