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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a38d61c0552c55ae738a98e940df39273b40d74cbd3beca6b14e6b533a8a5a5
4
- data.tar.gz: 6afe1d5a11b6fe578e0ec3c10eab69981fc322e6667b7d7f6266b36a900fe259
3
+ metadata.gz: 74e858174ff63a9b7c6766058c7f0ba6b8480fb3ab2c3dc36a8153130ea4c9fc
4
+ data.tar.gz: ce4458d89ba475e768d88ca6daf10ee5518b4fe6f9a3eb8f21a2c362461b7014
5
5
  SHA512:
6
- metadata.gz: fcb9637cef98d96f5c9b1742a034fcf0d9aedf0a71c2f32c3eb162ef27a797b715015b0b73317975cf3766365ae008d71215b8476bc3cff4936795ed9a3024a6
7
- data.tar.gz: deecb846c655d8798f5cda9edeca2fb528f729a890f7ee80546ca86749bb1db549cdc9b56586084e8300db811829de87a355d7a715f59f7756bfccb02ec94118
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
- @args.keys.each do |arg|
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][value]
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.optional? }.to_h
71
+ args.reject { |_, type| optional_arg?(type) }.to_h
68
72
  end
69
73
 
70
74
  def optional_args
71
- args.select { |_, type| type.optional? }.to_h
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tensai
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
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.3
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-03 00:00:00.000000000 Z
11
+ date: 2019-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-types