yaml-sugar 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/yaml-sugar/sugar.rb +32 -27
- data/lib/yaml-sugar/version.rb +1 -1
- data/lib/yaml-sugar/yaml-sugar.rb +2 -3
- metadata +14 -20
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab3bdfaef086854e51b7365a4fd127ce3437290f
|
4
|
+
data.tar.gz: 597894290c837ad6c0ad9dd2633bce7d447ead17
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66cac587de7d98edefd37dc81cc755fb74ccc2f299ce27879fe2a811f7b06555d6c9b0ea26773bb4fbcf4149157a9e9ee96a07877132c359ef77ee936ae8379d
|
7
|
+
data.tar.gz: d499cd15979a4c6c41797d910d5b7f91485e1a0a96e122b3b2ee8c4cea86e08df690d1eeb9563ed6d8826e647abbf4e7b45adf132602878b0676578ed772a0e7
|
data/lib/yaml-sugar/sugar.rb
CHANGED
@@ -8,42 +8,47 @@ require 'ostruct'
|
|
8
8
|
module YamlSugar
|
9
9
|
class Sugar
|
10
10
|
attr_reader :config
|
11
|
+
extend Gem::Deprecate
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
@config.send method_sym
|
15
|
-
else
|
16
|
-
super
|
13
|
+
def initialize
|
14
|
+
@config = OpenStruct.new
|
17
15
|
end
|
18
|
-
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
def method_missing(method_sym, *args)
|
18
|
+
if @config.respond_to? method_sym
|
19
|
+
@config.send method_sym, *args
|
20
|
+
elsif method_sym.to_s.end_with?('=')
|
21
|
+
@config.send method_sym, *args
|
22
|
+
else
|
23
|
+
nil
|
24
|
+
end
|
23
25
|
end
|
24
|
-
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def set(attr, value)
|
28
|
+
@config.send("#{attr.to_s}=", value)
|
29
|
+
end
|
30
|
+
deprecate :set, '.attr =', 2016, 9
|
31
|
+
|
32
|
+
def load(dir, args = {})
|
33
|
+
deep_merge = args.fetch :deep_merge, false
|
34
|
+
fail "Parameter #{File.join(Dir.pwd, dir)} is not a valid directory" unless File.directory? dir
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
new_config = YAML.load_file(yaml_file)
|
36
|
+
@yaml_files ||= []
|
37
|
+
Find.find(dir) do |yaml_file|
|
38
|
+
next unless yaml_file =~ /.*\.yml$/ or yaml_file =~ /.*\.yaml$/
|
39
|
+
new_config = YAML.load_file(yaml_file)
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
attr_name = File.basename(yaml_file, File.extname(yaml_file)).to_sym
|
42
|
+
if @config.respond_to?(attr_name)
|
43
|
+
old_config = @config.send(attr_name).to_hash
|
44
|
+
if deep_merge
|
45
|
+
new_config = new_config.deep_merge(old_config)
|
46
|
+
else
|
47
|
+
new_config = old_config.merge(new_config)
|
48
|
+
end
|
43
49
|
end
|
50
|
+
@config.send("#{attr_name}=", new_config.to_hashugar)
|
44
51
|
end
|
45
|
-
@config.send("#{attr_name}=", new_config.to_hashugar)
|
46
52
|
end
|
47
53
|
end
|
48
54
|
end
|
49
|
-
end
|
data/lib/yaml-sugar/version.rb
CHANGED
@@ -14,8 +14,8 @@ module YamlSugar
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# Define on self, since it's a module method
|
17
|
-
def self.method_missing(method_sym, *
|
18
|
-
@config.send method_sym, *
|
17
|
+
def self.method_missing(method_sym, *args)
|
18
|
+
@config.send method_sym, *args
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.load(dir, args = {})
|
@@ -23,4 +23,3 @@ module YamlSugar
|
|
23
23
|
@config.load(dir, args)
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml-sugar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.9
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Daniel Han
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2016-
|
11
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: hashugar
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: deep_merge
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '1.0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '1.0'
|
46
41
|
description: Read yaml files recursively from a given directory and return an OpenStruct
|
@@ -49,33 +44,32 @@ executables: []
|
|
49
44
|
extensions: []
|
50
45
|
extra_rdoc_files: []
|
51
46
|
files:
|
47
|
+
- lib/yaml-sugar.rb
|
52
48
|
- lib/yaml-sugar/sugar.rb
|
53
49
|
- lib/yaml-sugar/version.rb
|
54
50
|
- lib/yaml-sugar/yaml-sugar.rb
|
55
|
-
- lib/yaml-sugar.rb
|
56
51
|
homepage: https://github.com/hex0cter/yaml-sugar
|
57
52
|
licenses:
|
58
53
|
- MIT
|
54
|
+
metadata: {}
|
59
55
|
post_install_message:
|
60
56
|
rdoc_options: []
|
61
57
|
require_paths:
|
62
58
|
- lib
|
63
59
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
60
|
requirements:
|
66
|
-
- -
|
61
|
+
- - ">="
|
67
62
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
63
|
+
version: 1.9.3
|
69
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
65
|
requirements:
|
72
|
-
- -
|
66
|
+
- - ">="
|
73
67
|
- !ruby/object:Gem::Version
|
74
68
|
version: '0'
|
75
69
|
requirements: []
|
76
70
|
rubyforge_project:
|
77
|
-
rubygems_version:
|
71
|
+
rubygems_version: 2.5.1
|
78
72
|
signing_key:
|
79
|
-
specification_version:
|
80
|
-
summary: Read yaml into an OpenStruct
|
73
|
+
specification_version: 4
|
74
|
+
summary: Read yaml files into an OpenStruct
|
81
75
|
test_files: []
|