fino 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fino/library.rb +14 -0
- data/lib/fino/settings/boolean.rb +8 -0
- data/lib/fino/settings/numeric.rb +48 -2
- data/lib/fino/version.rb +1 -1
- data/lib/fino.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 02fd274d08f9e015ac157ee3237c91080af94ecb7b8439153531681acba77572
|
|
4
|
+
data.tar.gz: 42b5dbc517b0fa2919b7896ca2885b280f734c246455685c4957ebb967922094
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bb7a6d189bd4b25ffc4414a66e98d6bd289c64d2b4ca3fa456fc452165be4d1750d14bf62b5afe71209f0a5ade1a6d76d4413b3600c517e5fb0163cd8d791f6b
|
|
7
|
+
data.tar.gz: ec48c0a0d6012021a1918b2ad5c334bad9256b2199caf63ee6846116216ef7361b8424871a4d85c7dce2d9b716f29c64f0d884accc791dc197097f5d1661dada
|
data/lib/fino/library.rb
CHANGED
|
@@ -15,6 +15,20 @@ class Fino::Library
|
|
|
15
15
|
settings(*setting_names, at: at).map { |s| s.value(**context) }
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
def enabled?(setting_name, at: nil, **context)
|
|
19
|
+
setting = setting(setting_name, at: at)
|
|
20
|
+
raise ArgumentError, "Setting #{setting_name} is not a boolean" unless setting.instance_of?(Fino::Settings::Boolean)
|
|
21
|
+
|
|
22
|
+
setting.enabled?(**context)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def disabled?(setting_name, at: nil, **context)
|
|
26
|
+
setting = setting(setting_name, at: at)
|
|
27
|
+
raise ArgumentError, "Setting #{setting_name} is not a boolean" unless setting.instance_of?(Fino::Settings::Boolean)
|
|
28
|
+
|
|
29
|
+
setting.disabled?(**context)
|
|
30
|
+
end
|
|
31
|
+
|
|
18
32
|
def setting(setting_name, at: nil)
|
|
19
33
|
pipeline.read(build_setting_definition(setting_name, at: at))
|
|
20
34
|
end
|
|
@@ -9,24 +9,70 @@ module Fino::Settings::Numeric
|
|
|
9
9
|
@name = name
|
|
10
10
|
@short_name = short_name || name
|
|
11
11
|
end
|
|
12
|
+
|
|
13
|
+
def base_factor
|
|
14
|
+
1
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def convertible_to?(_other)
|
|
18
|
+
false
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
module Time
|
|
23
|
+
BASE_UNIT = :seconds
|
|
24
|
+
|
|
25
|
+
def convertible_to?(other)
|
|
26
|
+
other.is_a?(Time)
|
|
27
|
+
end
|
|
12
28
|
end
|
|
13
29
|
|
|
14
30
|
class Milliseconds < Generic
|
|
31
|
+
include Time
|
|
32
|
+
|
|
15
33
|
def initialize = super("Milliseconds", "ms")
|
|
34
|
+
|
|
35
|
+
def base_factor
|
|
36
|
+
0.001
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class Seconds < Generic
|
|
41
|
+
include Time
|
|
42
|
+
|
|
43
|
+
def initialize = super("Seconds", "sec")
|
|
44
|
+
|
|
45
|
+
def base_factor
|
|
46
|
+
1
|
|
47
|
+
end
|
|
16
48
|
end
|
|
17
49
|
|
|
18
50
|
module_function
|
|
19
51
|
|
|
20
52
|
def for(identifier)
|
|
21
|
-
case identifier
|
|
22
|
-
when
|
|
53
|
+
case identifier.to_s
|
|
54
|
+
when "ms", "milliseconds"
|
|
23
55
|
Milliseconds.new
|
|
56
|
+
when "sec", "seconds"
|
|
57
|
+
Seconds.new
|
|
24
58
|
else
|
|
25
59
|
Generic.new(identifier.to_s.capitalize)
|
|
26
60
|
end
|
|
27
61
|
end
|
|
28
62
|
end
|
|
29
63
|
|
|
64
|
+
def value(**context)
|
|
65
|
+
result = super
|
|
66
|
+
return result unless (target_unit_identifier = context[:unit])
|
|
67
|
+
|
|
68
|
+
raise ArgumentError, "No unit defined for this setting" unless unit
|
|
69
|
+
|
|
70
|
+
target_unit = Unit.for(target_unit_identifier)
|
|
71
|
+
raise ArgumentError, "Cannot convert #{unit.name} to #{target_unit.name}" unless unit.convertible_to?(target_unit)
|
|
72
|
+
|
|
73
|
+
result * unit.base_factor / target_unit.base_factor
|
|
74
|
+
end
|
|
75
|
+
|
|
30
76
|
def unit
|
|
31
77
|
return unless (identifier = definition.options[:unit])
|
|
32
78
|
|
data/lib/fino/version.rb
CHANGED
data/lib/fino.rb
CHANGED