rbatch 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/rbatch/config.rb +23 -7
  3. metadata +2 -2
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'rake/testtask'
7
7
 
8
8
  spec = Gem::Specification.new do |s|
9
9
  s.name = 'rbatch'
10
- s.version = '1.5.1'
10
+ s.version = '1.6.0'
11
11
  s.extra_rdoc_files = ['README.md', 'LICENSE']
12
12
  s.summary = 'batch framework'
13
13
  s.description = ''
data/lib/rbatch/config.rb CHANGED
@@ -5,11 +5,14 @@ module RBatch
5
5
 
6
6
  module_function
7
7
 
8
+ # Alias of RBatch::Config.new
9
+ def config ; Config.new end
10
+
8
11
  # Read config file and return hash opject.
9
12
  #
10
- # Default config file path is "../config/(Program name).yaml"
13
+ # Default config file path is "../conf/(Program Base name).yaml"
11
14
  # ==== Sample
12
- # config : ./config/sample2.yaml
15
+ # config : ./conf/sample2.yaml
13
16
  # key: value
14
17
  # array:
15
18
  # - item1
@@ -17,13 +20,26 @@ module RBatch
17
20
  # - item3
18
21
  # script : ./bin/sample2.rb
19
22
  # require 'rbatch'
20
- # p RBatch::config
23
+ # p RBatch::Config.new
24
+ # # or p RBatch::config
21
25
  # => {"key" => "value", "array" => ["item1", "item2", "item3"]}
22
- def config
23
- file = Pathname(File.basename(RBatch.program_name)).sub_ext(".yaml").to_s
24
- dir = File.join(File.join(File.dirname(RBatch.program_name),".."),"conf")
25
- return YAML::load_file(File.join(dir,file))
26
+ class Config
27
+ @path
28
+ @config
29
+ def initialize
30
+ file = Pathname(File.basename(RBatch.program_name)).sub_ext(".yaml").to_s
31
+ dir = File.join(File.join(File.dirname(RBatch.program_name),".."),"conf")
32
+ @path = File.join(dir,file)
33
+ @config = YAML::load_file(@path)
34
+ end
35
+ def[](key)
36
+ raise RBatch::Config::Exception, "Value of key=\"#{key}\" is nil" if @config[key].nil?
37
+ @config[key]
38
+ end
39
+ def path ; @path ; end
40
+ def to_s ; @config.to_s ;end
26
41
  end
27
42
 
43
+ class RBatch::Config::Exception < Exception; end
28
44
  end
29
45
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rbatch
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.5.1
5
+ version: 1.6.0
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: 2013-01-11 00:00:00 Z
13
+ date: 2013-01-14 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: ""