yaml-ostruct 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/yaml/ostruct.rb CHANGED
@@ -4,8 +4,8 @@ require 'yaml/yaml_ostruct_impl'
4
4
  module YamlOstruct
5
5
  attr_reader :config
6
6
 
7
- def self.new
8
- YamlOstructImpl.new
7
+ def self.new(args = {})
8
+ YamlOstructImpl.new args
9
9
  end
10
10
 
11
11
  def self.clear
@@ -17,8 +17,13 @@ module YamlOstruct
17
17
  @config.send method_sym, *args
18
18
  end
19
19
 
20
- def self.load(dir, args = {})
20
+ def self.load(dir)
21
21
  @config ||= YamlOstructImpl.new
22
- @config.load(dir, args)
22
+ @config.load(dir)
23
+ end
24
+
25
+ def self.configure
26
+ @config ||= YamlOstructImpl.new
27
+ yield @config
23
28
  end
24
29
  end
data/lib/yaml/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # yaml-ostruct gem version
2
2
  module YamlOstruct
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
@@ -8,10 +8,13 @@ module YamlOstruct
8
8
  # YamlOstructImpl class
9
9
  class YamlOstructImpl
10
10
  attr_reader :config
11
- extend Gem::Deprecate
11
+ attr_accessor :omit_path
12
+ attr_accessor :deep_merge
12
13
 
13
- def initialize
14
+ def initialize(args = {})
14
15
  @config = OpenStruct.new
16
+ @omit_path = args.fetch :omit_path, false
17
+ @deep_merge = args.fetch :deep_merge, false
15
18
  end
16
19
 
17
20
  def method_missing(method_sym, *args)
@@ -26,18 +29,17 @@ module YamlOstruct
26
29
  end
27
30
  end
28
31
 
29
- def load(dir, args = {})
32
+ def load(dir)
30
33
  fail "Parameter #{File.join(Dir.pwd, dir)} is not a valid directory" unless File.directory? dir
31
34
 
32
- if args[:omit_path]
33
- load_omit_path(dir, @config, args)
35
+ if @omit_path
36
+ load_omit_path(dir, @config)
34
37
  else
35
- load_recursively(dir, @config)
38
+ load_recursively_with_path(dir, @config)
36
39
  end
37
40
  end
38
41
 
39
- def load_omit_path(dir, config, args)
40
- deep_merge = args.fetch :deep_merge, false
42
+ def load_omit_path(dir, config)
41
43
  fail "Parameter #{File.join(Dir.pwd, dir)} is not a valid directory" unless File.directory? dir
42
44
 
43
45
  Find.find(dir) do |yaml_file|
@@ -47,7 +49,7 @@ module YamlOstruct
47
49
  attr_name = File.basename(yaml_file, File.extname(yaml_file)).to_sym
48
50
  if config.respond_to?(attr_name)
49
51
  old_config = config.send(attr_name).to_hash
50
- new_config = if deep_merge
52
+ new_config = if @deep_merge
51
53
  new_config.deep_merge(old_config)
52
54
  else
53
55
  old_config.merge(new_config)
@@ -57,13 +59,13 @@ module YamlOstruct
57
59
  end
58
60
  end
59
61
 
60
- def load_recursively(dir, config)
62
+ def load_recursively_with_path(dir, config)
61
63
  files = Dir.entries(dir)
62
64
  files.each do |file_name|
63
65
  next if file_name.start_with?('.')
64
66
  if File.directory?("#{dir}/#{file_name}")
65
67
  new_config = OpenStruct.new
66
- config.send("#{file_name}=", load_recursively("#{dir}/#{file_name}", new_config))
68
+ config.send("#{file_name}=", load_recursively_with_path("#{dir}/#{file_name}", new_config))
67
69
  end
68
70
 
69
71
  extension = File.extname(file_name)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml-ostruct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-24 00:00:00.000000000 Z
12
+ date: 2016-06-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashugar