yaml-sugar 0.0.9 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yaml/sugar.rb +24 -0
- data/lib/{yaml-sugar/sugar.rb → yaml/sugar_impl.rb} +12 -11
- data/lib/{yaml-sugar → yaml}/version.rb +1 -1
- metadata +4 -5
- data/lib/yaml-sugar.rb +0 -1
- data/lib/yaml-sugar/yaml-sugar.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ab33f42fda682e83aecf1447da5d556a0409e1a
|
4
|
+
data.tar.gz: 0655b7c8102e42e0823871e9bd003afa0299b2e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bd840e4daa6dbbe60887c801dfde4356ed8a0f5f566c2dab9ef4cdce7c7d971034950497d5a2b2914ea2e3284412c6e0bb372241747ee7b5a9fff544c332b77
|
7
|
+
data.tar.gz: 46d8455c7787ee299f29c71ed2fe0a72816a07ceab2bdceaca57c35a80566e55e7a7ebd0dd6aa208d061c86a305c81c176213b918c34f931b314b699c1ae71dc
|
data/lib/yaml/sugar.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'yaml/sugar_impl'
|
2
|
+
|
3
|
+
# YamlSugar module
|
4
|
+
module YamlSugar
|
5
|
+
attr_reader :config
|
6
|
+
|
7
|
+
def self.new
|
8
|
+
SugarImpl.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.clear
|
12
|
+
@config = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.method_missing(method_sym, *args)
|
16
|
+
@config ||= SugarImpl.new
|
17
|
+
@config.send method_sym, *args
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.load(dir, args = {})
|
21
|
+
@config ||= SugarImpl.new
|
22
|
+
@config.load(dir, args)
|
23
|
+
end
|
24
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require 'deep_merge'
|
2
1
|
require 'find'
|
3
|
-
require 'hashugar'
|
4
2
|
require 'yaml'
|
5
3
|
require 'ostruct'
|
4
|
+
require 'hashugar'
|
5
|
+
require 'deep_merge'
|
6
6
|
|
7
|
-
# YamlSugar class
|
8
7
|
module YamlSugar
|
9
|
-
class
|
8
|
+
# SugarImpl class
|
9
|
+
class SugarImpl
|
10
10
|
attr_reader :config
|
11
11
|
extend Gem::Deprecate
|
12
12
|
|
@@ -19,15 +19,16 @@ module YamlSugar
|
|
19
19
|
@config.send method_sym, *args
|
20
20
|
elsif method_sym.to_s.end_with?('=')
|
21
21
|
@config.send method_sym, *args
|
22
|
+
elsif method_sym == :clear
|
23
|
+
@config = OpenStruct.new
|
22
24
|
else
|
23
25
|
nil
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
29
|
def set(attr, value)
|
28
|
-
@config.send("#{attr
|
30
|
+
@config.send("#{attr}=", value)
|
29
31
|
end
|
30
|
-
deprecate :set, '.attr =', 2016, 9
|
31
32
|
|
32
33
|
def load(dir, args = {})
|
33
34
|
deep_merge = args.fetch :deep_merge, false
|
@@ -41,11 +42,11 @@ module YamlSugar
|
|
41
42
|
attr_name = File.basename(yaml_file, File.extname(yaml_file)).to_sym
|
42
43
|
if @config.respond_to?(attr_name)
|
43
44
|
old_config = @config.send(attr_name).to_hash
|
44
|
-
if deep_merge
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
new_config = if deep_merge
|
46
|
+
new_config.deep_merge(old_config)
|
47
|
+
else
|
48
|
+
old_config.merge(new_config)
|
49
|
+
end
|
49
50
|
end
|
50
51
|
@config.send("#{attr_name}=", new_config.to_hashugar)
|
51
52
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml-sugar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '1.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Han
|
@@ -44,10 +44,9 @@ executables: []
|
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
-
- lib/yaml
|
48
|
-
- lib/yaml
|
49
|
-
- lib/yaml
|
50
|
-
- lib/yaml-sugar/yaml-sugar.rb
|
47
|
+
- lib/yaml/sugar.rb
|
48
|
+
- lib/yaml/sugar_impl.rb
|
49
|
+
- lib/yaml/version.rb
|
51
50
|
homepage: https://github.com/hex0cter/yaml-sugar
|
52
51
|
licenses:
|
53
52
|
- MIT
|
data/lib/yaml-sugar.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'yaml-sugar/yaml-sugar'
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'deep_merge'
|
2
|
-
require 'find'
|
3
|
-
require 'hashugar'
|
4
|
-
require 'yaml'
|
5
|
-
require 'ostruct'
|
6
|
-
require 'yaml-sugar/sugar'
|
7
|
-
|
8
|
-
# YamlSugar module
|
9
|
-
module YamlSugar
|
10
|
-
attr_reader :config
|
11
|
-
|
12
|
-
def self.new
|
13
|
-
Sugar.new
|
14
|
-
end
|
15
|
-
|
16
|
-
# Define on self, since it's a module method
|
17
|
-
def self.method_missing(method_sym, *args)
|
18
|
-
@config.send method_sym, *args
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.load(dir, args = {})
|
22
|
-
@config ||= Sugar.new
|
23
|
-
@config.load(dir, args)
|
24
|
-
end
|
25
|
-
end
|