tensai-core 0.1.3 → 0.1.4
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/tensai/util/initializer.rb +17 -9
- data/lib/tensai/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74e858174ff63a9b7c6766058c7f0ba6b8480fb3ab2c3dc36a8153130ea4c9fc
|
4
|
+
data.tar.gz: ce4458d89ba475e768d88ca6daf10ee5518b4fe6f9a3eb8f21a2c362461b7014
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93862828daba8fd33dc1f3084628246d48ede34939f3efac5fc7c1d89267b59e81284e425f4e2e8d8c12cb2393c46859ae998bef7b260ed2e41c25841488e83b
|
7
|
+
data.tar.gz: 760b0241b2df55f483185223f8f343f6fd2102661eb8f7da7ea82dd7c86fed26133dfa5e259ca3e344acffbc786b97f16661c7a34c3523f157f6c1044ea22f84
|
@@ -11,17 +11,21 @@ module Tensai::Util
|
|
11
11
|
@args = args
|
12
12
|
end
|
13
13
|
|
14
|
-
def included(klass)
|
15
|
-
|
16
|
-
klass.class_eval "attr_reader :#{arg}", __FILE__, __LINE__
|
17
|
-
end
|
18
|
-
|
14
|
+
def included(klass) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
15
|
+
this_class_args = args
|
19
16
|
all_args = all_args_for(klass)
|
20
17
|
|
21
18
|
klass.instance_eval do
|
22
19
|
define_method :__check_argument_type do |argument, value|
|
23
|
-
all_args[argument]
|
20
|
+
type = all_args[argument]
|
21
|
+
if type.default? && value.nil?
|
22
|
+
instance_variable_set("@#{argument}".to_sym, type[])
|
23
|
+
else
|
24
|
+
type[value]
|
25
|
+
end
|
24
26
|
end
|
27
|
+
|
28
|
+
attr_reader(*this_class_args.keys)
|
25
29
|
end
|
26
30
|
|
27
31
|
klass.class_eval InitializeMethod.new(all_args).code, __FILE__, __LINE__ + 11
|
@@ -47,8 +51,8 @@ module Tensai::Util
|
|
47
51
|
def code
|
48
52
|
<<~CODE
|
49
53
|
def initialize(#{signature})
|
50
|
-
#{check_argument_types_code}
|
51
54
|
#{assign_instance_variables_code}
|
55
|
+
#{check_argument_types_code}
|
52
56
|
end
|
53
57
|
CODE
|
54
58
|
end
|
@@ -64,11 +68,11 @@ module Tensai::Util
|
|
64
68
|
end
|
65
69
|
|
66
70
|
def required_args
|
67
|
-
args.reject { |_, type| type
|
71
|
+
args.reject { |_, type| optional_arg?(type) }.to_h
|
68
72
|
end
|
69
73
|
|
70
74
|
def optional_args
|
71
|
-
args.select { |_, type| type
|
75
|
+
args.select { |_, type| optional_arg?(type) }.to_h
|
72
76
|
end
|
73
77
|
|
74
78
|
def check_argument_types_code
|
@@ -78,6 +82,10 @@ module Tensai::Util
|
|
78
82
|
def assign_instance_variables_code
|
79
83
|
args.keys.map { |arg| "@#{arg} = #{arg}" }.join(';')
|
80
84
|
end
|
85
|
+
|
86
|
+
def optional_arg?(arg_type)
|
87
|
+
arg_type.optional? || arg_type.default?
|
88
|
+
end
|
81
89
|
end
|
82
90
|
end
|
83
91
|
end
|
data/lib/tensai/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tensai-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Fischer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-types
|