app-configs 0.1.0 → 0.1.5
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/.rubocop.yml +73 -0
- data/README.adoc +3 -3
- data/README.ja.adoc +3 -3
- data/Rakefile +8 -8
- data/app-configs.gemspec +3 -3
- data/lib/app/config.rb +15 -2
- data/lib/app/config/base.rb +3 -17
- data/lib/app/config/deeply.rb +150 -99
- data/lib/app/config/json.rb +9 -5
- data/lib/app/config/ruby.rb +14 -6
- data/lib/app/config/version.rb +1 -1
- data/lib/app/config/yaml.rb +14 -6
- data/sample/sample_1.rb +15 -15
- metadata +16 -16
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1604af5697161e0aee809f766c8925509481a4f54ed767986739dcdaea6dc906
|
4
|
+
data.tar.gz: 66ae81383a077848a80c9ea8241611408dbda5cb5eb2eaf43e30f1df44dbcc8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c9e4056085ab2ed012e8e92c202a3a601083148b6deb19f6ae940103024b606edb109087f0d6064b19ad5eeec26013d936ceee14b282cdfab4e1dc390a73bf2
|
7
|
+
data.tar.gz: 4f61dd7411ad7f0dba986cd05fdb2c3aad58cf5deeef38f019e94a8e80558e9f6a4d8dcef4af03770cd9409c59c6ea9182b9fef02011862446e5ee7edd0ce269
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
|
2
|
+
AllCops:
|
3
|
+
Exclude:
|
4
|
+
- '.*'
|
5
|
+
- '*'
|
6
|
+
- '*.gemspec'
|
7
|
+
- 'Gemfile*'
|
8
|
+
- 'bin/**'
|
9
|
+
- 'exe/**'
|
10
|
+
- 'config/**/*'
|
11
|
+
- 'spec/**/*'
|
12
|
+
- 'tmp/**/*'
|
13
|
+
- 'vendor/**/*'
|
14
|
+
TargetRubyVersion: 2.7
|
15
|
+
|
16
|
+
Layout/ExtraSpacing:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Layout/SpaceAroundOperators:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Layout/SpaceBeforeFirstArg:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Layout/SpaceInsideParens:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Layout/SpaceInsideArrayLiteralBrackets:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Layout/SpaceInsideRangeLiteral:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Layout/SpaceInsideReferenceBrackets:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Layout/SpaceInsideStringInterpolation:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Lint/AmbiguousBlockAssociation:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Lint/EmptyWhen:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Lint/ReturnInVoidContext:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Lint/UselessAssignment:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Metrics/BlockLength:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Metrics/LineLength:
|
56
|
+
Enabled: false
|
57
|
+
Max: 120
|
58
|
+
|
59
|
+
Metrics/MethodLength:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Style/Documentation:
|
63
|
+
Enabled: true
|
64
|
+
|
65
|
+
Style/FrozenStringLiteralComment:
|
66
|
+
Enabled: false
|
67
|
+
|
68
|
+
Style/NumericPredicate:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
Style/StringLiterals:
|
72
|
+
Enabled: false
|
73
|
+
|
data/README.adoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= App::Config
|
2
2
|
|
3
|
-
Yet another library for load/save
|
3
|
+
Yet another library for load/save app config files.
|
4
4
|
|
5
5
|
== Features
|
6
6
|
|
@@ -29,11 +29,11 @@ Or install it yourself as:
|
|
29
29
|
|
30
30
|
== Usage
|
31
31
|
|
32
|
-
=== Example
|
32
|
+
=== Example
|
33
33
|
|
34
34
|
[source,ruby]
|
35
35
|
----
|
36
|
-
require "app
|
36
|
+
require "app/config"
|
37
37
|
|
38
38
|
# initial load. default search paths: "./config/defaults:./config:./var"
|
39
39
|
config = App::Config.new
|
data/README.ja.adoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= App::Config
|
2
2
|
|
3
|
-
|
3
|
+
またもやアプリ構成ファイル読み込み/書き出しライブラリ.
|
4
4
|
|
5
5
|
== 特徴
|
6
6
|
|
@@ -29,11 +29,11 @@ gem 'app-configs'
|
|
29
29
|
|
30
30
|
== 使い方
|
31
31
|
|
32
|
-
=== Example
|
32
|
+
=== Example
|
33
33
|
|
34
34
|
[source,ruby]
|
35
35
|
----
|
36
|
-
require "app
|
36
|
+
require "app/config"
|
37
37
|
|
38
38
|
# 初期読み込み. 初期探索パス: "./config/defaults:./config:./var"
|
39
39
|
config = App::Config.new
|
data/Rakefile
CHANGED
@@ -13,7 +13,7 @@ class Bundler::GemHelper
|
|
13
13
|
dest_path = File.join(dir, "#{name}-#{version}.zip")
|
14
14
|
cmnd = "git archive --format zip --prefix=#{name}/ HEAD > #{dest_path}"
|
15
15
|
|
16
|
-
|
16
|
+
_, code = sh_with_status( cmnd )
|
17
17
|
raise "Couldn't archive gem," unless code == 0
|
18
18
|
|
19
19
|
Bundler.ui.confirm "#{name} #{version} archived to #{dest_path}."
|
@@ -23,11 +23,11 @@ class Bundler::GemHelper
|
|
23
23
|
ver = version.to_s
|
24
24
|
|
25
25
|
cmnd = "git push origin #{ver} "
|
26
|
-
|
26
|
+
_, code = sh_with_status( cmnd )
|
27
27
|
raise "Couldn't git push origin." unless code == 0
|
28
28
|
|
29
29
|
cmnd = "git push "
|
30
|
-
|
30
|
+
_, code = sh_with_status( cmnd )
|
31
31
|
raise "Couldn't git push." unless code == 0
|
32
32
|
|
33
33
|
Bundler.ui.confirm "Git Push #{ver}."
|
@@ -43,15 +43,15 @@ class Bundler::GemHelper
|
|
43
43
|
end
|
44
44
|
|
45
45
|
cmnd = "git add #{version_pathname} "
|
46
|
-
|
46
|
+
_, code = sh_with_status( cmnd )
|
47
47
|
raise "Couldn't git add," unless code == 0
|
48
48
|
|
49
49
|
cmnd = "git commit -m '#{new_version}' "
|
50
|
-
|
50
|
+
_, code = sh_with_status( cmnd )
|
51
51
|
raise "Couldn't git commit." unless code == 0
|
52
52
|
|
53
53
|
cmnd = "git tag #{new_version} "
|
54
|
-
|
54
|
+
_, code = sh_with_status( cmnd )
|
55
55
|
raise "Couldn't git tag." unless code == 0
|
56
56
|
|
57
57
|
Bundler.ui.confirm "Update Tags to #{new_version}."
|
@@ -80,14 +80,14 @@ Bundler::GemHelper.new(Dir.pwd).instance_eval do
|
|
80
80
|
|
81
81
|
desc "Update Version Minor"
|
82
82
|
task 'minor' do
|
83
|
-
major, minor,
|
83
|
+
major, minor, _tiny = version.to_s.split('.')
|
84
84
|
new_version = [major, minor.to_i + 1, 0].join('.')
|
85
85
|
update_version( new_version )
|
86
86
|
end
|
87
87
|
|
88
88
|
desc "Update Version Major"
|
89
89
|
task 'major' do
|
90
|
-
major,
|
90
|
+
major, _minor, _tiny = version.to_s.split('.')
|
91
91
|
new_version = [major.to_i + 1, 0, 0].join('.')
|
92
92
|
update_version( new_version )
|
93
93
|
end
|
data/app-configs.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.email = ["arima.yasuhiro@gmail.com"]
|
8
8
|
|
9
9
|
spec.summary = %q{ Application config loader/saver. }
|
10
|
-
spec.description = %q{
|
10
|
+
spec.description = %q{ App::Config is yet another library for load/save app config files. }
|
11
11
|
spec.homepage = "https://github.com/arimay/app-configs"
|
12
12
|
spec.license = "MIT"
|
13
13
|
|
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "rake"
|
22
|
-
spec.add_development_dependency "rspec"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
23
|
end
|
data/lib/app/config.rb
CHANGED
@@ -1,13 +1,26 @@
|
|
1
1
|
require "app/config/version"
|
2
2
|
require "app/config/base"
|
3
|
-
require "app/config/deeply"
|
4
3
|
|
5
4
|
module App
|
6
5
|
module Config
|
7
6
|
class Error < StandardError; end
|
8
7
|
|
8
|
+
DEFAULT_PATH = "$ROOT/config/defaults:$ROOT/config:$ROOT/var"
|
9
|
+
|
9
10
|
class << self
|
10
|
-
|
11
|
+
def new( *args, **opts )
|
12
|
+
type = args.shift || :YAML
|
13
|
+
case type.to_sym
|
14
|
+
when :RUBY
|
15
|
+
App::Config::RUBY.new( **opts )
|
16
|
+
when :YAML
|
17
|
+
App::Config::YAML.new( **opts )
|
18
|
+
when :JSON
|
19
|
+
App::Config::JSON.new( **opts )
|
20
|
+
else
|
21
|
+
raise App::Config::Error, "unknown type: #{type}"
|
22
|
+
end
|
23
|
+
end
|
11
24
|
end
|
12
25
|
|
13
26
|
autoload :RUBY, "app/config/ruby"
|
data/lib/app/config/base.rb
CHANGED
@@ -2,26 +2,12 @@
|
|
2
2
|
module App
|
3
3
|
module Config
|
4
4
|
|
5
|
-
class Error < StandardError; end
|
6
|
-
|
7
|
-
DEFAULT_PATH = "$ROOT/config/defaults:$ROOT/config:$ROOT/var"
|
8
|
-
|
9
5
|
module Base
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
case type.to_sym
|
14
|
-
when :RUBY
|
15
|
-
App::Config::RUBY.new( **opts )
|
16
|
-
when :YAML
|
17
|
-
App::Config::YAML.new( **opts )
|
18
|
-
when :JSON
|
19
|
-
App::Config::JSON.new( **opts )
|
20
|
-
else
|
21
|
-
raise App::Config::Error, "unknown type: #{type}"
|
6
|
+
def initialize
|
7
|
+
self.default_proc = proc do |hash, key|
|
8
|
+
hash[key] = {}
|
22
9
|
end
|
23
10
|
end
|
24
|
-
|
25
11
|
end
|
26
12
|
|
27
13
|
end
|
data/lib/app/config/deeply.rb
CHANGED
@@ -1,145 +1,196 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
|
3
|
+
module Deeply
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
## deeply_symbolize_keys
|
6
|
+
|
7
|
+
refine Hash do
|
8
|
+
def deeply_symbolize_keys!
|
9
|
+
temp = self.deeply_symbolize_keys
|
10
|
+
self.clear
|
11
|
+
self.merge!( temp )
|
12
|
+
end
|
13
|
+
|
14
|
+
def deeply_symbolize_keys
|
15
|
+
self.each_with_object({}) do |(key, obj), hash|
|
16
|
+
k = key.to_s.to_sym
|
17
|
+
case obj
|
18
|
+
when Array, Hash
|
19
|
+
hash[k] = obj.deeply_symbolize_keys
|
20
|
+
else
|
21
|
+
hash[k] = obj
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
9
25
|
end
|
10
26
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
27
|
+
refine Array do
|
28
|
+
def deeply_symbolize_keys!
|
29
|
+
temp = self.deeply_symbolize_keys
|
30
|
+
self.clear
|
31
|
+
self.push( *temp )
|
32
|
+
end
|
33
|
+
|
34
|
+
def deeply_symbolize_keys
|
35
|
+
self.map do |obj|
|
36
|
+
case obj
|
37
|
+
when Array, Hash
|
38
|
+
obj.deeply_symbolize_keys
|
39
|
+
else
|
40
|
+
obj.dup
|
41
|
+
end
|
19
42
|
end
|
20
43
|
end
|
21
44
|
end
|
22
|
-
end
|
23
45
|
|
24
46
|
|
25
|
-
## deeply_stringify_keys
|
47
|
+
## deeply_stringify_keys
|
48
|
+
|
49
|
+
refine Hash do
|
50
|
+
def deeply_stringify_keys!
|
51
|
+
temp = self.deeply_stringify_keys
|
52
|
+
self.clear
|
53
|
+
self.merge!( temp )
|
54
|
+
end
|
26
55
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
56
|
+
def deeply_stringify_keys
|
57
|
+
self.each_with_object({}) do |(key, obj), hash|
|
58
|
+
k = key.to_s
|
59
|
+
case obj
|
60
|
+
when Array, Hash
|
61
|
+
hash[k] = obj.deeply_stringify_keys
|
62
|
+
else
|
63
|
+
hash[k] = obj
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
32
67
|
end
|
33
68
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
69
|
+
refine Array do
|
70
|
+
def deeply_stringify_keys!
|
71
|
+
temp = self.deeply_stringify_keys
|
72
|
+
self.clear
|
73
|
+
self.push( *temp )
|
74
|
+
end
|
75
|
+
|
76
|
+
def deeply_stringify_keys
|
77
|
+
self.map do |obj|
|
78
|
+
case obj
|
79
|
+
when Array, Hash
|
80
|
+
obj.deeply_stringify_keys
|
81
|
+
else
|
82
|
+
obj.dup
|
83
|
+
end
|
42
84
|
end
|
43
85
|
end
|
44
86
|
end
|
45
|
-
end
|
46
87
|
|
47
88
|
|
48
|
-
## deeply_merge
|
89
|
+
## deeply_merge
|
49
90
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
91
|
+
refine Hash do
|
92
|
+
def deeply_merge( hash )
|
93
|
+
raise ArgumentError( "type invalid. : %s" % hash ) unless hash.is_a? Hash
|
94
|
+
|
95
|
+
temp = self.deeply_dup
|
96
|
+
temp.deeply_merge!( hash )
|
97
|
+
temp
|
98
|
+
end
|
54
99
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
100
|
+
def deeply_merge!( hash )
|
101
|
+
raise ArgumentError( "type invalid. : %s" % hash ) unless hash.is_a? Hash
|
102
|
+
|
103
|
+
hash.each do |key, obj|
|
104
|
+
case obj
|
105
|
+
when NilClass
|
106
|
+
self[key] = nil
|
107
|
+
when Hash
|
108
|
+
self[key] = {} if self[key].nil?
|
109
|
+
self[key].deeply_merge!(obj)
|
110
|
+
else
|
111
|
+
self[key] = obj.dup
|
112
|
+
end
|
67
113
|
end
|
68
114
|
end
|
69
115
|
end
|
70
|
-
end
|
71
116
|
|
72
117
|
|
73
|
-
## deeply_map
|
118
|
+
## deeply_map
|
74
119
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
120
|
+
refine Hash do
|
121
|
+
def deeply_map( &block )
|
122
|
+
temp = self.deeply_dup
|
123
|
+
temp.deeply_map!( &block )
|
124
|
+
temp
|
125
|
+
end
|
79
126
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
127
|
+
def deeply_map!( &block )
|
128
|
+
self.each do |key, obj|
|
129
|
+
case obj
|
130
|
+
when NilClass
|
131
|
+
self[key] = nil
|
132
|
+
when Array, Hash
|
133
|
+
self[key].deeply_map!( &block )
|
134
|
+
else
|
135
|
+
self[key] = block.call( obj )
|
136
|
+
end
|
89
137
|
end
|
90
138
|
end
|
91
139
|
end
|
92
|
-
end
|
93
140
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
141
|
+
refine Array do
|
142
|
+
def deeply_map( &block )
|
143
|
+
temp = self.deeply_dup
|
144
|
+
temp.deeply_map!( &block )
|
145
|
+
temp
|
146
|
+
end
|
98
147
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
148
|
+
def deeply_map!( &block )
|
149
|
+
self.map! do |obj|
|
150
|
+
case obj
|
151
|
+
when NilClass
|
152
|
+
nil
|
153
|
+
when Array, Hash
|
154
|
+
obj.deeply_map!( &block )
|
155
|
+
else
|
156
|
+
block.call( obj )
|
157
|
+
end
|
108
158
|
end
|
109
159
|
end
|
110
160
|
end
|
111
|
-
end
|
112
161
|
|
113
162
|
|
114
|
-
## deeply_dup
|
163
|
+
## deeply_dup
|
115
164
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
165
|
+
refine Hash do
|
166
|
+
def deeply_dup
|
167
|
+
self.each_with_object({}) do |(key, obj), hash|
|
168
|
+
case obj
|
169
|
+
when NilClass
|
170
|
+
hash[key] = nil
|
171
|
+
when Array, Hash
|
172
|
+
hash[key] = obj.deeply_dup
|
173
|
+
else
|
174
|
+
hash[key] = obj.dup
|
175
|
+
end
|
126
176
|
end
|
127
177
|
end
|
128
178
|
end
|
129
|
-
end
|
130
179
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
180
|
+
refine Array do
|
181
|
+
def deeply_dup
|
182
|
+
self.map do |obj|
|
183
|
+
case obj
|
184
|
+
when NilClass
|
185
|
+
nil
|
186
|
+
when Array, Hash
|
187
|
+
obj.deeply_dup
|
188
|
+
else
|
189
|
+
obj.dup
|
190
|
+
end
|
141
191
|
end
|
142
192
|
end
|
143
193
|
end
|
194
|
+
|
144
195
|
end
|
145
196
|
|
data/lib/app/config/json.rb
CHANGED
@@ -3,18 +3,22 @@ require "erb"
|
|
3
3
|
require "json"
|
4
4
|
require "time"
|
5
5
|
require "date"
|
6
|
+
require_relative "deeply"
|
6
7
|
|
7
8
|
module App
|
8
9
|
module Config
|
10
|
+
using Deeply
|
9
11
|
|
10
12
|
class JSON < ::Hash
|
13
|
+
include App::Config::Base
|
14
|
+
|
11
15
|
DEFAULT_MASK = "*.json"
|
12
16
|
DEFAULT_SUFFIX = ".json"
|
17
|
+
DEFAULT_ENCODE = { allow_nan: true }
|
18
|
+
DEFAULT_DECODE = { allow_nan: true }
|
13
19
|
|
14
20
|
def initialize( **opts )
|
15
|
-
|
16
|
-
hash[key] = {}
|
17
|
-
end
|
21
|
+
super()
|
18
22
|
reload( **opts )
|
19
23
|
end
|
20
24
|
|
@@ -29,8 +33,8 @@ module App
|
|
29
33
|
@vardir = @paths.last
|
30
34
|
Dir.mkdir( @vardir ) unless ::Dir.exist?( @vardir )
|
31
35
|
|
32
|
-
@encode =
|
33
|
-
@decode =
|
36
|
+
@encode = DEFAULT_ENCODE.merge( encode || {} )
|
37
|
+
@decode = DEFAULT_DECODE.merge( decode || {} )
|
34
38
|
|
35
39
|
load_overlay( DEFAULT_MASK )
|
36
40
|
end
|
data/lib/app/config/ruby.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
require "fileutils"
|
2
2
|
require "pp"
|
3
|
+
require_relative "deeply"
|
3
4
|
|
4
5
|
module App
|
5
6
|
module Config
|
7
|
+
using Deeply
|
6
8
|
|
7
9
|
class RUBY < ::Hash
|
10
|
+
include App::Config::Base
|
11
|
+
|
8
12
|
DEFAULT_MASK = "*.rb"
|
9
13
|
DEFAULT_SUFFIX = ".rb"
|
14
|
+
DEFAULT_ENCODE = {}
|
15
|
+
DEFAULT_DECODE = {}
|
10
16
|
|
11
17
|
def initialize( **opts )
|
12
|
-
|
13
|
-
hash[key] = {}
|
14
|
-
end
|
18
|
+
super()
|
15
19
|
reload( **opts )
|
16
20
|
end
|
17
21
|
|
@@ -26,8 +30,8 @@ module App
|
|
26
30
|
@vardir = @paths.last
|
27
31
|
Dir.mkdir( @vardir ) unless ::Dir.exist?( @vardir )
|
28
32
|
|
29
|
-
@encode =
|
30
|
-
@decode =
|
33
|
+
@encode = DEFAULT_ENCODE.merge( encode || {} )
|
34
|
+
@decode = DEFAULT_DECODE.merge( decode || {} )
|
31
35
|
|
32
36
|
load_overlay( DEFAULT_MASK )
|
33
37
|
end
|
@@ -64,10 +68,14 @@ module App
|
|
64
68
|
pathname = savepathname(section)
|
65
69
|
hash = { section => self[section] }.deeply_stringify_keys
|
66
70
|
::File.open( pathname, "w" ) do |file|
|
67
|
-
file.puts( hash
|
71
|
+
file.puts( pretty_text( hash ) )
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
75
|
+
def pretty_text( hash )
|
76
|
+
hash.pretty_inspect
|
77
|
+
end
|
78
|
+
|
71
79
|
# remove and load configuration.
|
72
80
|
def reset( section )
|
73
81
|
raise ArgumentError, "'#{ section }' is not String." unless String === section
|
data/lib/app/config/version.rb
CHANGED
data/lib/app/config/yaml.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
require "fileutils"
|
2
2
|
require "erb"
|
3
3
|
require "yaml"
|
4
|
+
require_relative "deeply"
|
4
5
|
|
5
6
|
module App
|
6
7
|
module Config
|
8
|
+
using Deeply
|
7
9
|
|
8
10
|
class YAML < ::Hash
|
11
|
+
include App::Config::Base
|
12
|
+
|
9
13
|
DEFAULT_MASK = "*.{yml,yaml}"
|
10
14
|
DEFAULT_SUFFIX = ".yaml"
|
15
|
+
DEFAULT_ENCODE = {}
|
16
|
+
DEFAULT_DECODE = {}
|
11
17
|
|
12
18
|
def initialize( **opts )
|
13
|
-
|
14
|
-
hash[key] = {}
|
15
|
-
end
|
19
|
+
super()
|
16
20
|
reload( **opts )
|
17
21
|
end
|
18
22
|
|
@@ -27,8 +31,8 @@ module App
|
|
27
31
|
@vardir = @paths.last
|
28
32
|
Dir.mkdir( @vardir ) unless ::Dir.exist?( @vardir )
|
29
33
|
|
30
|
-
@encode =
|
31
|
-
@decode =
|
34
|
+
@encode = DEFAULT_ENCODE.merge( encode || {} )
|
35
|
+
@decode = DEFAULT_DECODE.merge( decode || {} )
|
32
36
|
|
33
37
|
load_overlay( DEFAULT_MASK )
|
34
38
|
end
|
@@ -66,10 +70,14 @@ module App
|
|
66
70
|
pathname = savepathname(section)
|
67
71
|
hash = { section => self[section] }.deeply_stringify_keys
|
68
72
|
::File.open( pathname, "w" ) do |file|
|
69
|
-
file.puts(
|
73
|
+
file.puts( pretty_text( hash ) )
|
70
74
|
end
|
71
75
|
end
|
72
76
|
|
77
|
+
def pretty_text( hash )
|
78
|
+
::YAML.dump( hash, **@encode )
|
79
|
+
end
|
80
|
+
|
73
81
|
# remove and load configuration.
|
74
82
|
def reset( section )
|
75
83
|
raise ArgumentError, "'#{ section }' is not String." unless String === section
|
data/sample/sample_1.rb
CHANGED
@@ -4,21 +4,21 @@ path = "$ROOT/config/defaults/:$ROOT/config:$ROOT/var"
|
|
4
4
|
|
5
5
|
# initialize variation
|
6
6
|
|
7
|
-
pp
|
8
|
-
pp
|
9
|
-
pp
|
7
|
+
pp App::Config.new
|
8
|
+
pp App::Config.new( root: Dir.pwd )
|
9
|
+
pp App::Config.new( path: path )
|
10
10
|
|
11
|
-
pp
|
12
|
-
pp
|
13
|
-
pp
|
14
|
-
pp
|
15
|
-
pp
|
16
|
-
pp
|
11
|
+
pp App::Config.new( :YAML )
|
12
|
+
pp App::Config.new( "YAML" )
|
13
|
+
pp App::Config.new( :YAML, path: path )
|
14
|
+
pp App::Config.new( "YAML", path: path )
|
15
|
+
pp App::Config::YAML.new
|
16
|
+
pp App::Config::YAML.new( path: path )
|
17
17
|
|
18
|
-
pp
|
19
|
-
pp
|
20
|
-
pp
|
21
|
-
pp
|
22
|
-
pp
|
23
|
-
pp
|
18
|
+
pp App::Config.new( :JSON )
|
19
|
+
pp App::Config.new( "JSON" )
|
20
|
+
pp App::Config.new( :JSON, path: path )
|
21
|
+
pp App::Config.new( "JSON", path: path )
|
22
|
+
pp App::Config::JSON.new
|
23
|
+
pp App::Config::JSON.new( path: path )
|
24
24
|
|
metadata
CHANGED
@@ -1,44 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app-configs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- arimay
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
-
description: "
|
40
|
+
version: '0'
|
41
|
+
description: " App::Config is yet another library for load/save app config files. "
|
42
42
|
email:
|
43
43
|
- arima.yasuhiro@gmail.com
|
44
44
|
executables: []
|
@@ -47,7 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
49
|
- ".rspec"
|
50
|
-
- ".
|
50
|
+
- ".rubocop.yml"
|
51
51
|
- Gemfile
|
52
52
|
- README.adoc
|
53
53
|
- README.ja.adoc
|
@@ -73,7 +73,7 @@ homepage: https://github.com/arimay/app-configs
|
|
73
73
|
licenses:
|
74
74
|
- MIT
|
75
75
|
metadata: {}
|
76
|
-
post_install_message:
|
76
|
+
post_install_message:
|
77
77
|
rdoc_options: []
|
78
78
|
require_paths:
|
79
79
|
- lib
|
@@ -88,8 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
|
-
rubygems_version: 3.
|
92
|
-
signing_key:
|
91
|
+
rubygems_version: 3.2.3
|
92
|
+
signing_key:
|
93
93
|
specification_version: 4
|
94
94
|
summary: Application config loader/saver.
|
95
95
|
test_files: []
|