configliere 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/configliere.gemspec +4 -3
- data/lib/configliere.rb +3 -3
- data/lib/configliere/config_file.rb +14 -1
- data/lib/configliere/core_ext/blank.rb +10 -6
- data/lib/configliere/core_ext/hash.rb +8 -10
- data/lib/configliere/define.rb +1 -1
- data/lib/configliere/env_var.rb +2 -2
- data/lib/configliere/param.rb +1 -1
- metadata +5 -10
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/configliere.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{configliere}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["mrflip"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-04-02}
|
13
13
|
s.default_executable = %q{configliere}
|
14
14
|
s.description = %q{ You've got a script. It's got some settings. Some settings are for this module, some are for that module. Most of them don't change. Except on your laptop, where the paths are different. Or when you're in production mode. Or when you're testing from the command line.
|
15
15
|
|
@@ -67,7 +67,7 @@ Configliere manage settings from many sources: static constants, simple config f
|
|
67
67
|
]
|
68
68
|
s.homepage = %q{http://github.com/mrflip/configliere}
|
69
69
|
s.require_paths = ["lib"]
|
70
|
-
s.rubygems_version = %q{1.
|
70
|
+
s.rubygems_version = %q{1.3.7}
|
71
71
|
s.summary = %q{Wise, discreet configuration management}
|
72
72
|
s.test_files = [
|
73
73
|
"examples/config_block_script.rb",
|
@@ -89,6 +89,7 @@ Configliere manage settings from many sources: static constants, simple config f
|
|
89
89
|
]
|
90
90
|
|
91
91
|
if s.respond_to? :specification_version then
|
92
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
92
93
|
s.specification_version = 3
|
93
94
|
|
94
95
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/lib/configliere.rb
CHANGED
@@ -7,7 +7,7 @@ module Configliere
|
|
7
7
|
|
8
8
|
# delegates to Configliere::Param
|
9
9
|
def self.new *args, &block
|
10
|
-
Configliere::Param.new
|
10
|
+
Configliere::Param.new(*args, &block)
|
11
11
|
end
|
12
12
|
|
13
13
|
ALL_MIXINS = [:define, :config_file, :commandline, :encrypted, :env_var, :config_block, :git_style_binaries]
|
@@ -20,7 +20,7 @@ module Configliere
|
|
20
20
|
|
21
21
|
# Base class for Configliere errors.
|
22
22
|
Error = Class.new(StandardError)
|
23
|
-
|
23
|
+
|
24
24
|
end
|
25
25
|
|
26
26
|
# Defines a global config object
|
@@ -32,5 +32,5 @@ Settings = Configliere.new unless defined?(Settings)
|
|
32
32
|
# pattern.
|
33
33
|
#
|
34
34
|
def Settings *args
|
35
|
-
Settings.defaults
|
35
|
+
Settings.defaults(*args)
|
36
36
|
end
|
@@ -13,7 +13,16 @@ module Configliere
|
|
13
13
|
# Load params from disk.
|
14
14
|
# * file is in YAML format, as a hash of handle => param_hash pairs
|
15
15
|
# * filename defaults to Configliere::DEFAULT_CONFIG_FILE (~/.configliere, probably)
|
16
|
-
|
16
|
+
#
|
17
|
+
# @option [String] :env
|
18
|
+
# If an :env option is given, only the indicated subhash is merged. This
|
19
|
+
# lets you for example specify production / environment / test settings
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# # Read from config/apey_eye.yaml and use settings appropriate for development/staging/production
|
23
|
+
# Settings.read(root_path('config/apey_eye.yaml'), :env => (ENV['RACK_ENV'] || 'production'))
|
24
|
+
#
|
25
|
+
def read handle, options={}
|
17
26
|
filename = filename_for_handle(handle)
|
18
27
|
begin
|
19
28
|
params = YAML.load(File.open(filename)) || {}
|
@@ -22,6 +31,10 @@ module Configliere
|
|
22
31
|
params = {}
|
23
32
|
end
|
24
33
|
params = params[handle] if handle.is_a?(Symbol)
|
34
|
+
# Extract the :env (production/development/etc)
|
35
|
+
if options[:env]
|
36
|
+
params = params[options[:env]]
|
37
|
+
end
|
25
38
|
deep_merge! params
|
26
39
|
end
|
27
40
|
|
@@ -1,3 +1,7 @@
|
|
1
|
+
#
|
2
|
+
# This is taken in whole from the extlib gem. Thanks y'all.
|
3
|
+
#
|
4
|
+
|
1
5
|
class Object
|
2
6
|
##
|
3
7
|
# Returns true if the object is nil or empty (if applicable)
|
@@ -11,7 +15,7 @@ class Object
|
|
11
15
|
# @api public
|
12
16
|
def blank?
|
13
17
|
nil? || (respond_to?(:empty?) && empty?)
|
14
|
-
end
|
18
|
+
end unless method_defined?(:blank?)
|
15
19
|
end # class Object
|
16
20
|
|
17
21
|
class Numeric
|
@@ -27,7 +31,7 @@ class Numeric
|
|
27
31
|
# @api public
|
28
32
|
def blank?
|
29
33
|
false
|
30
|
-
end
|
34
|
+
end unless method_defined?(:blank?)
|
31
35
|
end # class Numeric
|
32
36
|
|
33
37
|
class NilClass
|
@@ -41,7 +45,7 @@ class NilClass
|
|
41
45
|
# @api public
|
42
46
|
def blank?
|
43
47
|
true
|
44
|
-
end
|
48
|
+
end unless method_defined?(:blank?)
|
45
49
|
end # class NilClass
|
46
50
|
|
47
51
|
class TrueClass
|
@@ -55,7 +59,7 @@ class TrueClass
|
|
55
59
|
# @api public
|
56
60
|
def blank?
|
57
61
|
false
|
58
|
-
end
|
62
|
+
end unless method_defined?(:blank?)
|
59
63
|
end # class TrueClass
|
60
64
|
|
61
65
|
class FalseClass
|
@@ -69,7 +73,7 @@ class FalseClass
|
|
69
73
|
# @api public
|
70
74
|
def blank?
|
71
75
|
true
|
72
|
-
end
|
76
|
+
end unless method_defined?(:blank?)
|
73
77
|
end # class FalseClass
|
74
78
|
|
75
79
|
class String
|
@@ -85,5 +89,5 @@ class String
|
|
85
89
|
# @api public
|
86
90
|
def blank?
|
87
91
|
strip.empty?
|
88
|
-
end
|
92
|
+
end unless method_defined?(:blank?)
|
89
93
|
end # class String
|
@@ -30,12 +30,12 @@ class Hash
|
|
30
30
|
#
|
31
31
|
def deep_merge hsh2
|
32
32
|
merge hsh2, &Hash::DEEP_MERGER
|
33
|
-
end
|
33
|
+
end unless method_defined?(:deep_merge)
|
34
34
|
|
35
35
|
def deep_merge! hsh2
|
36
36
|
update hsh2, &Hash::DEEP_MERGER
|
37
37
|
self
|
38
|
-
end
|
38
|
+
end unless method_defined?(:deep_merge!)
|
39
39
|
|
40
40
|
#
|
41
41
|
# Treat hash as tree of hashes:
|
@@ -55,7 +55,7 @@ class Hash
|
|
55
55
|
args.each{|key| hsh = (hsh[key] ||= self.class.new) }
|
56
56
|
# set leaf value
|
57
57
|
hsh[last_key] = val
|
58
|
-
end
|
58
|
+
end unless method_defined?(:deep_set)
|
59
59
|
|
60
60
|
#
|
61
61
|
# Treat hash as tree of hashes:
|
@@ -73,11 +73,10 @@ class Hash
|
|
73
73
|
def deep_get *args
|
74
74
|
last_key = args.pop
|
75
75
|
# dig down to last subtree (building out if necessary)
|
76
|
-
hsh = args.inject(self){|
|
76
|
+
hsh = args.inject(self){|h, k| h[k] || {} }
|
77
77
|
# get leaf value
|
78
78
|
hsh[last_key]
|
79
|
-
end
|
80
|
-
|
79
|
+
end unless method_defined?(:deep_get)
|
81
80
|
|
82
81
|
#
|
83
82
|
# Treat hash as tree of hashes:
|
@@ -92,19 +91,18 @@ class Hash
|
|
92
91
|
last_key = args.pop
|
93
92
|
last_hsh = args.empty? ? self : (deep_get(*args)||{})
|
94
93
|
last_hsh.delete(last_key)
|
95
|
-
end
|
94
|
+
end unless method_defined?(:deep_delete)
|
96
95
|
|
97
96
|
#
|
98
97
|
# remove all key-value pairs where the value is nil
|
99
98
|
#
|
100
99
|
def compact
|
101
100
|
reject{|key,val| val.nil? }
|
102
|
-
end
|
101
|
+
end unless method_defined?(:compact)
|
103
102
|
#
|
104
103
|
# Replace the hash with its compacted self
|
105
104
|
#
|
106
105
|
def compact!
|
107
106
|
replace(compact)
|
108
|
-
end
|
109
|
-
|
107
|
+
end unless method_defined?(:compact!)
|
110
108
|
end
|
data/lib/configliere/define.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Configliere
|
2
2
|
module Define
|
3
3
|
# Definitions for params: :description, :type, :encrypted, etc.
|
4
|
-
|
4
|
+
attr_writer :param_definitions
|
5
5
|
|
6
6
|
# @param param the setting to describe. Either a simple symbol or a dotted param string.
|
7
7
|
# @param definitions the defineables to set (:description, :type, :encrypted, etc.)
|
data/lib/configliere/env_var.rb
CHANGED
data/lib/configliere/param.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configliere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
8
|
+
- 3
|
9
|
+
version: 0.2.3
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- mrflip
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-
|
17
|
+
date: 2011-04-02 00:00:00 -05:00
|
19
18
|
default_executable: configliere
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 13
|
30
28
|
segments:
|
31
29
|
- 1
|
32
30
|
- 2
|
@@ -42,7 +40,6 @@ dependencies:
|
|
42
40
|
requirements:
|
43
41
|
- - ">="
|
44
42
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
43
|
segments:
|
47
44
|
- 0
|
48
45
|
version: "0"
|
@@ -113,7 +110,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
110
|
requirements:
|
114
111
|
- - ">="
|
115
112
|
- !ruby/object:Gem::Version
|
116
|
-
hash: 3
|
117
113
|
segments:
|
118
114
|
- 0
|
119
115
|
version: "0"
|
@@ -122,14 +118,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
118
|
requirements:
|
123
119
|
- - ">="
|
124
120
|
- !ruby/object:Gem::Version
|
125
|
-
hash: 3
|
126
121
|
segments:
|
127
122
|
- 0
|
128
123
|
version: "0"
|
129
124
|
requirements: []
|
130
125
|
|
131
126
|
rubyforge_project:
|
132
|
-
rubygems_version: 1.
|
127
|
+
rubygems_version: 1.3.7
|
133
128
|
signing_key:
|
134
129
|
specification_version: 3
|
135
130
|
summary: Wise, discreet configuration management
|