libis-tools 0.9.7 → 0.9.9

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: 1e717837dc7e2b3f0549cf1b6abf6ca1240f1344
4
- data.tar.gz: 8310be003731268e303dd930279638d61b6a5edf
3
+ metadata.gz: f35282647506db8de43d2a9963bd3aabaa944788
4
+ data.tar.gz: 476b0593171ce67aec1e15a33d75e5e72751b2fa
5
5
  SHA512:
6
- metadata.gz: 8fce8638e6fc55803704fda53975fedce79a0ed127c2c8e2cf7dd8b989e6d87af001a56205d1091865764c5fa99dc864dd473dd23df637b24e305f29d49d8df0
7
- data.tar.gz: 8b8f8b6b0af625240709d68fd48ea75003c7fe8dbf460cdaecd4d67d6f8a2a19a9aad07daae54ab9602237769ec118807eeb6d92107b34c64d48fcb9af15ad48
6
+ metadata.gz: aa6158973c7ac9f8a1ef9fc1bfa5406bcb0cce7651592488ede57a245c4a3e9e04ec8eb89f14e194d58e00cc3f025896238c98d495ca609d8f17acc6556fe2ac
7
+ data.tar.gz: e11e56b324b2a3e58e27f8ac5770b383246cec7c09af4800ddb61e6385d95b433bc1608c54a4a83606d701ab272991e3fb421f4032e0a77ebd7b29b7bb7ed0a0
@@ -73,7 +73,7 @@ module Libis
73
73
 
74
74
  # Clear all data.
75
75
  #
76
- # Not only all configuration parameters are deleted, but also the memoirized list of loaded files
76
+ # Not only all configuration parameters are deleted, but also the memorized list of loaded files
77
77
  # and hashes are cleared and the logger configuration is reset to it's default status.
78
78
  def clear!
79
79
  super
@@ -46,8 +46,8 @@ module Libis
46
46
  # derived classes such as ::Libis::Tools::Config.
47
47
  #
48
48
  # @param [String,Hash] file_or_hash optional String or Hash argument to initialize the data.
49
- def <<(file_or_hash)
50
- _file_to_hash(file_or_hash).each { |key, value| self[key] = value }
49
+ def <<(file_or_hash, &block)
50
+ _file_to_hash(file_or_hash, &block).each { |key, value| self[key] = value }
51
51
  self
52
52
  end
53
53
 
@@ -139,7 +139,9 @@ module Libis
139
139
  parameters[name] = Parameter.new(name, default) if parameters[name].nil?
140
140
  options.each { |key, value| parameters[name][key] = value if value }
141
141
  else
142
- parameters[options]
142
+ param_def = parameters[options]
143
+ return param_def unless param_def.nil?
144
+ self.superclass.parameter(options) rescue nil
143
145
  end
144
146
  end
145
147
 
@@ -1,5 +1,5 @@
1
1
  module Libis
2
2
  module Tools
3
- VERSION = '0.9.7'
3
+ VERSION = '0.9.9'
4
4
  end
5
5
  end
@@ -4,26 +4,33 @@ require 'libis/tools/parameter'
4
4
 
5
5
  describe 'ParameterContainer' do
6
6
 
7
- before :context do
8
- class TestContainer
9
- include ::Libis::Tools::ParameterContainer
10
-
11
- parameter check: true
12
- parameter count: 0
13
- parameter price: 1.0
14
- parameter name: 'nobody'
15
- parameter calendar: Date.new(2014, 01, 01)
16
- parameter clock: Time.parse('10:10')
17
- parameter timestamp: DateTime.new(2014, 01, 01, 10, 10)
18
- parameter with_options: true, options: {a: 1, b: 2}, c: 3
7
+ class TestContainer
8
+ include ::Libis::Tools::ParameterContainer
9
+
10
+ parameter check: true
11
+ parameter count: 0
12
+ parameter price: 1.0
13
+ parameter name: 'nobody'
14
+ parameter calendar: Date.new(2014, 01, 01)
15
+ parameter clock: Time.parse('10:10')
16
+ parameter timestamp: DateTime.new(2014, 01, 01, 10, 10)
17
+ parameter with_options: true, options: {a: 1, b: 2}, c: 3
19
18
 
20
- end
21
19
  end
22
20
 
23
- before :example do
24
- @test_container = TestContainer.new
21
+ class DerivedContainer < TestContainer
22
+ parameter name: 'somebody'
23
+ parameter check: 'yes'
25
24
  end
26
25
 
26
+ class DerivedDerivedContainer < DerivedContainer; end
27
+ class DerivedDerivedDerivedContainer < DerivedDerivedContainer; end
28
+
29
+ let(:test_container) { TestContainer.new }
30
+ let(:derived_container) { DerivedContainer.new }
31
+ let(:derived_derived_container) { DerivedDerivedContainer.new }
32
+ let(:derived_derived_derived_container) { DerivedDerivedDerivedContainer.new }
33
+
27
34
  it 'class should return parameter if only name is given' do
28
35
  [:check, :count, :price, :name, :calendar, :clock, :timestamp].each do |v|
29
36
  expect(TestContainer.parameter(v)).to be_a ::Libis::Tools::Parameter
@@ -31,62 +38,75 @@ describe 'ParameterContainer' do
31
38
  end
32
39
 
33
40
  it 'should have default parameters' do
34
- expect(@test_container.parameter(:check)).to be_truthy
35
- expect(@test_container.parameter(:count)).to eq 0
36
- expect(@test_container.parameter(:price)).to eq 1.0
37
- expect(@test_container.parameter(:name)).to eq 'nobody'
38
- expect(@test_container.parameter(:calendar).year).to eq 2014
39
- expect(@test_container.parameter(:calendar).month).to eq 1
40
- expect(@test_container.parameter(:calendar).day).to eq 1
41
- expect(@test_container.parameter(:clock).hour).to eq 10
42
- expect(@test_container.parameter(:clock).min).to eq 10
43
- expect(@test_container.parameter(:clock).sec).to eq 0
44
- expect(@test_container.parameter(:timestamp).year).to eq 2014
45
- expect(@test_container.parameter(:timestamp).month).to eq 1
46
- expect(@test_container.parameter(:timestamp).day).to eq 1
47
- expect(@test_container.parameter(:timestamp).hour).to eq 10
48
- expect(@test_container.parameter(:timestamp).min).to eq 10
49
- expect(@test_container.parameter(:timestamp).sec).to eq 0
41
+ expect(test_container.parameter(:check)).to be_truthy
42
+ expect(test_container.parameter(:count)).to eq 0
43
+ expect(test_container.parameter(:price)).to eq 1.0
44
+ expect(test_container.parameter(:name)).to eq 'nobody'
45
+ expect(test_container.parameter(:calendar).year).to eq 2014
46
+ expect(test_container.parameter(:calendar).month).to eq 1
47
+ expect(test_container.parameter(:calendar).day).to eq 1
48
+ expect(test_container.parameter(:clock).hour).to eq 10
49
+ expect(test_container.parameter(:clock).min).to eq 10
50
+ expect(test_container.parameter(:clock).sec).to eq 0
51
+ expect(test_container.parameter(:timestamp).year).to eq 2014
52
+ expect(test_container.parameter(:timestamp).month).to eq 1
53
+ expect(test_container.parameter(:timestamp).day).to eq 1
54
+ expect(test_container.parameter(:timestamp).hour).to eq 10
55
+ expect(test_container.parameter(:timestamp).min).to eq 10
56
+ expect(test_container.parameter(:timestamp).sec).to eq 0
50
57
  end
51
58
 
52
59
  it 'should allow to set values' do
53
- @test_container.parameter(:check, false)
54
- expect(@test_container.parameter(:check)).to be_falsey
55
-
56
- @test_container.parameter(:count, 99)
57
- expect(@test_container.parameter(:count)).to eq 99
58
-
59
- @test_container.parameter(:price, 99.99)
60
- expect(@test_container.parameter(:price)).to eq 99.99
61
-
62
- @test_container.parameter(:name, 'everybody')
63
- expect(@test_container.parameter(:name)).to eq 'everybody'
64
-
65
- @test_container.parameter(:calendar, Date.new(2015, 02, 03))
66
- expect(@test_container.parameter(:calendar).year).to eq 2015
67
- expect(@test_container.parameter(:calendar).month).to eq 2
68
- expect(@test_container.parameter(:calendar).day).to eq 3
69
-
70
- @test_container.parameter(:clock, Time.parse('14:40:23'))
71
- expect(@test_container.parameter(:clock).hour).to eq 14
72
- expect(@test_container.parameter(:clock).min).to eq 40
73
- expect(@test_container.parameter(:clock).sec).to eq 23
74
-
75
- @test_container.parameter(:timestamp, DateTime.new(2015, 02, 03, 14, 40, 23))
76
- expect(@test_container.parameter(:timestamp).year).to eq 2015
77
- expect(@test_container.parameter(:timestamp).month).to eq 2
78
- expect(@test_container.parameter(:timestamp).day).to eq 3
79
- expect(@test_container.parameter(:timestamp).hour).to eq 14
80
- expect(@test_container.parameter(:timestamp).min).to eq 40
81
- expect(@test_container.parameter(:timestamp).sec).to eq 23
60
+ test_container.parameter(:check, false)
61
+ expect(test_container.parameter(:check)).to be_falsey
62
+
63
+ test_container.parameter(:count, 99)
64
+ expect(test_container.parameter(:count)).to eq 99
65
+
66
+ test_container.parameter(:price, 99.99)
67
+ expect(test_container.parameter(:price)).to eq 99.99
68
+
69
+ test_container.parameter(:name, 'everybody')
70
+ expect(test_container.parameter(:name)).to eq 'everybody'
71
+
72
+ test_container.parameter(:calendar, Date.new(2015, 02, 03))
73
+ expect(test_container.parameter(:calendar).year).to eq 2015
74
+ expect(test_container.parameter(:calendar).month).to eq 2
75
+ expect(test_container.parameter(:calendar).day).to eq 3
76
+
77
+ test_container.parameter(:clock, Time.parse('14:40:23'))
78
+ expect(test_container.parameter(:clock).hour).to eq 14
79
+ expect(test_container.parameter(:clock).min).to eq 40
80
+ expect(test_container.parameter(:clock).sec).to eq 23
81
+
82
+ test_container.parameter(:timestamp, DateTime.new(2015, 02, 03, 14, 40, 23))
83
+ expect(test_container.parameter(:timestamp).year).to eq 2015
84
+ expect(test_container.parameter(:timestamp).month).to eq 2
85
+ expect(test_container.parameter(:timestamp).day).to eq 3
86
+ expect(test_container.parameter(:timestamp).hour).to eq 14
87
+ expect(test_container.parameter(:timestamp).min).to eq 40
88
+ expect(test_container.parameter(:timestamp).sec).to eq 23
82
89
  end
83
90
 
84
91
  it 'should be able to define parameter with options' do
85
- expect(@test_container.class.parameter(:with_options)[:options]).to eq a: 1, b: 2, c: 3
86
- expect(@test_container.class.parameter(:with_options)[:options][:a]).to be 1
87
- expect(@test_container.class.parameter(:with_options)[:a]).to be 1
88
- expect(@test_container.class.parameter(:with_options)[:options][:c]).to be 3
89
- expect(@test_container.class.parameter(:with_options)[:c]).to be 3
92
+ expect(test_container.class.parameter(:with_options)[:options]).to eq a: 1, b: 2, c: 3
93
+ expect(test_container.class.parameter(:with_options)[:options][:a]).to be 1
94
+ expect(test_container.class.parameter(:with_options)[:a]).to be 1
95
+ expect(test_container.class.parameter(:with_options)[:options][:c]).to be 3
96
+ expect(test_container.class.parameter(:with_options)[:c]).to be 3
97
+ end
98
+
99
+ it 'derived class should override parameter values from parent class' do
100
+ expect(derived_container.parameter(:name)).to eq 'somebody'
101
+ expect(derived_container.parameter(:check)).to eq 'yes'
102
+ end
103
+
104
+ it 'derived class should be able to access parameters of parent class' do
105
+ expect(derived_container.parameter(:price)).to eq 1.0
106
+ end
107
+
108
+ it 'derivation should be supported over multiple levels' do
109
+ expect(derived_derived_derived_container.parameter(:price)).to eq 1.0
90
110
  end
91
111
 
92
112
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libis-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kris Dekeyser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-29 00:00:00.000000000 Z
11
+ date: 2015-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -247,7 +247,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
247
  version: '0'
248
248
  requirements: []
249
249
  rubyforge_project:
250
- rubygems_version: 2.4.6
250
+ rubygems_version: 2.4.8
251
251
  signing_key:
252
252
  specification_version: 4
253
253
  summary: LIBIS toolbox.