sober_swag 0.12.0 → 0.13.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/lib/sober_swag/compiler/type.rb +13 -10
- data/lib/sober_swag/parser.rb +2 -1
- data/lib/sober_swag/version.rb +1 -1
- metadata +1 -2
- data/bin/console +0 -48
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 9e65d79013d299407a6fbe6c610bf1ca4c6b24be6b2e944de39faf0bc80204d1
         | 
| 4 | 
            +
              data.tar.gz: 69e079b589f72e3ff06d5b08bfff72064341cbc916311166dcfd4b9e8172b5da
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 342f90b5d974c97149b4449e5ae20b7d2551190a4ded32bfef1e62ea82b5b7e03c75103fefdb48390cf0cfbe9bc58b37f4118bcca3fded7b5f951b8470195ad0
         | 
| 7 | 
            +
              data.tar.gz: 3877ec4ef5cd9823e6e43a9c192a7aae89bf51913c9481018fef38206e7bbb36e2907cad3613098907d0c394c52119b7488263bad645a25d9d28452ea55cc75e
         | 
| @@ -126,7 +126,9 @@ module SoberSwag | |
| 126 126 |  | 
| 127 127 | 
             
                    case type
         | 
| 128 128 | 
             
                    when Class
         | 
| 129 | 
            -
                       | 
| 129 | 
            +
                      # refs have to be standalone
         | 
| 130 | 
            +
                      # so to not interefere with our other stuff, do this horrible garbage
         | 
| 131 | 
            +
                      { oneOf: [{ '$ref'.to_sym => self.class.get_ref(type) }] }
         | 
| 130 132 | 
             
                    when Dry::Types::Constrained
         | 
| 131 133 | 
             
                      self.class.new(type.type).schema_stub
         | 
| 132 134 | 
             
                    when Dry::Types::Array::Member
         | 
| @@ -220,19 +222,20 @@ module SoberSwag | |
| 220 222 | 
             
                      else
         | 
| 221 223 | 
             
                        [name, value]
         | 
| 222 224 | 
             
                      end
         | 
| 223 | 
            -
                    # can't match on value directly as ruby uses `===` to match,
         | 
| 224 | 
            -
                    # and classes use `===` to mean `is an instance of`, as
         | 
| 225 | 
            -
                    # opposed to direct equality lmao
         | 
| 226 225 | 
             
                    when Nodes::Primitive
         | 
| 227 226 | 
             
                      value = object.value
         | 
| 228 227 | 
             
                      metadata = object.metadata
         | 
| 229 | 
            -
                       | 
| 230 | 
            -
                         | 
| 231 | 
            -
             | 
| 232 | 
            -
             | 
| 228 | 
            +
                      type_def =
         | 
| 229 | 
            +
                        if self.class.primitive?(value)
         | 
| 230 | 
            +
                          self.class.primitive_def(value)
         | 
| 231 | 
            +
                        else
         | 
| 232 | 
            +
                          metadata.merge!(value.meta)
         | 
| 233 | 
            +
                          # refs have to be on their own, this is the stupid workaround
         | 
| 234 | 
            +
                          # so you can add descriptions and stuff
         | 
| 235 | 
            +
                          { oneOf: [{ '$ref'.to_sym => self.class.get_ref(value) }] }
         | 
| 233 236 | 
             
                        end
         | 
| 234 | 
            -
                       | 
| 235 | 
            -
                         | 
| 237 | 
            +
                      METADATA_KEYS.select(&metadata.method(:key?)).reduce(type_def) do |definition, key|
         | 
| 238 | 
            +
                        definition.merge(key => metadata[key])
         | 
| 236 239 | 
             
                      end
         | 
| 237 240 | 
             
                    else
         | 
| 238 241 | 
             
                      raise ArgumentError, "Got confusing node #{object} (#{object.class})"
         | 
    
        data/lib/sober_swag/parser.rb
    CHANGED
    
    | @@ -46,8 +46,9 @@ module SoberSwag | |
| 46 46 | 
             
                  when Dry::Types::Constrained
         | 
| 47 47 | 
             
                    bind(Parser.new(@node.type))
         | 
| 48 48 | 
             
                  when Dry::Types::Nominal
         | 
| 49 | 
            +
                    old_meta = @node.primitive.respond_to?(:meta) ? @node.primitive.meta : {}
         | 
| 49 50 | 
             
                    # start off with the moral equivalent of NodeTree[String]
         | 
| 50 | 
            -
                    Nodes::Primitive.new(@node.primitive, @node.meta)
         | 
| 51 | 
            +
                    Nodes::Primitive.new(@node.primitive, old_meta.merge(@node.meta))
         | 
| 51 52 | 
             
                  else
         | 
| 52 53 | 
             
                    # Inside of this case we have a class that is some user-defined type
         | 
| 53 54 | 
             
                    # We put it in our array of found types, and consider it a primitive
         | 
    
        data/lib/sober_swag/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sober_swag
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.13.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Anthony Super
         | 
| @@ -183,7 +183,6 @@ files: | |
| 183 183 | 
             
            - LICENSE.txt
         | 
| 184 184 | 
             
            - README.md
         | 
| 185 185 | 
             
            - Rakefile
         | 
| 186 | 
            -
            - bin/console
         | 
| 187 186 | 
             
            - bin/setup
         | 
| 188 187 | 
             
            - docs/serializers.md
         | 
| 189 188 | 
             
            - example/.gitignore
         | 
    
        data/bin/console
    DELETED
    
    | @@ -1,48 +0,0 @@ | |
| 1 | 
            -
            #!/usr/bin/env ruby
         | 
| 2 | 
            -
            # frozen_string_literal: true
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            require 'bundler/setup'
         | 
| 5 | 
            -
            require 'sober_swag'
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            # You can add fixtures and/or initialization code here to make experimenting
         | 
| 8 | 
            -
            # with your gem easier. You can also use a different console, if you like.
         | 
| 9 | 
            -
            module Types
         | 
| 10 | 
            -
              include Dry.Types()
         | 
| 11 | 
            -
            end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            Bio = SoberSwag.input_object do
         | 
| 14 | 
            -
              attribute :name, primitive(:String).meta(description: 'A very basic bio name')
         | 
| 15 | 
            -
            end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
            Person = SoberSwag.input_object do
         | 
| 18 | 
            -
              attribute :name, primitive(:String).meta(description: 'The full name description')
         | 
| 19 | 
            -
              attribute :age, param(:Integer).constrained(gt: 0).optional.meta(description: 'My cool age')
         | 
| 20 | 
            -
              attribute? :mood, Types::String
         | 
| 21 | 
            -
            end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
            ##
         | 
| 24 | 
            -
            # Demonstration of subclass-style.
         | 
| 25 | 
            -
            class PersonSearch < SoberSwag::InputObject
         | 
| 26 | 
            -
              attribute? :name, Types::String
         | 
| 27 | 
            -
              attribute? :age, Types::Integer
         | 
| 28 | 
            -
            end
         | 
| 29 | 
            -
             | 
| 30 | 
            -
            ##
         | 
| 31 | 
            -
            # Demonstration of subclass-style *and* recursion in structs.
         | 
| 32 | 
            -
            class LinkedList < SoberSwag::InputObject
         | 
| 33 | 
            -
              attribute :value, Types::String
         | 
| 34 | 
            -
              attribute? :next, LinkedList
         | 
| 35 | 
            -
            end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
            Foo = SoberSwag::OutputObject.define do
         | 
| 38 | 
            -
              field :name, primitive(:String)
         | 
| 39 | 
            -
              field :age, primitive(:String)
         | 
| 40 | 
            -
             | 
| 41 | 
            -
              view :foo do
         | 
| 42 | 
            -
                field :bar, primitive(:String).optional
         | 
| 43 | 
            -
              end
         | 
| 44 | 
            -
            end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
            # (If you use this, don't forget to add pry to your Gemfile!)
         | 
| 47 | 
            -
            require 'pry'
         | 
| 48 | 
            -
            Pry.start
         |