libis-tools 0.9.1 → 0.9.3
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/parameter.rb +24 -3
- data/lib/libis/tools/version.rb +1 -1
- data/spec/parameter_container_spec.rb +9 -0
- data/spec/parameter_spec.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2c6c77cfccd6c062ae90c8379432fddc206f414
|
4
|
+
data.tar.gz: 215cea5196e3827cd404b1e4152aeb31ef526e36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 166dbb502d7ddb353711dd3ca89566e054f2c0f10c47295c10bb20a869dd645ad41c7211a1682f2d995492e120b0dfcdf3c0584b77678a0aa1647a6913072db0
|
7
|
+
data.tar.gz: c8ddc3e402ae7b7e4a0671e1619d73da0c276b40ffbd9c1be824f4e6e07e644191b20b85e1379d4213accde18fad2a3f5e9699cb57d5d575bcc15a4e51f772e4
|
@@ -8,14 +8,35 @@ module Libis
|
|
8
8
|
# noinspection RubyConstantNamingConvention
|
9
9
|
Parameter = ::Struct.new(:name, :default, :datatype, :description, :constraint, :options) do
|
10
10
|
|
11
|
-
VALID_PARAMETER_KEYS = [:name, :default, :datatype, :description, :constraint, :options]
|
12
|
-
|
13
11
|
def initialize(*args)
|
14
12
|
# noinspection RubySuperCallWithoutSuperclassInspection
|
15
13
|
super(*args)
|
16
14
|
self.options = {} unless self.options
|
17
15
|
end
|
18
16
|
|
17
|
+
def [](key)
|
18
|
+
# noinspection RubySuperCallWithoutSuperclassInspection
|
19
|
+
return super(key) if members.include?(key)
|
20
|
+
self[:options][key]
|
21
|
+
end
|
22
|
+
|
23
|
+
def []=(key,value)
|
24
|
+
# noinspection RubySuperCallWithoutSuperclassInspection
|
25
|
+
return super(key,value) if members.include?(key)
|
26
|
+
self[:options][key] = value
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.from_hash(h)
|
30
|
+
h.each { |k,v| self[k.to_s.to_sym] = v }
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_h
|
34
|
+
super.inject({}) do |hash, key, value|
|
35
|
+
key == :options ? value.each {|k,v| hash[k] = v} : hash[key] = value
|
36
|
+
hash
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
19
40
|
TRUE_BOOL = %w'true yes t y 1'
|
20
41
|
FALSE_BOOL = %w'false no f n 0'
|
21
42
|
|
@@ -116,7 +137,7 @@ module Libis
|
|
116
137
|
name = param_def.first.to_s.to_sym
|
117
138
|
default = param_def.last
|
118
139
|
parameters[name] = Parameter.new(name, default) if parameters[name].nil?
|
119
|
-
|
140
|
+
options.each { |key, value| parameters[name][key] = value if value }
|
120
141
|
else
|
121
142
|
parameters[options]
|
122
143
|
end
|
data/lib/libis/tools/version.rb
CHANGED
@@ -15,6 +15,7 @@ describe 'ParameterContainer' do
|
|
15
15
|
parameter calendar: Date.new(2014, 01, 01)
|
16
16
|
parameter clock: Time.parse('10:10')
|
17
17
|
parameter timestamp: DateTime.new(2014, 01, 01, 10, 10)
|
18
|
+
parameter with_options: true, options: {a: 1, b: 2}, c: 3
|
18
19
|
|
19
20
|
end
|
20
21
|
end
|
@@ -80,4 +81,12 @@ describe 'ParameterContainer' do
|
|
80
81
|
expect(@test_container.parameter(:timestamp).sec).to eq 23
|
81
82
|
end
|
82
83
|
|
84
|
+
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
|
90
|
+
end
|
91
|
+
|
83
92
|
end
|
data/spec/parameter_spec.rb
CHANGED
@@ -136,4 +136,13 @@ describe 'Parameter' do
|
|
136
136
|
|
137
137
|
end
|
138
138
|
|
139
|
+
it 'should allow to set and get options' do
|
140
|
+
|
141
|
+
@bool_parameter[:my_value] = :dummy_value
|
142
|
+
|
143
|
+
expect(@bool_parameter[:my_value]).to be :dummy_value
|
144
|
+
expect(@bool_parameter[:options][:my_value]).to be :dummy_value
|
145
|
+
|
146
|
+
end
|
147
|
+
|
139
148
|
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.3
|
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-04-
|
11
|
+
date: 2015-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|