scopie 1.0.2 → 1.0.3
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/scopie/value.rb +13 -7
- data/lib/scopie/version.rb +1 -1
- data/lib/scopie.rb +0 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5437b5335d372d559a4d07e873999cad8e65cde2
|
|
4
|
+
data.tar.gz: f82f54898eab51611111625c633c176fb26187a0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b7cf7460e1fb19a77a4bd15b68a1609d25ef7b1216428e149a425ddd0428ad3698b40724706631319403408dfb1def209d848bd6edbb4f8df720a901d9e5d770
|
|
7
|
+
data.tar.gz: 07fe08d3b2d86ddb3921d65a44d40c4148c71b4b06e6887978e0d53e9bee04435c963df0a2a9327d9eafb1f7297229b4f8b6f1375cadb1f46de0b8cee7b46ce7
|
data/lib/scopie/value.rb
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
class Scopie::Value
|
|
3
|
+
class Scopie::Value
|
|
4
4
|
|
|
5
5
|
TRUE_VALUES = ['true', true, '1', 1].freeze
|
|
6
6
|
|
|
7
|
+
def initialize(hash, key_name, options)
|
|
8
|
+
@hash = hash
|
|
9
|
+
@key_name = key_name
|
|
10
|
+
@options = options
|
|
11
|
+
end
|
|
12
|
+
|
|
7
13
|
def raw
|
|
8
|
-
return hash[key_name] if hash.key?(key_name)
|
|
14
|
+
return @hash[@key_name] if @hash.key?(@key_name)
|
|
9
15
|
fetch_default
|
|
10
16
|
end
|
|
11
17
|
|
|
@@ -14,15 +20,15 @@ class Scopie::Value < Struct.new(:hash, :key_name, :options)
|
|
|
14
20
|
end
|
|
15
21
|
|
|
16
22
|
def fetch_type
|
|
17
|
-
options[:type]
|
|
23
|
+
@options[:type]
|
|
18
24
|
end
|
|
19
25
|
|
|
20
26
|
def fetch_default
|
|
21
|
-
options[:default]
|
|
27
|
+
@options[:default]
|
|
22
28
|
end
|
|
23
29
|
|
|
24
30
|
def has_default?
|
|
25
|
-
options.key?(:default)
|
|
31
|
+
@options.key?(:default)
|
|
26
32
|
end
|
|
27
33
|
|
|
28
34
|
def given?
|
|
@@ -30,7 +36,7 @@ class Scopie::Value < Struct.new(:hash, :key_name, :options)
|
|
|
30
36
|
end
|
|
31
37
|
|
|
32
38
|
def key_passed?
|
|
33
|
-
hash.key?(key_name)
|
|
39
|
+
@hash.key?(@key_name)
|
|
34
40
|
end
|
|
35
41
|
|
|
36
42
|
def present?
|
|
@@ -45,7 +51,7 @@ class Scopie::Value < Struct.new(:hash, :key_name, :options)
|
|
|
45
51
|
|
|
46
52
|
coercion_method_name = "coerce_to_#{type}"
|
|
47
53
|
|
|
48
|
-
respond_to?(coercion_method_name, true) ||
|
|
54
|
+
respond_to?(coercion_method_name, true) || raise(Scopie::InvalidOptionError.new, "Unknown value for option 'type' provided: :#{type}")
|
|
49
55
|
|
|
50
56
|
send(coercion_method_name, value)
|
|
51
57
|
end
|
data/lib/scopie/version.rb
CHANGED
data/lib/scopie.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Scopie
|
|
4
|
-
|
|
5
4
|
class InvalidOptionError < StandardError; end
|
|
6
5
|
|
|
7
6
|
RESULTS_TO_IGNORE = [true, false].freeze
|
|
@@ -16,5 +15,4 @@ module Scopie
|
|
|
16
15
|
def self.current_scopes(hash, method: nil, scopie: Scopie::Base.new)
|
|
17
16
|
scopie.current_scopes(hash, method)
|
|
18
17
|
end
|
|
19
|
-
|
|
20
18
|
end
|