localconfig 0.2.0 → 0.3.0
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 +7 -0
- data/README.md +23 -29
- data/lib/localconfig.rb +3 -3
- data/lib/localconfig/admin.rb +3 -3
- data/lib/localconfig/config.rb +109 -17
- data/lib/localconfig/rails.rb +3 -3
- data/lib/localconfig/rake.rb +3 -3
- data/lib/localconfig/version.rb +2 -2
- data/localconfig.gemspec +1 -1
- data/spec/localconfig/config_spec.rb +3 -3
- metadata +37 -33
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 69720f49e2aaf298ba101c6cf4b62d19896ccabc
|
4
|
+
data.tar.gz: 08cdc94023f7e7c30c61d0b876c109c625806786
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 899ffc8ed6c89e921ba45511ef76a3f93e3bb166b819916f19e5ce71afb05502c9dd2d4eeda10da6797008bba7f1bd1907cae4cfef854a097bf436ed4f2e7dda
|
7
|
+
data.tar.gz: 5056aaf7eb5d76e79a57619a989ca3d47dc040a64e2959f35ce34972473f7e958dacb287a26ec1d8b81ae34eb938957bbc6d860df614762eca57f31743e1b9e9
|
data/README.md
CHANGED
@@ -2,13 +2,15 @@
|
|
2
2
|
|
3
3
|
File : README.md
|
4
4
|
Maintainer : Felix C. Stegerman <flx@obfusk.net>
|
5
|
-
Date :
|
5
|
+
Date : 2014-10-21
|
6
6
|
|
7
|
-
Copyright : Copyright (C)
|
8
|
-
Version : v0.
|
7
|
+
Copyright : Copyright (C) 2014 Felix C. Stegerman
|
8
|
+
Version : v0.3.0
|
9
9
|
|
10
10
|
[]: }}}1
|
11
11
|
|
12
|
+
[](https://rubygems.org/gems/localconfig)
|
13
|
+
|
12
14
|
## Description
|
13
15
|
[]: {{{1
|
14
16
|
|
@@ -20,7 +22,7 @@
|
|
20
22
|
files from this directory.
|
21
23
|
|
22
24
|
Additionally, it allows rails applications to easily define
|
23
|
-
admin:exists and admin:create rake tasks to make it easier to
|
25
|
+
`admin:exists` and `admin:create` rake tasks to make it easier to
|
24
26
|
automate application setup.
|
25
27
|
|
26
28
|
Just about everything is configurable: see the docs.
|
@@ -33,19 +35,24 @@
|
|
33
35
|
## Examples
|
34
36
|
[]: {{{1
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
```
|
38
|
+
```ruby
|
39
|
+
# Gemfile
|
39
40
|
gem 'localconfig', require: 'localconfig/rails'
|
40
41
|
```
|
41
42
|
|
42
|
-
config/localconfig.rb
|
43
|
-
|
44
43
|
```ruby
|
44
|
+
# config/localconfig.rb
|
45
45
|
LocalConfig['rails'].configure do |c|
|
46
46
|
puts "env: #{c.env}, #{Rails.env}"
|
47
|
+
|
47
48
|
c.require 'init.rb'
|
49
|
+
|
48
50
|
c.load_json 'pg.json'
|
51
|
+
c.load_yaml 'git.yml' # repo:, branch:
|
52
|
+
c.git_repo 'more', c.git.repo, branch: c.git.branch
|
53
|
+
c.load_dir 'more' # more/foo.yml, more/bar.json
|
54
|
+
puts "more: #{c.more.foo.key1} #{c.more.bar.key2}"
|
55
|
+
|
49
56
|
c.on_admin_exists do |username|
|
50
57
|
# ...
|
51
58
|
end
|
@@ -58,37 +65,24 @@ end
|
|
58
65
|
[]: }}}1
|
59
66
|
|
60
67
|
## Specs & Docs
|
61
|
-
[]: {{{1
|
62
68
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
69
|
+
```bash
|
70
|
+
rake spec
|
71
|
+
rake docs
|
72
|
+
```
|
67
73
|
|
68
74
|
## TODO
|
69
|
-
[]: {{{1
|
70
75
|
|
71
76
|
* more specs/docs?
|
72
77
|
* ...
|
73
78
|
|
74
|
-
[]: }}}1
|
75
|
-
|
76
79
|
## License
|
77
|
-
[]: {{{1
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
[]: }}}1
|
81
|
+
LGPLv3+ [1].
|
82
82
|
|
83
83
|
## References
|
84
|
-
[]: {{{1
|
85
|
-
|
86
|
-
[1] GNU General Public License, version 2
|
87
|
-
--- http://www.opensource.org/licenses/GPL-2.0
|
88
84
|
|
89
|
-
[
|
90
|
-
--- http://www.
|
91
|
-
|
92
|
-
[]: }}}1
|
85
|
+
[1] GNU Lesser General Public License, version 3
|
86
|
+
--- http://www.gnu.org/licenses/lgpl-3.0.html
|
93
87
|
|
94
88
|
[]: ! ( vim: set tw=70 sw=2 sts=2 et fdm=marker : )
|
data/lib/localconfig.rb
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
#
|
3
3
|
# File : localconfig.rb
|
4
4
|
# Maintainer : Felix C. Stegerman <flx@obfusk.net>
|
5
|
-
# Date :
|
5
|
+
# Date : 2014-10-21
|
6
6
|
#
|
7
|
-
# Copyright : Copyright (C)
|
8
|
-
# Licence :
|
7
|
+
# Copyright : Copyright (C) 2014 Felix C. Stegerman
|
8
|
+
# Licence : LGPLv3+
|
9
9
|
#
|
10
10
|
# -- ; }}}1
|
11
11
|
|
data/lib/localconfig/admin.rb
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
#
|
3
3
|
# File : localconfig/admin.rb
|
4
4
|
# Maintainer : Felix C. Stegerman <flx@obfusk.net>
|
5
|
-
# Date :
|
5
|
+
# Date : 2014-10-21
|
6
6
|
#
|
7
|
-
# Copyright : Copyright (C)
|
8
|
-
# Licence :
|
7
|
+
# Copyright : Copyright (C) 2014 Felix C. Stegerman
|
8
|
+
# Licence : LGPLv3+
|
9
9
|
#
|
10
10
|
# -- ; }}}1
|
11
11
|
|
data/lib/localconfig/config.rb
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
#
|
3
3
|
# File : localconfig/config.rb
|
4
4
|
# Maintainer : Felix C. Stegerman <flx@obfusk.net>
|
5
|
-
# Date :
|
5
|
+
# Date : 2014-10-21
|
6
6
|
#
|
7
|
-
# Copyright : Copyright (C)
|
8
|
-
# Licence :
|
7
|
+
# Copyright : Copyright (C) 2014 Felix C. Stegerman
|
8
|
+
# Licence : LGPLv3+
|
9
9
|
#
|
10
10
|
# -- ; }}}1
|
11
11
|
|
@@ -23,6 +23,9 @@ module LocalConfig
|
|
23
23
|
# configuration
|
24
24
|
class Config # {{{1
|
25
25
|
|
26
|
+
# something went wrong calling `system`
|
27
|
+
class RunError < StandardError; end
|
28
|
+
|
26
29
|
# dir
|
27
30
|
attr_accessor :dir
|
28
31
|
|
@@ -36,6 +39,11 @@ module LocalConfig
|
|
36
39
|
@name = opts[:name] || derive_name
|
37
40
|
end
|
38
41
|
|
42
|
+
# access setting by key
|
43
|
+
def [](k)
|
44
|
+
@config[k.to_s]
|
45
|
+
end
|
46
|
+
|
39
47
|
# configure; self is passed to the block
|
40
48
|
# @return self
|
41
49
|
def configure(&b)
|
@@ -58,7 +66,7 @@ module LocalConfig
|
|
58
66
|
end
|
59
67
|
end # }}}2
|
60
68
|
|
61
|
-
#
|
69
|
+
# `dir/name/...`
|
62
70
|
def path(*paths)
|
63
71
|
([dir,name] + paths)*'/'
|
64
72
|
end
|
@@ -70,21 +78,94 @@ module LocalConfig
|
|
70
78
|
|
71
79
|
# require relative to path
|
72
80
|
def require(*files)
|
73
|
-
_files(files).
|
81
|
+
_files(files).each { |f| Kernel.require f[:path] }
|
82
|
+
nil
|
74
83
|
end
|
75
84
|
|
76
85
|
# load json file relative to path and store as Hashie::Mash in
|
77
|
-
# self
|
86
|
+
# self; for example:
|
87
|
+
#
|
88
|
+
# ```
|
89
|
+
# lc.load_json 'foo.json'
|
90
|
+
# lc.foo.key1
|
91
|
+
# lc.load_json 'bar/baz.json'
|
92
|
+
# lc.bar.baz.key2
|
93
|
+
# ```
|
78
94
|
def load_json(*files)
|
79
|
-
_load
|
95
|
+
_load %w{ .json }, (-> x { JSON.parse x }), files
|
80
96
|
end
|
81
97
|
|
82
98
|
# load yaml file relative to path and store as Hashie::Mash in
|
83
|
-
# self
|
99
|
+
# self; for example:
|
100
|
+
#
|
101
|
+
# ```
|
102
|
+
# lc.load_yaml 'foo.yaml'
|
103
|
+
# lc.foo.key1
|
104
|
+
# lc.load_yaml 'bar/baz.yml'
|
105
|
+
# lc.bar.baz.key2
|
106
|
+
# ```
|
84
107
|
def load_yaml(*files)
|
85
|
-
_load
|
108
|
+
_load %w{ .yml .yaml }, (-> x { YAML.load x }), files
|
109
|
+
end
|
110
|
+
|
111
|
+
# `load_{json,yaml}` `*.json`, `*.y{a,}ml` in dir; for example:
|
112
|
+
#
|
113
|
+
# ```
|
114
|
+
# lc.load_dir 'more' # more/foo.json, more/bar.yml
|
115
|
+
# lc.more.foo.key1
|
116
|
+
# lc.more.bar.key2
|
117
|
+
# ```
|
118
|
+
def load_dir(*dirs)
|
119
|
+
dirs.flat_map do |d|
|
120
|
+
j = glob "#{d}/*.json"; y = glob "#{d}/*.y{a,}ml"
|
121
|
+
load_json *j; load_yaml *y; j + y
|
122
|
+
end
|
86
123
|
end
|
87
124
|
|
125
|
+
# <!-- {{{1 -->
|
126
|
+
#
|
127
|
+
# clone/fetch git repo in dir (to load more config files from
|
128
|
+
# elsewhere); for example:
|
129
|
+
#
|
130
|
+
# ```
|
131
|
+
# lc.load_yaml 'git.yml' # repo:, branch:
|
132
|
+
# lc.git_repo 'more', c.git.repo, branch: c.git.branch
|
133
|
+
# lc.load_dir 'more' # more/foo.yml, more/bar.json
|
134
|
+
# ```
|
135
|
+
#
|
136
|
+
# You can't use more than one of `:rev`, `:tag`, `:branch`; if you
|
137
|
+
# specify none, the default is `branch: 'master'`.
|
138
|
+
#
|
139
|
+
# @param [String] path subpath to clone to
|
140
|
+
# @param [String] url url to clone from
|
141
|
+
#
|
142
|
+
# @param [Hash] opts options
|
143
|
+
# @option opts [Bool] :quiet (true) whether to be quiet
|
144
|
+
# @option opts [String] :rev specific revision (SHA1)
|
145
|
+
# @option opts [String] :tag specific tag
|
146
|
+
# @option opts [String] :branch specific branch
|
147
|
+
#
|
148
|
+
# <!-- }}}1 -->
|
149
|
+
def git_repo(path, url, opts = {}) # {{{1
|
150
|
+
q = opts.fetch(:quiet, true) ? %w{ --quiet } : []
|
151
|
+
b = opts[:branch]; b = "origin/#{b}" if b && !b['/']
|
152
|
+
rev = opts[:rev] || opts[:tag]
|
153
|
+
ref = rev || b || 'origin/master'
|
154
|
+
dest = path path
|
155
|
+
if File.exist? dest
|
156
|
+
Dir.chdir(dest) do
|
157
|
+
_sys *(%w{ git fetch --force --tags } + q) \
|
158
|
+
unless rev && %x[ git rev-parse HEAD ] ==
|
159
|
+
%x[ git rev-parse --revs-only #{rev}^0 -- ]
|
160
|
+
end
|
161
|
+
else
|
162
|
+
_sys *(%w{ git clone } + q + [url, dest])
|
163
|
+
end
|
164
|
+
Dir.chdir(dest) do
|
165
|
+
_sys *(%w{ git reset --hard } + q + [ref] + %w{ -- })
|
166
|
+
end
|
167
|
+
end # }}}1
|
168
|
+
|
88
169
|
# --
|
89
170
|
|
90
171
|
# LocalConfig.branch
|
@@ -97,20 +178,31 @@ module LocalConfig
|
|
97
178
|
|
98
179
|
# files relative to path
|
99
180
|
def _files(files)
|
100
|
-
files.map { |f| "#{path}/#{f}" }
|
181
|
+
files.map { |f| { f: f, path: "#{path}/#{f}" } }
|
101
182
|
end
|
102
183
|
|
103
|
-
# load file relative to path and store as Hashie::Mash in
|
104
|
-
#
|
105
|
-
def _load(ext, parse, files) # {{{2
|
184
|
+
# load file relative to path and store as Hashie::Mash in self
|
185
|
+
def _load(exts, parse, files) # {{{2
|
106
186
|
_files(files).each do |f|
|
107
|
-
b =
|
108
|
-
|
109
|
-
|
110
|
-
|
187
|
+
*pre, b = all = Pathname.new(f[:f]).each_filename.to_a
|
188
|
+
ext = exts.find { |x| b.end_with? x } || ''
|
189
|
+
k = File.basename b, ext ; c_k = (pre+[k]).first
|
190
|
+
o = @config
|
191
|
+
pre.each { |x| o = o[x] ||= Hashie::Mash.new }
|
192
|
+
raise "self.#{(pre+[k])*'.'} already set" if o[k]
|
193
|
+
o[k] = Hashie::Mash.new parse[File.read(f[:path])]
|
194
|
+
define_singleton_method(c_k) { @config[c_k] } \
|
195
|
+
unless self.respond_to? c_k
|
111
196
|
end
|
197
|
+
nil
|
112
198
|
end # }}}2
|
113
199
|
|
200
|
+
# run!
|
201
|
+
def _sys(cmd, *args)
|
202
|
+
system([cmd, cmd], *args) or \
|
203
|
+
raise RunError, "failed to run command #{[cmd]+args} (#$?)"
|
204
|
+
end
|
205
|
+
|
114
206
|
end # }}}1
|
115
207
|
|
116
208
|
# --
|
data/lib/localconfig/rails.rb
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
#
|
3
3
|
# File : localconfig/rails.rb
|
4
4
|
# Maintainer : Felix C. Stegerman <flx@obfusk.net>
|
5
|
-
# Date :
|
5
|
+
# Date : 2014-10-21
|
6
6
|
#
|
7
|
-
# Copyright : Copyright (C)
|
8
|
-
# Licence :
|
7
|
+
# Copyright : Copyright (C) 2014 Felix C. Stegerman
|
8
|
+
# Licence : LGPLv3+
|
9
9
|
#
|
10
10
|
# -- ; }}}1
|
11
11
|
|
data/lib/localconfig/rake.rb
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
#
|
3
3
|
# File : localconfig/rake.rb
|
4
4
|
# Maintainer : Felix C. Stegerman <flx@obfusk.net>
|
5
|
-
# Date :
|
5
|
+
# Date : 2014-10-21
|
6
6
|
#
|
7
|
-
# Copyright : Copyright (C)
|
8
|
-
# Licence :
|
7
|
+
# Copyright : Copyright (C) 2014 Felix C. Stegerman
|
8
|
+
# Licence : LGPLv3+
|
9
9
|
#
|
10
10
|
# -- ; }}}1
|
11
11
|
|
data/lib/localconfig/version.rb
CHANGED
data/localconfig.gemspec
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
#
|
3
3
|
# File : localconfig/config_spec.rb
|
4
4
|
# Maintainer : Felix C. Stegerman <flx@obfusk.net>
|
5
|
-
# Date :
|
5
|
+
# Date : 2014-10-21
|
6
6
|
#
|
7
|
-
# Copyright : Copyright (C)
|
8
|
-
# Licence :
|
7
|
+
# Copyright : Copyright (C) 2014 Felix C. Stegerman
|
8
|
+
# Licence : LGPLv3+
|
9
9
|
#
|
10
10
|
# -- ; }}}1
|
11
11
|
|
metadata
CHANGED
@@ -1,97 +1,101 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: localconfig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Felix C. Stegerman
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: hashie
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: rake
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: rspec
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - ">="
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '0'
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
47
|
-
|
48
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: |
|
56
|
+
local configuration for ruby (web) apps
|
49
57
|
|
50
58
|
...
|
51
|
-
|
52
|
-
'
|
53
59
|
email:
|
54
60
|
- flx@obfusk.net
|
55
61
|
executables: []
|
56
62
|
extensions: []
|
57
63
|
extra_rdoc_files: []
|
58
64
|
files:
|
59
|
-
- .yardopts
|
65
|
+
- ".yardopts"
|
60
66
|
- README.md
|
61
67
|
- Rakefile
|
62
|
-
- localconfig.
|
68
|
+
- lib/localconfig.rb
|
69
|
+
- lib/localconfig/admin.rb
|
70
|
+
- lib/localconfig/config.rb
|
71
|
+
- lib/localconfig/rails.rb
|
63
72
|
- lib/localconfig/rake.rb
|
64
73
|
- lib/localconfig/version.rb
|
65
|
-
-
|
66
|
-
- lib/localconfig/config.rb
|
67
|
-
- lib/localconfig/admin.rb
|
68
|
-
- lib/localconfig.rb
|
74
|
+
- localconfig.gemspec
|
69
75
|
- spec/localconfig/config_spec.rb
|
70
76
|
homepage: https://github.com/obfusk/rb-localconfig
|
71
77
|
licenses:
|
72
|
-
-
|
73
|
-
|
78
|
+
- LGPLv3+
|
79
|
+
metadata: {}
|
74
80
|
post_install_message:
|
75
81
|
rdoc_options: []
|
76
82
|
require_paths:
|
77
83
|
- lib
|
78
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
85
|
requirements:
|
81
|
-
- -
|
86
|
+
- - ">="
|
82
87
|
- !ruby/object:Gem::Version
|
83
88
|
version: 1.9.1
|
84
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
90
|
requirements:
|
87
|
-
- -
|
91
|
+
- - ">="
|
88
92
|
- !ruby/object:Gem::Version
|
89
93
|
version: '0'
|
90
94
|
requirements: []
|
91
95
|
rubyforge_project:
|
92
|
-
rubygems_version:
|
96
|
+
rubygems_version: 2.2.2
|
93
97
|
signing_key:
|
94
|
-
specification_version:
|
98
|
+
specification_version: 4
|
95
99
|
summary: local configuration for ruby (web) apps
|
96
100
|
test_files: []
|
97
101
|
has_rdoc:
|