config_plus 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/config_plus/base.rb +35 -34
- data/lib/config_plus/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93199817135b965a48712d1c659c03c93f6cd27b
|
4
|
+
data.tar.gz: b6f9ddced4e4e05a876b4d78aafa6552b5589b2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49e59f9dc8bd1b3a5cd5d3ba14cc07eba8a3e38154d71198a37f95f7a3744a1e8cb874f93bd39c68e47f20f4fa776789290aff56486380d31694385b836ab1fe
|
7
|
+
data.tar.gz: 594a37efbd171daf932e102f021abde34b221a31ddcf5b6b5baf6cc70a58298a76d52edbcd0b635aecf187eeb810bb5e8b26d50649d4bbb0479ec4c6b634cfaa
|
data/lib/config_plus/base.rb
CHANGED
@@ -4,17 +4,16 @@ module ConfigPlus
|
|
4
4
|
|
5
5
|
# Sets up configuration of ++ConfigPlus++ and loads data
|
6
6
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# configuration data would be loaded from the file.
|
7
|
+
# Set a YAML file path to ++source++ property and you can
|
8
|
+
# access its data with ++ConfigPlus.root++.
|
10
9
|
#
|
11
10
|
# ConfigPlus.configure do |conf|
|
12
11
|
# conf.source = '/path/to/yaml/file.yml'
|
13
12
|
# end
|
14
13
|
#
|
15
|
-
# When a directory path
|
16
|
-
#
|
17
|
-
#
|
14
|
+
# When you set a directory path to ++source++,
|
15
|
+
# you get configuration data that is merged every contents
|
16
|
+
# of YAML files under the directory you specify.
|
18
17
|
#
|
19
18
|
def configure
|
20
19
|
yield config if block_given?
|
@@ -37,48 +36,50 @@ module ConfigPlus
|
|
37
36
|
load
|
38
37
|
end
|
39
38
|
|
39
|
+
def included(base)
|
40
|
+
method_name = self.config.config_method
|
41
|
+
return unless method_name
|
42
|
+
own = self::Helper.config_for(base, self.root)
|
43
|
+
inheritance = inherited_config_of(base)
|
44
|
+
|
45
|
+
[base, base.singleton_class].each do |obj|
|
46
|
+
obj.instance_eval do
|
47
|
+
config = inheritance ?
|
48
|
+
::ConfigPlus::Merger.merge(inheritance, own || {}) : own
|
49
|
+
config = ::ConfigPlus::Node.new(config)
|
50
|
+
define_method method_name, -> { config }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
40
55
|
protected
|
41
56
|
|
42
57
|
def config
|
43
|
-
@config ||= ::
|
58
|
+
@config ||= self::Config.new
|
44
59
|
end
|
45
60
|
|
46
61
|
private
|
47
62
|
|
48
|
-
#
|
63
|
+
# Loads a configuration data as a hash object
|
49
64
|
# from files specified with ++source++ or
|
50
65
|
# ++root_dir++ settings.
|
51
66
|
#
|
52
67
|
def load
|
53
68
|
hash = config.loader.load
|
54
|
-
@root = ::
|
69
|
+
@root = self::Node.new(hash)
|
55
70
|
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.included(base)
|
59
|
-
method_name = self.config.config_method
|
60
|
-
return unless method_name
|
61
|
-
variable_name = "@#{method_name}"
|
62
|
-
helper = ::ConfigPlus::Helper
|
63
|
-
own = helper.config_for(base, ::ConfigPlus.root)
|
64
71
|
|
65
|
-
|
66
|
-
klass
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
h
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
[base, base.singleton_class].each do |obj|
|
77
|
-
obj.instance_eval do
|
78
|
-
config = inheritance ? inheritance.merge(own || {}) : own
|
79
|
-
config = ::ConfigPlus::Node.new(config)
|
80
|
-
define_method method_name, -> { config }
|
81
|
-
end
|
72
|
+
def inherited_config_of(klass)
|
73
|
+
klass.ancestors.select {|clazz|
|
74
|
+
clazz != klass and
|
75
|
+
clazz != self and
|
76
|
+
clazz.ancestors.include?(self)
|
77
|
+
}.reverse.each.inject({}) {|hsh, clazz|
|
78
|
+
h = clazz.public_send(self.config.config_method)
|
79
|
+
h = self::Helper.config_for(clazz, self.root) unless
|
80
|
+
h or h.is_a?(Hash)
|
81
|
+
self::Merger.merge(hsh, h)
|
82
|
+
}
|
82
83
|
end
|
83
84
|
end
|
84
85
|
end
|
data/lib/config_plus/version.rb
CHANGED