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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2b3b4a00d7564afb4a9d51b1ef35e87f0af7bafb9403a5155b0931d5f3a466d
4
- data.tar.gz: 579a93663bf8401af70283bb20b95bcd2cea8af4185ed4c422604ddad8734176
3
+ metadata.gz: 02fd274d08f9e015ac157ee3237c91080af94ecb7b8439153531681acba77572
4
+ data.tar.gz: 42b5dbc517b0fa2919b7896ca2885b280f734c246455685c4957ebb967922094
5
5
  SHA512:
6
- metadata.gz: b946c8453fa1d6b09c088360420306fa16bb27b890e84967f458361f52a311bab1551f081830c1e37e073c85e0ee47d660ea9b2aeccbdb7ae9c7081eadb62118
7
- data.tar.gz: e43d7a8f613bd7cc605f07d008c981021a7b593a974cf4a9f005c76d7ae5a9b7a8b498e4f8478b6cb287bcd58442198ff45a06e33fe3988b06cc016d13de79f5
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
@@ -17,4 +17,12 @@ class Fino::Settings::Boolean
17
17
  end
18
18
  end
19
19
  end
20
+
21
+ def enabled?(**context)
22
+ value(**context)
23
+ end
24
+
25
+ def disabled?(**context)
26
+ !enabled?(**context)
27
+ end
20
28
  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 :ms
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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fino
4
- VERSION = "1.5.1"
4
+ VERSION = "1.6.0"
5
5
  REQUIRED_RUBY_VERSION = ">= 3.0.0"
6
6
  end
data/lib/fino.rb CHANGED
@@ -39,6 +39,8 @@ module Fino
39
39
  def_delegators :library,
40
40
  :value,
41
41
  :values,
42
+ :enabled?,
43
+ :disabled?,
42
44
  :setting,
43
45
  :settings,
44
46
  :slice,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fino
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Egor Iskrenkov