rbatch 2.5.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.ja.md CHANGED
@@ -373,7 +373,7 @@ Run-Conf(`${RB_HOME}/.rbatchrc`)のサンプルは以下の通り
373
373
 
374
374
  # ログを追記するかどうか
375
375
  #
376
- # デフォルト値はture
376
+ # デフォルト値はtrue
377
377
  #
378
378
  #log_append : true
379
379
  #log_append : false
data/README.md CHANGED
@@ -401,7 +401,7 @@ Sample of RBatch Run-Conf `${RB_HOME}/.rbatchrc`.
401
401
 
402
402
  # Append Log
403
403
  #
404
- # Default is ture.
404
+ # Default is true.
405
405
  #
406
406
  #log_append : true
407
407
  #log_append : false
data/bin/rbatch-init CHANGED
@@ -98,7 +98,7 @@ contents[".rbatchrc"] = <<EOF
98
98
 
99
99
  # Append Log
100
100
  #
101
- # Default is ture.
101
+ # Default is true.
102
102
  #
103
103
  #log_append : true
104
104
  #log_append : false
data/lib/rbatch/config.rb CHANGED
@@ -8,19 +8,19 @@ module RBatch
8
8
  @path
9
9
 
10
10
  # Actual data
11
- @hash
11
+ @element
12
12
 
13
13
  # @param [String] path Config file path
14
14
  def initialize(path,is_erb = false)
15
15
  @path = path
16
16
  begin
17
17
  if is_erb
18
- @hash = ConfigElement.new(YAML::load(ERB.new(IO.read(@path)).result))
18
+ @element = Config.parse(YAML::load(ERB.new(IO.read(@path)).result))
19
19
  else
20
- @hash = ConfigElement.new(YAML::load_file(@path))
20
+ @element = Config.parse(YAML::load_file(@path))
21
21
  end
22
22
  rescue Errno::ENOENT => e
23
- @hash = nil
23
+ @element = nil
24
24
  end
25
25
  end
26
26
 
@@ -28,10 +28,10 @@ module RBatch
28
28
  # @param [Object] key Config key.
29
29
  # @raise [RBatch::ConfigException]
30
30
  def[](key)
31
- if @hash.nil?
31
+ if @element.nil?
32
32
  raise RBatch::ConfigException, "Config file \"#{@path}\" does not exist"
33
33
  else
34
- @hash[key]
34
+ @element[key]
35
35
  end
36
36
  end
37
37
 
@@ -41,36 +41,51 @@ module RBatch
41
41
 
42
42
  # Config file exists or not
43
43
  # @return [Boolean]
44
- def exist? ; ! @hash.nil? ; end
44
+ def exist? ; ! @element.nil? ; end
45
45
 
46
46
  # @return [Hash]
47
47
  def to_h
48
- if @hash.nil?
48
+ if @element.nil?
49
49
  raise RBatch::ConfigException, "Config file \"#{@path}\" does not exist"
50
50
  else
51
- @hash
51
+ @element
52
52
  end
53
53
  end
54
54
 
55
55
  # @return [String]
56
56
  def to_s
57
- if @hash.nil?
57
+ if @element.nil?
58
58
  raise RBatch::ConfigException, "Config file \"#{@path}\" does not exist"
59
59
  else
60
- @hash.to_s
60
+ @element.to_s
61
61
  end
62
62
  end
63
- end
64
63
 
65
- class ConfigElement < Hash
64
+ # @return ConfigElementArray or ConfigElementHash
65
+ def Config.parse(yaml)
66
+ if yaml.class == Hash
67
+ return ConfigElementHash.new(yaml)
68
+ elsif yaml.class == Array
69
+ return ConfigElementArray.new(yaml)
70
+ else
71
+ return yaml
72
+ end
73
+ end
74
+ end
75
+
76
+ class ConfigElementArray < Array
77
+ def initialize(array)
78
+ array.each_with_index do |item,index|
79
+ self[index] = Config.parse(item)
80
+ end
81
+ end
82
+ end
83
+
84
+ class ConfigElementHash < Hash
66
85
  def initialize(hash)
67
86
  if hash
68
87
  hash.each_key do |key|
69
- if hash[key].class == Hash
70
- self[key] = ConfigElement.new(hash[key])
71
- else
72
- self[key] = hash[key]
73
- end
88
+ self[key] = Config.parse(hash[key])
74
89
  end
75
90
  end
76
91
  end
@@ -1,3 +1,3 @@
1
1
  module RBatch
2
- VERSION = "2.5.0"
2
+ VERSION = "2.5.1"
3
3
  end
data/sample/.rbatchrc CHANGED
@@ -95,7 +95,7 @@
95
95
 
96
96
  # Append Log
97
97
  #
98
- # Default is ture.
98
+ # Default is true.
99
99
  #
100
100
  #log_append : true
101
101
  #log_append : false
@@ -77,8 +77,8 @@ describe RBatch::Config do
77
77
 
78
78
  end
79
79
 
80
- describe RBatch::ConfigElement do
81
- it "" do
80
+ describe "RBatch::Config.parse" do
81
+ it "parses hash" do
82
82
  hash = {
83
83
  "a" => "av" ,
84
84
  "b" => {
@@ -89,11 +89,11 @@ describe RBatch::ConfigElement do
89
89
  }
90
90
  }
91
91
  }
92
- ce = RBatch::ConfigElement.new(hash)
92
+ ce = RBatch::Config.parse(hash)
93
93
  expect(ce["a"]).to eq "av"
94
- expect(ce["b"].class).to eq RBatch::ConfigElement
94
+ expect(ce["b"].class).to eq RBatch::ConfigElementHash
95
95
  expect(ce["b"]["c"]).to eq "cv"
96
- expect(ce["b"]["d"].class).to eq RBatch::ConfigElement
96
+ expect(ce["b"]["d"].class).to eq RBatch::ConfigElementHash
97
97
  expect(ce["b"]["d"]["e"]).to eq "ev"
98
98
  expect(ce["b"]["d"]["f"][1]).to eq 2
99
99
  expect { ce["noexist"] }.to raise_error(RBatch::ConfigException)
@@ -101,4 +101,23 @@ describe RBatch::ConfigElement do
101
101
  expect { ce["b"]["noexist"] }.to raise_error(RBatch::ConfigException)
102
102
  expect { ce["b"]["d"]["noexist"] }.to raise_error(RBatch::ConfigException)
103
103
  end
104
+
105
+ it "parses array" do
106
+ array = [
107
+ "a",
108
+ [ "b", "c" ],
109
+ { "d" => "dv" , "e" => "ev" },
110
+ [ "f",["g","h","i"]]
111
+ ]
112
+ ce = RBatch::Config.parse(array)
113
+ expect(ce.class).to eq RBatch::ConfigElementArray
114
+ expect(ce[0]).to eq "a"
115
+ expect(ce[1].class).to eq RBatch::ConfigElementArray
116
+ expect(ce[1][0]).to eq "b"
117
+ expect(ce[1][1]).to eq "c"
118
+ expect(ce[2].class).to eq RBatch::ConfigElementHash
119
+ expect(ce[2]["d"]).to eq "dv"
120
+ expect { ce[2]["z"] }.to raise_error(RBatch::ConfigException)
121
+ expect(ce[3][1][1]).to eq "h"
122
+ end
104
123
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rbatch
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.5.0
5
+ version: 2.5.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - fetaro
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2015-06-13 00:00:00 Z
13
+ date: 2015-06-17 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: Batch Script Framework