strict 1.2.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/strict/interface.rb +15 -5
- data/lib/strict/interfaces/coercer.rb +19 -0
- data/lib/strict/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0af28e3c930c3859226bfad6360511e5941d63c0f14fdeb761c7db3f5ab316e8
|
4
|
+
data.tar.gz: 68423c7710c7da8cf074efea03b48bc49bcd31b31e7ab66808f6fea9b7b11246
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eae1ecfe69816a29f9bfdec1ba1d9648f5d30f08dcfd9400a99f0c68a167404965fc976218cfa4c1b2e507477f1c08b68ae8293ec738ad3c6d3dfec2158763ea
|
7
|
+
data.tar.gz: 2056d98bdcb4d26b429636ac71158113f0ad0fa57459d1d750bbe8428fa99995364d00726c5cbec77e76b492b3e405d26463e42fa2150e4f06bdc98cca09da25
|
data/Gemfile.lock
CHANGED
data/lib/strict/interface.rb
CHANGED
@@ -7,15 +7,25 @@ module Strict
|
|
7
7
|
mod.include(Interfaces::Instance)
|
8
8
|
end
|
9
9
|
|
10
|
+
def coercer
|
11
|
+
Interfaces::Coercer.new(self)
|
12
|
+
end
|
13
|
+
|
10
14
|
def expose(method_name, &block)
|
11
15
|
sig = sig(&block)
|
12
|
-
parameter_list =
|
13
|
-
|
16
|
+
parameter_list = [
|
17
|
+
*sig.parameters.map { |parameter| "#{parameter.name}:" },
|
18
|
+
"&block"
|
19
|
+
].join(", ")
|
20
|
+
argument_list = [
|
21
|
+
*sig.parameters.map { |parameter| "#{parameter.name}: #{parameter.name}" },
|
22
|
+
"&block"
|
23
|
+
].join(", ")
|
14
24
|
|
15
25
|
module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
16
|
-
def #{method_name}(#{parameter_list}
|
17
|
-
implementation.#{method_name}(#{argument_list}
|
18
|
-
end
|
26
|
+
def #{method_name}(#{parameter_list}) # def method_name(one:, two:, three:, &block)
|
27
|
+
implementation.#{method_name}(#{argument_list}) # implementation.method_name(one: one, two: two, three: three, &block)
|
28
|
+
end # end
|
19
29
|
RUBY
|
20
30
|
end
|
21
31
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Strict
|
4
|
+
module Interfaces
|
5
|
+
class Coercer
|
6
|
+
attr_reader :interface_class
|
7
|
+
|
8
|
+
def initialize(interface_class)
|
9
|
+
@interface_class = interface_class
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(value)
|
13
|
+
return value if value.nil? || value.instance_of?(interface_class)
|
14
|
+
|
15
|
+
interface_class.new(value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/strict/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strict
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Thompson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/strict/implementation_does_not_conform_error.rb
|
171
171
|
- lib/strict/initialization_error.rb
|
172
172
|
- lib/strict/interface.rb
|
173
|
+
- lib/strict/interfaces/coercer.rb
|
173
174
|
- lib/strict/interfaces/instance.rb
|
174
175
|
- lib/strict/method.rb
|
175
176
|
- lib/strict/method_call_error.rb
|