shale-builder 0.5.0 → 0.5.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: febc908c436d767296b5869c0f83de5192ebd2dea56649a68840f951ca61210e
4
- data.tar.gz: 921efc21393a6a01516dc0954efe6f87fe74326d51d1969c00e985f3f8ad9824
3
+ metadata.gz: 5129b4e45147ec672d0e23aaf17ad57290bdc9f1f4a81b9d1756ebd44a738df3
4
+ data.tar.gz: 0e47f511519fe4003622c862799ccd34e51bf61bba7bbce3ca6d8e81bdac95d8
5
5
  SHA512:
6
- metadata.gz: 315da1873bcba3a08cbf4a6d405b975a8c9be51442726faab0e886138be48b50fa6bec7c5367064d1d0cc731af17ec0c10bbe9cfb04716a5b1d0712de46244a5
7
- data.tar.gz: 54df3a9708bc1e327ecb7f85338a1420cca5b98d82b754acbecd03417541951472b9f2d005035abe5fe1217bfd5db10d3730a1966043c65956b3cdb83d080299
6
+ metadata.gz: 4682a5bf3469eec462ad9a191434bb761c633cf21117e2443dba85cefc4a2e2641104c4966cd113d76200b95954206b3292fc1182836b550a085cf4d144625c6
7
+ data.tar.gz: 349e8086105a41ee0b5decb2ebbedcb810f7a331ae8b0e2b6a1bdab051eeafb9939e5d36f7d4b841062d7eab3269f85fb0b07d77eb63d3abfdae24ea9b774b7d
data/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.5.1] - 2025-10-15
9
+
10
+ [Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.5.0...v0.5.1)
11
+
12
+ ### Changes
13
+ - Add `return_type` and `setter_type` overrides per attribute
14
+
8
15
  ## [0.5.0] - 2025-10-15
9
16
 
10
17
  [Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.4.1...v0.5.0)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shale-builder (0.5.0)
4
+ shale-builder (0.5.1)
5
5
  booleans (>= 0.1)
6
6
  shale (< 2.0)
7
7
  sorbet-runtime (> 0.5)
@@ -7,6 +7,12 @@ module Shale
7
7
  class Attribute # rubocop:disable Style/Documentation
8
8
  extend T::Sig
9
9
 
10
+ #: untyped
11
+ attr_accessor :setter_type
12
+
13
+ #: untyped
14
+ attr_accessor :return_type
15
+
10
16
  # Contains the documentation comment for the shale attribute
11
17
  # in a Ruby String.
12
18
  #: String?
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Shale
4
4
  module Builder
5
- VERSION = '0.5.0'
5
+ VERSION = '0.5.1'
6
6
  end
7
7
  end
data/lib/shale/builder.rb CHANGED
@@ -97,13 +97,34 @@ module Shale
97
97
  sig { abstract.returns(T::Hash[Symbol, Shale::Attribute]) }
98
98
  def attributes; end
99
99
 
100
- #: ((String | Symbol) name, Class type, ?collection: bool, ?default: Proc?, ?doc: String?, **Object kwargs) ?{ -> void } -> void
101
- def attribute(name, type, collection: false, default: nil, doc: nil, **kwargs, &block)
102
- super(name, type, collection:, default:, **kwargs, &block)
100
+ #: (
101
+ #| String | Symbol name,
102
+ #| Class shale_mapper,
103
+ #| ?collection: bool,
104
+ #| ?default: Proc?,
105
+ #| ?doc: String?,
106
+ #| ?return_type: untyped,
107
+ #| ?setter_type: untyped,
108
+ #| **Object kwargs
109
+ #| ) ?{ -> void } -> void
110
+ def attribute(
111
+ name,
112
+ shale_mapper,
113
+ collection: false,
114
+ default: nil,
115
+ doc: nil,
116
+ return_type: nil,
117
+ setter_type: nil,
118
+ **kwargs,
119
+ &block
120
+ )
121
+ super(name, shale_mapper, collection:, default:, **kwargs, &block)
103
122
  if (attr_def = attributes[name.to_sym])
104
123
  attr_def.doc = doc
124
+ attr_def.return_type = return_type
125
+ attr_def.setter_type = setter_type
105
126
  end
106
- return unless type < ::Shale::Mapper
127
+ return unless shale_mapper < ::Shale::Mapper
107
128
 
108
129
  if collection
109
130
  @builder_methods_module.class_eval <<~RUBY, __FILE__, __LINE__ + 1
@@ -111,7 +132,7 @@ module Shale
111
132
  return super unless block_given? # return super unless block_given?
112
133
  #
113
134
  arr = self.#{name} ||= [] # arr = self.clients ||= []
114
- object = #{type}.new # object = Client.new
135
+ object = #{shale_mapper}.new # object = Client.new
115
136
  yield(object) # yield(object)
116
137
  arr << object # arr << object
117
138
  object # object
@@ -124,7 +145,7 @@ module Shale
124
145
  def #{name} # def amount
125
146
  return super unless block_given? # return super unless block_given?
126
147
  #
127
- object = #{type}.new # object = Amount.new
148
+ object = #{shale_mapper}.new # object = Amount.new
128
149
  yield(object) # yield(object)
129
150
  self.#{name} = object # self.amount = object
130
151
  end # end
@@ -37,9 +37,13 @@ module Tapioca
37
37
  # For each attribute defined in the class
38
38
  attribute_names = constant.attributes.keys.sort
39
39
  attribute_names.each do |attribute_name|
40
- attribute = T.let(constant.attributes[attribute_name], ::Shale::Attribute)
41
- return_type, nilable = shale_type_to_sorbet_return_type(attribute)
42
- comments = T.let([], T::Array[RBI::Comment])
40
+ attribute = constant.attributes[attribute_name] #: ::Shale::Attribute
41
+ if (type = attribute.return_type)
42
+ return_type = type
43
+ else
44
+ return_type, nilable = shale_type_to_sorbet_return_type(attribute)
45
+ end
46
+ comments = [] #: T::Array[RBI::Comment]
43
47
  if shale_builder_defined? && attribute.doc
44
48
  comments << RBI::Comment.new(T.must(attribute.doc))
45
49
  end
@@ -52,7 +56,11 @@ module Tapioca
52
56
  getter_without_block_type = return_type.to_s
53
57
  end
54
58
 
55
- setter_type, nilable = shale_type_to_sorbet_setter_type(attribute)
59
+ if (type = attribute.return_type || attribute.setter_type)
60
+ setter_type = type
61
+ else
62
+ setter_type, nilable = shale_type_to_sorbet_setter_type(attribute)
63
+ end
56
64
  if attribute.collection?
57
65
  setter_type_str = "T.nilable(T::Array[#{setter_type}])"
58
66
  elsif nilable
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shale-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Drewniak