config-hash 0.9.0 → 1.0.0

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
  SHA256:
3
- metadata.gz: d402199a83e315a08c1ec966be61cacd3c611ad159266a9e5302694fe431f986
4
- data.tar.gz: 8456cec67ff0dc3b0a7700dbb7d0765334068c8392a836aff9c6d0a3f626e92f
3
+ metadata.gz: 18cc65d997214d22026cd64bd4a4a648e943d0f5aabe62e25633d583e8c1426c
4
+ data.tar.gz: 9b8de42e1c7428a97aae9e82338dd0e6dd00c23995d0078ca5be05d6d4d87213
5
5
  SHA512:
6
- metadata.gz: 46202cd059c38067fed89a376c5db4dedf8a03329df78cfcfabfec930f80bbd810771fdbec14280ff868c932b6b589c9be11065f7ee4503fcb8276ecf109579c
7
- data.tar.gz: f77bf4bd20d790219cee22b6beb84ef72b4f649c3a5afe2abf9eac20a24696b5aa96188bfa98ff9347535c3789453f8e8e07fc0b8c16782f4872b53b8191e8a0
6
+ metadata.gz: fc9e93f97ad627f5ba663d444c35cf3266e0351d1fb5dedf01fe26912e26d0773368d80f6677f474e69905930f1f6d65fe978579840b2f0dbb20f566ada7157f
7
+ data.tar.gz: d612503adbdc102de8a4a81e2d60c45dca4ab8f21c997384b65263f0dee9cd7e4894d93f3dcbe9feb2f0ae5c6116c0906e44e962e42391cee364c112a3721245
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5
1
+ 2.6.5
data/config-hash.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "config-hash"
5
- s.version = "0.9.0"
5
+ s.version = "1.0.0"
6
6
  s.author = "Steve Shreeve"
7
7
  s.email = "steve.shreeve@gmail.com"
8
8
  s.summary = "A safe, homoiconic, Ruby hash supporting dot notation"
data/lib/config-hash.rb CHANGED
@@ -3,32 +3,25 @@ class Hash
3
3
  def +@; ConfigHash[self]; end
4
4
  end
5
5
 
6
- class Array
7
- def keys
8
- +Hash[zip]
9
- end
10
- end
11
-
12
6
  class NormalHash < Hash
13
7
  end
14
8
 
15
9
  class ConfigHash < Hash
16
10
  SEPARATORS ||= %r|[./]|
17
11
 
18
- # remove likely collisions
19
- undef_method :zip
20
-
21
12
  def self.[](hash=nil)
22
13
  new(hash)
23
14
  end
24
15
 
25
- def self.load(path="config.rb", var="config")
16
+ def self.load(path="config.rb", list=nil, name: "config")
26
17
  path = File.expand_path(path)
27
- eval <<-"end", binding, path, 0
28
- #{var} ||= new
29
- #{IO.read(path, encoding: 'utf-8') if File.exists?(path)}
30
- #{var}
18
+ data = eval <<~"end", binding, path, 0
19
+ #{name} ||= new
20
+ #{IO.read(path, encoding: 'utf-8') if File.readable?(path)}
21
+ #{name}
31
22
  end
23
+ data.load(*list) if list && !list.empty?
24
+ data
32
25
  end
33
26
 
34
27
  def initialize(hash=nil)
@@ -36,21 +29,21 @@ class ConfigHash < Hash
36
29
  update(hash) if hash
37
30
  end
38
31
 
39
- def import(root, glob)
40
- root = File.expand_path(root)
41
- pref = root.size + 1
42
- Dir[File.join(root, glob)].each do |path|
43
- keys = File.dirname(path[pref..-1])
44
- data = ConfigHash.load(path)
45
- self[keys] = data
32
+ def load(*list)
33
+ [list].each do |root, glob|
34
+ root = File.expand_path(root)
35
+ pref = root.size + 1
36
+ full = File.join([root, glob].compact)
37
+ list = Dir[full].sort {|a,b| [a.count('/'), a] <=> [b.count('/'), b]}
38
+ list.each do |path|
39
+ info = File.dirname(path[pref...] || '')
40
+ data = ConfigHash.load(path)
41
+ info == '.' ? update(data) : (self[info] = data)
42
+ end
46
43
  end
47
44
  self
48
45
  end
49
46
 
50
- def zip!(*args)
51
- +Hash[keys.zip(*args)]
52
- end
53
-
54
47
  def key?(key)
55
48
  super(key.to_s)
56
49
  end
@@ -88,15 +81,16 @@ class ConfigHash < Hash
88
81
  end
89
82
  end
90
83
 
91
- alias_method :store, :[]=
92
-
93
- def update(hash)
84
+ def update(hash, nuke=false)
94
85
  raise ArgumentError unless Hash === hash
86
+ clear if nuke
95
87
  hash.each {|key, val| self[key] = val}
96
88
  self
97
89
  end
98
90
 
99
- alias_method :merge!, :update
91
+ def update!(hash)
92
+ update(hash, true)
93
+ end
100
94
 
101
95
  def to_hash
102
96
  Hash[self]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config-hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-01 00:00:00.000000000 Z
11
+ date: 2021-04-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This gem makes it easy to work with configuration data.
14
14
  email: steve.shreeve@gmail.com
@@ -26,7 +26,7 @@ homepage: https://github.com/shreeve/config-hash
26
26
  licenses:
27
27
  - MIT
28
28
  metadata: {}
29
- post_install_message:
29
+ post_install_message:
30
30
  rdoc_options: []
31
31
  require_paths:
32
32
  - lib
@@ -41,9 +41,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  requirements: []
44
- rubyforge_project:
45
- rubygems_version: 2.7.7
46
- signing_key:
44
+ rubygems_version: 3.2.16
45
+ signing_key:
47
46
  specification_version: 4
48
47
  summary: A safe, homoiconic, Ruby hash supporting dot notation
49
48
  test_files: []