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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab3bdfaef086854e51b7365a4fd127ce3437290f
4
- data.tar.gz: 597894290c837ad6c0ad9dd2633bce7d447ead17
3
+ metadata.gz: 6ab33f42fda682e83aecf1447da5d556a0409e1a
4
+ data.tar.gz: 0655b7c8102e42e0823871e9bd003afa0299b2e6
5
5
  SHA512:
6
- metadata.gz: 66cac587de7d98edefd37dc81cc755fb74ccc2f299ce27879fe2a811f7b06555d6c9b0ea26773bb4fbcf4149157a9e9ee96a07877132c359ef77ee936ae8379d
7
- data.tar.gz: d499cd15979a4c6c41797d910d5b7f91485e1a0a96e122b3b2ee8c4cea86e08df690d1eeb9563ed6d8826e647abbf4e7b45adf132602878b0676578ed772a0e7
6
+ metadata.gz: 4bd840e4daa6dbbe60887c801dfde4356ed8a0f5f566c2dab9ef4cdce7c7d971034950497d5a2b2914ea2e3284412c6e0bb372241747ee7b5a9fff544c332b77
7
+ data.tar.gz: 46d8455c7787ee299f29c71ed2fe0a72816a07ceab2bdceaca57c35a80566e55e7a7ebd0dd6aa208d061c86a305c81c176213b918c34f931b314b699c1ae71dc
@@ -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 Sugar
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.to_s}=", value)
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
- new_config = new_config.deep_merge(old_config)
46
- else
47
- new_config = old_config.merge(new_config)
48
- end
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
@@ -1,4 +1,4 @@
1
1
  # yaml-sugar gem version
2
2
  module YamlSugar
3
- VERSION = '0.0.9'
3
+ VERSION = '1.0'
4
4
  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: 0.0.9
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-sugar.rb
48
- - lib/yaml-sugar/sugar.rb
49
- - lib/yaml-sugar/version.rb
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
@@ -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