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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 599e3bd010d176091ffe984b74c85369558386fe
4
- data.tar.gz: b558ba580faf0701f777d0003c3757a113c84ac1
3
+ metadata.gz: 93199817135b965a48712d1c659c03c93f6cd27b
4
+ data.tar.gz: b6f9ddced4e4e05a876b4d78aafa6552b5589b2e
5
5
  SHA512:
6
- metadata.gz: 121668b57e69c4119f6a3e267f88215f12c779983d7712b2980e11cfafc18bc32b2af02177a03f6e485b1aba8456f4b2263c1a66ac9f9f26772fffb9e8bb0177
7
- data.tar.gz: 66ca9d59b7b6db91ba7c57f75904071af8fd584f20c80b8342fba905bbeb5febacf304f169122ef3aa49609ce7db4fd2574f8ea951ff74a2d9ff62dceef59fcb
6
+ metadata.gz: 49e59f9dc8bd1b3a5cd5d3ba14cc07eba8a3e38154d71198a37f95f7a3744a1e8cb874f93bd39c68e47f20f4fa776789290aff56486380d31694385b836ab1fe
7
+ data.tar.gz: 594a37efbd171daf932e102f021abde34b221a31ddcf5b6b5baf6cc70a58298a76d52edbcd0b635aecf187eeb810bb5e8b26d50649d4bbb0479ec4c6b634cfaa
@@ -4,17 +4,16 @@ module ConfigPlus
4
4
 
5
5
  # Sets up configuration of ++ConfigPlus++ and loads data
6
6
  #
7
- # When a YAML file path is specified with
8
- # ++source++ (or ++root_dir++) setting as below,
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 is specified, configuration
16
- # would be loaded from all YAML files under the
17
- # specified directory.
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 ||= ::ConfigPlus::Config.new
58
+ @config ||= self::Config.new
44
59
  end
45
60
 
46
61
  private
47
62
 
48
- # loads a configuration data as a hash object
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 = ::ConfigPlus::Node.new(hash)
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
- inheritance = base.ancestors.select {|klass|
66
- klass != base and
67
- klass != ConfigPlus and
68
- klass.ancestors.include?(ConfigPlus)
69
- }.reverse.each.inject({}) {|hsh, klass|
70
- h = klass.public_send(method_name)
71
- h = helper.config_for(klass, ::ConfigPlus.root) unless
72
- h or h.is_a?(Hash)
73
- Merger.merge(hsh, h)
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
@@ -1,3 +1,3 @@
1
1
  module ConfigPlus
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - m4oda