shale-builder 0.5.1 → 0.6.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 +4 -4
 - data/CHANGELOG.md +8 -0
 - data/Gemfile.lock +1 -1
 - data/lib/shale/attribute.rb +7 -0
 - data/lib/shale/builder/assigned_attributes.rb +8 -0
 - data/lib/shale/builder/version.rb +1 -1
 - data/lib/shale/builder.rb +55 -8
 - data/lib/tapioca/dsl/compilers/shale.rb +2 -0
 - 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: da23c125418576ee513aefaabf8cc5817b9be9308755347902a55d3b8833c08f
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 76f3e943bea32652f01ecd0ea5d05565137a8b23b70c4edc386b87b534658e06
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 24737af006585825886b1588274f86da50a91f30303c89df4018dff232f59cb1d933d02a186346edb28b10455b14de8a72bf03e0623ef31225cf14f59866c15f
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 7d6bb01e61849c64667cdc08b38b611b6cd70f1cae72cf736ab0e7e76dc427311dc345e2764abd42936c0d8c573bc7dd0e5a1b3901bfe23c977bcf509df3a7c3
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -5,6 +5,14 @@ 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.6.0] - 2025-10-16
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            [Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.5.1...v0.6.0)
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            ### Changes
         
     | 
| 
      
 13 
     | 
    
         
            +
            - Add `Shale::Builder::mapper_attributes`, `Shale::Builder::mapper_attributes!`, `Shale::Builder::builder_attributes`, `Shale::Builder::builder_attributes!`
         
     | 
| 
      
 14 
     | 
    
         
            +
            - Add `Shale::Builder#inject_context`
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
       8 
16 
     | 
    
         
             
            ## [0.5.1] - 2025-10-15
         
     | 
| 
       9 
17 
     | 
    
         | 
| 
       10 
18 
     | 
    
         
             
            [Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.5.0...v0.5.1)
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/lib/shale/attribute.rb
    CHANGED
    
    | 
         @@ -38,5 +38,12 @@ module Shale 
     | 
|
| 
       38 
38 
     | 
    
         
             
                def mapper?
         
     | 
| 
       39 
39 
     | 
    
         
             
                  type.is_a?(Class) && type < Shale::Mapper
         
     | 
| 
       40 
40 
     | 
    
         
             
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                # Returns `true` if the attribute is handled by a shale builder.
         
     | 
| 
      
 43 
     | 
    
         
            +
                #
         
     | 
| 
      
 44 
     | 
    
         
            +
                #: -> bool
         
     | 
| 
      
 45 
     | 
    
         
            +
                def builder?
         
     | 
| 
      
 46 
     | 
    
         
            +
                  type.is_a?(Class) && type < Shale::Builder
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
       41 
48 
     | 
    
         
             
              end
         
     | 
| 
       42 
49 
     | 
    
         
             
            end
         
     | 
| 
         @@ -59,6 +59,14 @@ module Shale 
     | 
|
| 
       59 
59 
     | 
    
         
             
                  end
         
     | 
| 
       60 
60 
     | 
    
         
             
                  mixes_in_class_methods ClassMethods
         
     | 
| 
       61 
61 
     | 
    
         | 
| 
      
 62 
     | 
    
         
            +
                  def initialize(*args, **kwargs, &block)
         
     | 
| 
      
 63 
     | 
    
         
            +
                    super
         
     | 
| 
      
 64 
     | 
    
         
            +
                    @__initialized = true
         
     | 
| 
      
 65 
     | 
    
         
            +
                  end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                  #: bool?
         
     | 
| 
      
 68 
     | 
    
         
            +
                  attr_reader :__initialized
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
       62 
70 
     | 
    
         
             
                  # Returns a set of names of assigned shale attributes.
         
     | 
| 
       63 
71 
     | 
    
         
             
                  #
         
     | 
| 
       64 
72 
     | 
    
         
             
                  #: -> Set[Symbol]
         
     | 
    
        data/lib/shale/builder.rb
    CHANGED
    
    | 
         @@ -169,16 +169,44 @@ module Shale 
     | 
|
| 
       169 
169 
     | 
    
         
             
                    RUBY
         
     | 
| 
       170 
170 
     | 
    
         
             
                  end
         
     | 
| 
       171 
171 
     | 
    
         | 
| 
       172 
     | 
    
         
            -
             
     | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
      
 172 
     | 
    
         
            +
                  # Returns a hash of shale attributes that are handled by a shale mapper.
         
     | 
| 
      
 173 
     | 
    
         
            +
                  # The result gets memoized.
         
     | 
| 
      
 174 
     | 
    
         
            +
                  #
         
     | 
| 
      
 175 
     | 
    
         
            +
                  #: -> Hash[Symbol, Shale::Attribute]
         
     | 
| 
      
 176 
     | 
    
         
            +
                  def mapper_attributes
         
     | 
| 
      
 177 
     | 
    
         
            +
                    @mapper_attributes ||= mapper_attributes!
         
     | 
| 
      
 178 
     | 
    
         
            +
                  end
         
     | 
| 
       174 
179 
     | 
    
         | 
| 
       175 
     | 
    
         
            -
             
     | 
| 
       176 
     | 
    
         
            -
                   
     | 
| 
       177 
     | 
    
         
            -
                   
     | 
| 
       178 
     | 
    
         
            -
             
     | 
| 
      
 180 
     | 
    
         
            +
                  # Returns a hash of shale attributes that are handled by a shale mapper.
         
     | 
| 
      
 181 
     | 
    
         
            +
                  # Always constructs a new hash.
         
     | 
| 
      
 182 
     | 
    
         
            +
                  #
         
     | 
| 
      
 183 
     | 
    
         
            +
                  #: -> Hash[Symbol, Shale::Attribute]
         
     | 
| 
      
 184 
     | 
    
         
            +
                  def mapper_attributes!
         
     | 
| 
      
 185 
     | 
    
         
            +
                    attributes.select do |_, attr|
         
     | 
| 
      
 186 
     | 
    
         
            +
                      attr.mapper?
         
     | 
| 
      
 187 
     | 
    
         
            +
                    end
         
     | 
| 
      
 188 
     | 
    
         
            +
                  end
         
     | 
| 
       179 
189 
     | 
    
         | 
| 
       180 
     | 
    
         
            -
             
     | 
| 
       181 
     | 
    
         
            -
             
     | 
| 
      
 190 
     | 
    
         
            +
                  # Returns a hash of shale attributes that are handled by a shale builder.
         
     | 
| 
      
 191 
     | 
    
         
            +
                  # The result gets memoized.
         
     | 
| 
      
 192 
     | 
    
         
            +
                  #
         
     | 
| 
      
 193 
     | 
    
         
            +
                  #: -> Hash[Symbol, Shale::Attribute]
         
     | 
| 
      
 194 
     | 
    
         
            +
                  def builder_attributes
         
     | 
| 
      
 195 
     | 
    
         
            +
                    @builder_attributes ||= builder_attributes!
         
     | 
| 
      
 196 
     | 
    
         
            +
                  end
         
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
      
 198 
     | 
    
         
            +
                  # Returns a hash of shale attributes that are handled by a shale builder.
         
     | 
| 
      
 199 
     | 
    
         
            +
                  # Always constructs a new hash.
         
     | 
| 
      
 200 
     | 
    
         
            +
                  #
         
     | 
| 
      
 201 
     | 
    
         
            +
                  #: -> Hash[Symbol, Shale::Attribute]
         
     | 
| 
      
 202 
     | 
    
         
            +
                  def builder_attributes!
         
     | 
| 
      
 203 
     | 
    
         
            +
                    attributes.select do |_, attr|
         
     | 
| 
      
 204 
     | 
    
         
            +
                      attr.builder?
         
     | 
| 
      
 205 
     | 
    
         
            +
                    end
         
     | 
| 
      
 206 
     | 
    
         
            +
                  end
         
     | 
| 
      
 207 
     | 
    
         
            +
             
     | 
| 
      
 208 
     | 
    
         
            +
                end
         
     | 
| 
      
 209 
     | 
    
         
            +
                mixes_in_class_methods(ClassMethods)
         
     | 
| 
       182 
210 
     | 
    
         | 
| 
       183 
211 
     | 
    
         
             
                # Returns an array of shale values
         
     | 
| 
       184 
212 
     | 
    
         
             
                # that have been assigned.
         
     | 
| 
         @@ -191,6 +219,25 @@ module Shale 
     | 
|
| 
       191 
219 
     | 
    
         
             
                  end
         
     | 
| 
       192 
220 
     | 
    
         
             
                end
         
     | 
| 
       193 
221 
     | 
    
         | 
| 
      
 222 
     | 
    
         
            +
                # Attempts to set the given attributes and values
         
     | 
| 
      
 223 
     | 
    
         
            +
                # within this shale builder object and all of its sub-builders.
         
     | 
| 
      
 224 
     | 
    
         
            +
                # Attributes that aren't defined are ignored.
         
     | 
| 
      
 225 
     | 
    
         
            +
                #
         
     | 
| 
      
 226 
     | 
    
         
            +
                #: (**untyped) -> void
         
     | 
| 
      
 227 
     | 
    
         
            +
                def inject_context(**context)
         
     | 
| 
      
 228 
     | 
    
         
            +
                  context.each do |name, val|
         
     | 
| 
      
 229 
     | 
    
         
            +
                    try(:"#{name}=", val)
         
     | 
| 
      
 230 
     | 
    
         
            +
                  end
         
     | 
| 
      
 231 
     | 
    
         
            +
             
     | 
| 
      
 232 
     | 
    
         
            +
                  klass = self.class #: as untyped
         
     | 
| 
      
 233 
     | 
    
         
            +
                  klass.builder_attributes.each_key do |name|
         
     | 
| 
      
 234 
     | 
    
         
            +
                    val = public_send(name)
         
     | 
| 
      
 235 
     | 
    
         
            +
                    next unless val
         
     | 
| 
      
 236 
     | 
    
         
            +
             
     | 
| 
      
 237 
     | 
    
         
            +
                    val.inject_context(context)
         
     | 
| 
      
 238 
     | 
    
         
            +
                  end
         
     | 
| 
      
 239 
     | 
    
         
            +
                end
         
     | 
| 
      
 240 
     | 
    
         
            +
             
     | 
| 
       194 
241 
     | 
    
         
             
              end
         
     | 
| 
       195 
242 
     | 
    
         
             
            end
         
     | 
| 
       196 
243 
     | 
    
         | 
| 
         @@ -40,6 +40,7 @@ module Tapioca 
     | 
|
| 
       40 
40 
     | 
    
         
             
                        attribute = constant.attributes[attribute_name] #: ::Shale::Attribute
         
     | 
| 
       41 
41 
     | 
    
         
             
                        if (type = attribute.return_type)
         
     | 
| 
       42 
42 
     | 
    
         
             
                          return_type = type
         
     | 
| 
      
 43 
     | 
    
         
            +
                          nilable = true
         
     | 
| 
       43 
44 
     | 
    
         
             
                        else
         
     | 
| 
       44 
45 
     | 
    
         
             
                          return_type, nilable = shale_type_to_sorbet_return_type(attribute)
         
     | 
| 
       45 
46 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -58,6 +59,7 @@ module Tapioca 
     | 
|
| 
       58 
59 
     | 
    
         | 
| 
       59 
60 
     | 
    
         
             
                        if (type = attribute.return_type || attribute.setter_type)
         
     | 
| 
       60 
61 
     | 
    
         
             
                          setter_type = type
         
     | 
| 
      
 62 
     | 
    
         
            +
                          nilable = true
         
     | 
| 
       61 
63 
     | 
    
         
             
                        else
         
     | 
| 
       62 
64 
     | 
    
         
             
                          setter_type, nilable = shale_type_to_sorbet_setter_type(attribute)
         
     | 
| 
       63 
65 
     | 
    
         
             
                        end
         
     |