active_pstore 0.5.0 → 0.5.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.
- checksums.yaml +4 -4
- data/README.ja.md +40 -0
- data/README.md +12 -3
- data/lib/active_pstore/application/configuration.rb +27 -0
- data/lib/active_pstore/finder_methods.rb +23 -3
- data/lib/active_pstore/query_methods.rb +2 -1
- data/lib/active_pstore/railtie.rb +5 -23
- data/lib/active_pstore/version.rb +1 -1
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e0846e7c7c7a6853ef77ea26f6ae2aa498d63b7
|
4
|
+
data.tar.gz: f12f60b9965364eca7eb3787d511a9f380fcfc75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36c9f10ad414bc43ca0949fac8fbafea9ac20eb6189eaa1a7d3f412fb67abbedd28cc1f1ffe21cb58a8316c9e2060afd351592183d8d6257422eebdc19c53908
|
7
|
+
data.tar.gz: faf2198901dffda085992ca707df9c00c4f78377b6941a6929ac6d36f1ca7a9c777f567043f0ef8a7057517a9c549ad9d76992d306564c6b1e41ada4dab522b1
|
data/README.ja.md
CHANGED
@@ -108,6 +108,46 @@ Artist.where(birth_date: Date.new(1948, 12, 3)..Date.new(1956, 12, 6))
|
|
108
108
|
|
109
109
|
続きは[テストコード](https://github.com/koic/active_pstore/tree/master/spec)をご参照ください。
|
110
110
|
|
111
|
+
## Integration with Rails
|
112
|
+
|
113
|
+
Active PStore では以下のジェネレータを用意しています。
|
114
|
+
|
115
|
+
### Generate config file
|
116
|
+
|
117
|
+
以下の行をRailsアプリケーションで実行してください。
|
118
|
+
|
119
|
+
```
|
120
|
+
bundle exec rails g active_pstore:config
|
121
|
+
```
|
122
|
+
|
123
|
+
config/active_pstore.yml が生成されます。
|
124
|
+
|
125
|
+
config/database.yml をもちいて Active PStore が pstore を使った保存先の情報を指定します。
|
126
|
+
|
127
|
+
```
|
128
|
+
development:
|
129
|
+
database: db/active_pstore_development.yml
|
130
|
+
```
|
131
|
+
|
132
|
+
### Generate model file
|
133
|
+
|
134
|
+
以下の行をRailsアプリケーションで実行してください。
|
135
|
+
|
136
|
+
```
|
137
|
+
bundle exec rails g active_pstore:model artist name associated_act instrument birth_date
|
138
|
+
```
|
139
|
+
|
140
|
+
app/models/artist.rb が生成されます。
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
class Artist < ActivePStore::Base
|
144
|
+
attr_accessor :name
|
145
|
+
attr_accessor :associated_act
|
146
|
+
attr_accessor :instrument
|
147
|
+
attr_accessor :birth_date
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
111
151
|
## REQUIREMENTS
|
112
152
|
|
113
153
|
* [Active Model](https://github.com/rails/rails/tree/master/activemodel)
|
data/README.md
CHANGED
@@ -109,19 +109,28 @@ see [spec codes](https://github.com/koic/active_pstore/tree/master/spec) for mor
|
|
109
109
|
|
110
110
|
## Integration with Rails
|
111
111
|
|
112
|
+
This library has following generators.
|
113
|
+
|
112
114
|
### Generate config file
|
113
115
|
|
114
|
-
Execute these lines
|
116
|
+
Execute these lines in your Rails application directory:
|
115
117
|
|
116
118
|
```
|
117
119
|
bundle exec rails g active_pstore:config
|
118
120
|
```
|
119
121
|
|
120
|
-
And then create config/active_pstore.yml
|
122
|
+
And then create config/active_pstore.yml
|
123
|
+
|
124
|
+
Using the config/database.yml file you can specify all the information needed to access your pstore database:
|
125
|
+
|
126
|
+
```
|
127
|
+
development:
|
128
|
+
database: db/active_pstore_development.yml
|
129
|
+
```
|
121
130
|
|
122
131
|
### Generate model file
|
123
132
|
|
124
|
-
Execute these lines
|
133
|
+
Execute these lines in your Rails application directory:
|
125
134
|
|
126
135
|
```
|
127
136
|
bundle exec rails g active_pstore:model artist name associated_act instrument birth_date
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ActivePStore
|
2
|
+
module Application
|
3
|
+
class Configuration
|
4
|
+
# Loads and returns the entire raw configuration of database from
|
5
|
+
# values stored in `config/active_pstore.yml`.
|
6
|
+
def database_configuration
|
7
|
+
yaml = Pathname.new('config/active_pstore.yml')
|
8
|
+
|
9
|
+
config = if yaml && yaml.exist?
|
10
|
+
require 'yaml'
|
11
|
+
require 'erb'
|
12
|
+
YAML.load(ERB.new(yaml.read).result) || {}
|
13
|
+
else
|
14
|
+
raise 'Could not load database configuration. No such file - config/active_pstore.yml'
|
15
|
+
end
|
16
|
+
|
17
|
+
config
|
18
|
+
rescue Psych::SyntaxError => e
|
19
|
+
raise "YAML syntax error occurred while parsing config/active_pstore.yml. " \
|
20
|
+
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
|
21
|
+
"Error: #{e.message}"
|
22
|
+
rescue => e
|
23
|
+
raise e, "Cannot load `Rails::ActivePStore::Railtie.database_configuration`:\n#{e.message}", e.backtrace
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,9 +1,15 @@
|
|
1
1
|
module ActivePStore
|
2
2
|
module FinderMethods
|
3
|
-
def find(
|
4
|
-
|
3
|
+
def find(*ids)
|
4
|
+
ids = ids.map {|id| id.is_a?(ActivePStore::Base) ? id.id : id }
|
5
5
|
|
6
|
-
|
6
|
+
_find(*ids).tap do |ret|
|
7
|
+
if ids.size == 1
|
8
|
+
raise ActivePStore::RecordNotFound, "Couldn't find #{self} with 'id'=#{ids.first}" if ret.nil?
|
9
|
+
else
|
10
|
+
raise ActivePStore::RecordNotFound, "Couldn't find all #{self} with 'id': (#{ids.join(', ')}) (found #{ret.size} results, but was looking for #{ids.size})" unless ret.size == ids.size
|
11
|
+
end
|
12
|
+
end
|
7
13
|
end
|
8
14
|
|
9
15
|
def find_by(conditions = {})
|
@@ -25,5 +31,19 @@ module ActivePStore
|
|
25
31
|
def take(limit = nil)
|
26
32
|
limit ? all.take(limit) : first
|
27
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def _find(*ids)
|
38
|
+
if ids.size == 1
|
39
|
+
id = ids.first
|
40
|
+
|
41
|
+
all.find {|obj| obj.id == id }
|
42
|
+
else
|
43
|
+
ids.each_with_object([]) {|id, ret|
|
44
|
+
ret << _find(id)
|
45
|
+
}.compact
|
46
|
+
end
|
47
|
+
end
|
28
48
|
end
|
29
49
|
end
|
@@ -11,33 +11,15 @@ module Rails
|
|
11
11
|
config.action_dispatch.rescue_responses.merge!(rescue_responses)
|
12
12
|
end
|
13
13
|
|
14
|
-
# Loads and returns the entire raw configuration of database from
|
15
|
-
# values stored in `config/active_pstore.yml`.
|
16
|
-
def database_configuration
|
17
|
-
yaml = Pathname.new('config/active_pstore.yml')
|
18
|
-
|
19
|
-
config = if yaml && yaml.exist?
|
20
|
-
require 'yaml'
|
21
|
-
require 'erb'
|
22
|
-
YAML.load(ERB.new(yaml.read).result) || {}
|
23
|
-
else
|
24
|
-
raise 'Could not load database configuration. No such file - config/active_pstore.yml'
|
25
|
-
end
|
26
|
-
|
27
|
-
config
|
28
|
-
rescue Psych::SyntaxError => e
|
29
|
-
raise "YAML syntax error occurred while parsing config/active_pstore.yml. " \
|
30
|
-
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
|
31
|
-
"Error: #{e.message}"
|
32
|
-
rescue => e
|
33
|
-
raise e, "Cannot load `Rails::ActivePStore::Railtie.database_configuration`:\n#{e.message}", e.backtrace
|
34
|
-
end
|
35
|
-
|
36
14
|
initializer 'active_pstore.initialize_database' do
|
37
15
|
config_file = Rails.root.join('config', 'active_pstore.yml')
|
38
16
|
|
39
17
|
if config_file.file?
|
40
|
-
|
18
|
+
require 'active_pstore/application/configuration'
|
19
|
+
|
20
|
+
configuration = ::ActivePStore::Application::Configuration.new
|
21
|
+
|
22
|
+
database = configuration.database_configuration.fetch(ENV['RAILS_ENV'] || 'development').fetch('database')
|
41
23
|
|
42
24
|
::ActivePStore::Base.establish_connection(database: database)
|
43
25
|
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.5.
|
4
|
+
version: 0.5.1
|
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-
|
11
|
+
date: 2015-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: generator_spec
|
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: railties
|
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'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rspec
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,6 +90,7 @@ files:
|
|
62
90
|
- README.ja.md
|
63
91
|
- README.md
|
64
92
|
- lib/active_pstore.rb
|
93
|
+
- lib/active_pstore/application/configuration.rb
|
65
94
|
- lib/active_pstore/attribute_methods.rb
|
66
95
|
- lib/active_pstore/base.rb
|
67
96
|
- lib/active_pstore/calculations.rb
|