jsonapi-resources-anchor 2.9.2 → 2.11.0

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: b6b495cccd59d5fe578f078f41827035d72da3829e8141963c3b475eb5f526da
4
- data.tar.gz: ff128bb2b40e9410d07750c3d420e9b6ccdea4b4a959aa1fea30b3e2b94a243c
3
+ metadata.gz: 3b169ae02d02b60767497e98abfe2570907e1c1f09f63c24640ef0f9750be576
4
+ data.tar.gz: 9dbba964c052a3209bc149c06b5c504098eeb1c6556f2b9b310a8e01aab25cfa
5
5
  SHA512:
6
- metadata.gz: ea29aace3714798eb05322f62fe18b712a1331ba0771636577f3505cdd4220df7ec757dcaabc232eb2e4a7ce8c4f9a6605be27452d23ebcb44fdfea605f0a2a5
7
- data.tar.gz: fd5235b86ebbf0f310f0fc4da805337e6e60c5e1c8be988fd1ac22faa8bdcb7ac37f4674f04ed81918142b684468eae2b0d7c23d1c7ec4bb39732eb476758c36
6
+ metadata.gz: 950c50fdd85db0fb37e255b5380325c72654eeaadb4e225f4b2d4aaae7ee5208e1f2b16a2d6e07c38864cff83942751e080267d6b169bd927aea2102e28f2454
7
+ data.tar.gz: f4f0e946db1de423979df2189a2b31e4ab0ee0fc8652891c490beaae0afabd70ddbcd47e20cb57f65f28e1ee704621607469431ff3637db8ca6dd09da3fd23d7
data/lib/anchor/config.rb CHANGED
@@ -9,7 +9,9 @@ module Anchor
9
9
  :use_type_as_schema_name,
10
10
  :maybe_as_union,
11
11
  :array_bracket_notation,
12
- :infer_default_as_non_null
12
+ :infer_default_as_non_null,
13
+ :ar_comment_to_string,
14
+ :infer_ar_enums
13
15
 
14
16
  def initialize
15
17
  @ar_column_to_type = nil
@@ -22,6 +24,8 @@ module Anchor
22
24
  @maybe_as_union = nil
23
25
  @array_bracket_notation = nil
24
26
  @infer_default_as_non_null = nil
27
+ @ar_comment_to_string = nil
28
+ @infer_ar_enums = nil
25
29
  end
26
30
  end
27
31
  end
@@ -76,10 +76,18 @@ module Anchor
76
76
  serializer_defined = (_model_class.try(:attribute_types) || {})[model_method.to_s].respond_to?(:coder)
77
77
  method_defined = model_method_defined || resource_method_defined || serializer_defined
78
78
 
79
+ enum = Anchor.config.infer_ar_enums && !method_defined && _model_class.try(:defined_enums).try(:[], model_method.to_s)
79
80
  column = !method_defined && _model_class.try(:columns_hash).try(:[], model_method.to_s)
80
- if column
81
+ if enum
82
+ Anchor::Types::Union.new(enum.map { |_key, val| Anchor::Types::Literal.new(val) })
83
+ elsif column
81
84
  type = Anchor::Types::Inference::ActiveRecord::SQL.from(column)
82
- description ||= column.comment if Anchor.config.use_active_record_comment
85
+ unless description
86
+ description = column.comment if Anchor.config.use_active_record_comment
87
+ if description && !Anchor.config.ar_comment_to_string.nil?
88
+ description = Anchor.config.ar_comment_to_string.call(description)
89
+ end
90
+ end
83
91
  check_presence = type.is_a?(Anchor::Types::Maybe) && Anchor.config.use_active_record_validations
84
92
  if check_presence && _model_class.validators_on(model_method).any? do |v|
85
93
  if v.is_a?(ActiveRecord::Validations::NumericalityValidator)
@@ -1,3 +1,3 @@
1
1
  module Anchor
2
- VERSION = "2.9.2"
2
+ VERSION = "2.11.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-resources-anchor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.2
4
+ version: 2.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-27 00:00:00.000000000 Z
11
+ date: 2025-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-resources