shale-builder 0.5.0 → 0.5.2
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/CHANGELOG.md +7 -0
 - data/Gemfile.lock +1 -1
 - data/lib/shale/attribute.rb +6 -0
 - data/lib/shale/builder/version.rb +1 -1
 - data/lib/shale/builder.rb +27 -6
 - data/lib/tapioca/dsl/compilers/shale.rb +14 -4
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 8991027b587aeafbed207ac9cd822e41afebdfa569c024f6ed76bae038ea30b5
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: f61364b0035ff89ef1ad00daca3829fb1597600cd9a7c8d581e3a137984670d7
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 1a929606c8017a98f0c30a54728bcf2d64ee6effa155a60c4a337fcc48360b98b82456d29530e2bcbecf9a31ca04281e8932db706972215ab2a36e7c354eed4c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 3b70d9301cb4633ee59c37f37afa9c0f977e3726914491d8632ec8f4c95b5b21f78882a290da7482c595bf8a603695ad758b04b8e6d5665a7414579701980e96
         
     | 
    
        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
    
    
    
        data/lib/shale/attribute.rb
    CHANGED
    
    | 
         @@ -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?
         
     | 
    
        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 
     | 
    
         
            -
                  #: ( 
     | 
| 
       101 
     | 
    
         
            -
                   
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
      
 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  
     | 
| 
      
 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 = #{ 
     | 
| 
      
 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 = #{ 
     | 
| 
      
 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,14 @@ 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 =  
     | 
| 
       41 
     | 
    
         
            -
                         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 40 
     | 
    
         
            +
                        attribute = constant.attributes[attribute_name] #: ::Shale::Attribute
         
     | 
| 
      
 41 
     | 
    
         
            +
                        if (type = attribute.return_type)
         
     | 
| 
      
 42 
     | 
    
         
            +
                          return_type = type
         
     | 
| 
      
 43 
     | 
    
         
            +
                          nilable = true
         
     | 
| 
      
 44 
     | 
    
         
            +
                        else
         
     | 
| 
      
 45 
     | 
    
         
            +
                          return_type, nilable = shale_type_to_sorbet_return_type(attribute)
         
     | 
| 
      
 46 
     | 
    
         
            +
                        end
         
     | 
| 
      
 47 
     | 
    
         
            +
                        comments = [] #: T::Array[RBI::Comment]
         
     | 
| 
       43 
48 
     | 
    
         
             
                        if shale_builder_defined? && attribute.doc
         
     | 
| 
       44 
49 
     | 
    
         
             
                          comments << RBI::Comment.new(T.must(attribute.doc))
         
     | 
| 
       45 
50 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -52,7 +57,12 @@ module Tapioca 
     | 
|
| 
       52 
57 
     | 
    
         
             
                          getter_without_block_type = return_type.to_s
         
     | 
| 
       53 
58 
     | 
    
         
             
                        end
         
     | 
| 
       54 
59 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
                         
     | 
| 
      
 60 
     | 
    
         
            +
                        if (type = attribute.return_type || attribute.setter_type)
         
     | 
| 
      
 61 
     | 
    
         
            +
                          setter_type = type
         
     | 
| 
      
 62 
     | 
    
         
            +
                          nilable = true
         
     | 
| 
      
 63 
     | 
    
         
            +
                        else
         
     | 
| 
      
 64 
     | 
    
         
            +
                          setter_type, nilable = shale_type_to_sorbet_setter_type(attribute)
         
     | 
| 
      
 65 
     | 
    
         
            +
                        end
         
     | 
| 
       56 
66 
     | 
    
         
             
                        if attribute.collection?
         
     | 
| 
       57 
67 
     | 
    
         
             
                          setter_type_str = "T.nilable(T::Array[#{setter_type}])"
         
     | 
| 
       58 
68 
     | 
    
         
             
                        elsif nilable
         
     |