support_table_data 1.6.0 → 1.6.1

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: 6aa6d124e04e60a539f6a56207da866bb6aa0d277484104f6685d9499b41d504
4
- data.tar.gz: f3c9791bf9e6b2a46416cca2a154abdb1fe18e108f3e386670818939cabac1a2
3
+ metadata.gz: 9977faeef0b935eb106be5e5cf9a6ba81a0ba1ab1f9e90fa6b694ce32fe3fd40
4
+ data.tar.gz: 31a8019bce856f7555f7a2fbb28a913fad287dbc4c554d36cb3983f2b564e3db
5
5
  SHA512:
6
- metadata.gz: cec5bdca6906dac42489e2f43798bf647eebaf6fd1df1d314bb259cf46170c6f7833aeccd7f7d59917ea0406699f6cc99905afc5977bd907c1e19f750dc0b3e5
7
- data.tar.gz: eb748280d59753b9bde5618900d0f25ae8e01c3ace0a37cdb5021cad1f1751832b14cc6e4bd624b200398178cd8bd3636e5d8d128c829180fe3c547d67ac88db
6
+ metadata.gz: 7cc917037da50fd3f79ffe67db151bafb4c0042729946eb62974b46a3cf5332a8e3b6ab2ff4a31df20d6d2273f111ba7aaad14509a352b1fa986eb120e7b4b68
7
+ data.tar.gz: 50ab7d9230f0b7f104f542121e1cf3d1b7ffb4f6082fda2af68c9829e9b2b8eb3b2e04c126ef81f82395800ea8a0802229d8fdd313c21e77d8704b1597d87ca0
data/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 1.6.1
8
+
9
+ ### Fixed
10
+
11
+ - Fixed issue with YARD and RBS documentation tasks possibly raising an error if a named value method is deprecated and wrapped to return an error. Types are now inferred directly from the data rather than calling a method.
12
+
7
13
  ## 1.6.0
8
14
 
9
15
  ### Added
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.0
1
+ 1.6.1
@@ -42,7 +42,7 @@ module SupportTableData
42
42
  lines << "def self.#{name}: () -> #{klass.name}"
43
43
  lines << "def #{name}?: () -> bool"
44
44
  klass.support_table_attribute_helpers.each do |attribute_name|
45
- return_type = TypeInference.rbs_type(TypeInference.value_type(klass, "#{name}_#{attribute_name}"))
45
+ return_type = TypeInference.rbs_type(TypeInference.value_type(klass, name, attribute_name))
46
46
  lines << "def self.#{name}_#{attribute_name}: () -> #{return_type}"
47
47
  end
48
48
  lines
@@ -3,26 +3,28 @@
3
3
  module SupportTableData
4
4
  module Documentation
5
5
  # Infers documentation types for the dynamically-defined attribute helpers
6
- # by calling the generated method and inspecting the class of the value
7
- # it returns. The values returned by these helpers are frozen literals from
8
- # the parsed data file, so this does not require a database connection.
9
- #
10
- # This module must not be used on finder helpers (e.g. `Color.red`), which
11
- # call `find_by!` and would hit the database.
6
+ # by reading the canonical value out of the parsed data file and
7
+ # inspecting its class. This avoids invoking the generated method, which
8
+ # may have been wrapped (e.g. deprecated) to raise.
12
9
  module TypeInference
13
10
  module_function
14
11
 
15
- # Determine the documentation type for an attribute helper by calling
16
- # the method and looking at the class of the returned value. Returns
17
- # nil when the method is not defined.
12
+ # Determine the documentation type for a named-instance attribute
13
+ # helper by looking up the attribute value in the model's named
14
+ # instance data and returning its class. Returns nil when the
15
+ # attribute is not defined for the named instance.
18
16
  #
19
17
  # @param klass [Class] The model class
20
- # @param method_name [String, Symbol] The class method name to call
18
+ # @param name [String, Symbol] The named instance name
19
+ # @param attribute_name [String, Symbol] The attribute name
21
20
  # @return [Class, nil]
22
- def value_type(klass, method_name)
23
- return nil unless klass.respond_to?(method_name)
21
+ def value_type(klass, name, attribute_name)
22
+ return nil unless klass.respond_to?(:named_instance_data)
24
23
 
25
- klass.public_send(method_name).class
24
+ data = klass.named_instance_data(name)
25
+ return nil unless data.is_a?(Hash) && data.key?(attribute_name.to_s)
26
+
27
+ data[attribute_name.to_s].class
26
28
  end
27
29
 
28
30
  # Map a Ruby value class to a YARD type string.
@@ -175,7 +175,7 @@ module SupportTableData
175
175
  end
176
176
 
177
177
  def attribute_yard_return_type(name, attribute_name)
178
- TypeInference.yard_type(TypeInference.value_type(klass, "#{name}_#{attribute_name}"))
178
+ TypeInference.yard_type(TypeInference.value_type(klass, name, attribute_name))
179
179
  end
180
180
  end
181
181
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: support_table_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand