data_reader 1.0.2 → 1.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: a8f2497b2d64abf0036c3a8e7a91d276b00b6328
4
- data.tar.gz: aa6ed30aa2fbb6d7a98521ab78bb863970038060
3
+ metadata.gz: f73829d7eaf46a4dba02827cbe1c13255e6316bc
4
+ data.tar.gz: 3f21945b2bd955f00a6ca318930c9d6e28f0300f
5
5
  SHA512:
6
- metadata.gz: bc142680fa2d7da4ebbdd28182d88ca593b1280b06b9fdccad2411d4eba1fd8708edde7663351ce780b5d17fbf89929ff01afe7faaff2d66d3ecd95b70a338ea
7
- data.tar.gz: 6b214e2cd16ae778b0d87c67eaa826432b512eccd9234807b2c6d96c9c675d3480f00cfc52e68ad18000e1ec1b9f7d7bd80048e4759ee3589f4a7a434bb25658
6
+ metadata.gz: f73e7f233816684826fb5d22f5c1138b2e9ea4733f4f69c0852b3a653433a776ec508636cef0b1e05ec572fa7227dfe4298601488fca1bbf925eed4d07f0e71e
7
+ data.tar.gz: 69d0030724241ad7fcd2489d1604e872d18a0841470a24d3f8e5b4c36b49063725a5cc17493a2ca0a5814c5afeae1d4286ce8334e3642bd95b83d597a1d755e2
data/.hound.yml CHANGED
@@ -55,7 +55,7 @@ Metrics/BlockNesting:
55
55
 
56
56
  # Encourage short methods.
57
57
  Metrics/MethodLength:
58
- Max: 10
58
+ Max: 12
59
59
 
60
60
  # Encourage fewer parameters.
61
61
  Metrics/ParameterLists:
@@ -1,3 +1,3 @@
1
1
  module DataReader
2
- VERSION = "1.0.2".freeze
2
+ VERSION = "1.1.0".freeze
3
3
  end
data/lib/data_reader.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "data_reader/version"
2
+ require "pathname"
2
3
  require "yaml"
3
4
  require "erb"
4
5
 
@@ -10,25 +11,49 @@ module DataReader
10
11
  def data_path
11
12
  return @data_path if @data_path
12
13
  return default_data_path if respond_to? :default_data_path
14
+
13
15
  nil
14
16
  end
15
17
 
16
18
  def data_source
17
19
  return @data_source if @data_source
20
+
18
21
  nil
19
22
  end
20
23
 
21
24
  def load(file_list)
22
25
  files = file_list.include?(',') ? file_list.split(',') : [file_list]
23
26
  files = files.collect(&:strip)
24
- @data_source = files.inject({}) do |data, file|
25
- data.merge!(YAML.safe_load(
26
- ERB.new(File.read("#{data_path}/#{file}")).result(binding)
27
- ))
27
+
28
+ @data_source = files.inject({}) do |all_data, file|
29
+ data = include_key(::YAML.safe_load(include_data(file)))
30
+ all_data.merge!(data) if data
28
31
  end
29
32
  end
30
33
 
31
- def include_data(filename)
32
- ERB.new(IO.read("#{data_path}/#{filename}")).result
34
+ def include_data(file)
35
+ filename = Pathname.new(file).absolute? ? file : "#{@data_path}/#{file}"
36
+ ERB.new(IO.read(filename)).result(binding) if File.exist?(filename)
37
+ end
38
+
39
+ private
40
+
41
+ def include_key(data)
42
+ include_data = {}
43
+
44
+ if data.key?('_include_')
45
+ [data['_include_']].flatten.each do |file_path|
46
+ include_data.merge!(load(file_path))
47
+ end
48
+ end
49
+
50
+ data.delete('_include_')
51
+ data.merge!(include_data)
52
+
53
+ data.each do |key, value|
54
+ data[key] = include_key(value) if value.is_a?(Hash)
55
+ end
56
+
57
+ data
33
58
  end
34
59
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_reader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Nyman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-05 00:00:00.000000000 Z
11
+ date: 2018-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -107,7 +107,7 @@ licenses:
107
107
  - MIT
108
108
  metadata: {}
109
109
  post_install_message: "\n(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)\n
110
- \ DataReader 1.0.2 has been installed.\n(::) (::) (::) (::) (::) (::) (::) (::)
110
+ \ DataReader 1.1.0 has been installed.\n(::) (::) (::) (::) (::) (::) (::) (::)
111
111
  (::) (::) (::) (::)\n "
112
112
  rdoc_options: []
113
113
  require_paths:
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  requirements: []
126
126
  rubyforge_project:
127
- rubygems_version: 2.6.13
127
+ rubygems_version: 2.5.2.2
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: Provides a standard method for reading YAML data files