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 +4 -4
- data/lib/libis/tools/config.rb +1 -1
- data/lib/libis/tools/config_file.rb +2 -2
- data/lib/libis/tools/parameter.rb +3 -1
- data/lib/libis/tools/version.rb +1 -1
- data/spec/parameter_container_spec.rb +85 -65
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f35282647506db8de43d2a9963bd3aabaa944788
|
4
|
+
data.tar.gz: 476b0593171ce67aec1e15a33d75e5e72751b2fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa6158973c7ac9f8a1ef9fc1bfa5406bcb0cce7651592488ede57a245c4a3e9e04ec8eb89f14e194d58e00cc3f025896238c98d495ca609d8f17acc6556fe2ac
|
7
|
+
data.tar.gz: e11e56b324b2a3e58e27f8ac5770b383246cec7c09af4800ddb61e6385d95b433bc1608c54a4a83606d701ab272991e3fb421f4032e0a77ebd7b29b7bb7ed0a0
|
data/lib/libis/tools/config.rb
CHANGED
@@ -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
|
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
|
|
data/lib/libis/tools/version.rb
CHANGED
@@ -4,26 +4,33 @@ require 'libis/tools/parameter'
|
|
4
4
|
|
5
5
|
describe 'ParameterContainer' do
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
24
|
-
|
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(
|
35
|
-
expect(
|
36
|
-
expect(
|
37
|
-
expect(
|
38
|
-
expect(
|
39
|
-
expect(
|
40
|
-
expect(
|
41
|
-
expect(
|
42
|
-
expect(
|
43
|
-
expect(
|
44
|
-
expect(
|
45
|
-
expect(
|
46
|
-
expect(
|
47
|
-
expect(
|
48
|
-
expect(
|
49
|
-
expect(
|
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
|
-
|
54
|
-
expect(
|
55
|
-
|
56
|
-
|
57
|
-
expect(
|
58
|
-
|
59
|
-
|
60
|
-
expect(
|
61
|
-
|
62
|
-
|
63
|
-
expect(
|
64
|
-
|
65
|
-
|
66
|
-
expect(
|
67
|
-
expect(
|
68
|
-
expect(
|
69
|
-
|
70
|
-
|
71
|
-
expect(
|
72
|
-
expect(
|
73
|
-
expect(
|
74
|
-
|
75
|
-
|
76
|
-
expect(
|
77
|
-
expect(
|
78
|
-
expect(
|
79
|
-
expect(
|
80
|
-
expect(
|
81
|
-
expect(
|
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(
|
86
|
-
expect(
|
87
|
-
expect(
|
88
|
-
expect(
|
89
|
-
expect(
|
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.
|
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-
|
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.
|
250
|
+
rubygems_version: 2.4.8
|
251
251
|
signing_key:
|
252
252
|
specification_version: 4
|
253
253
|
summary: LIBIS toolbox.
|