Sha256: 2b06230fb89ab6083387dd5a86431f9c41df671456a52eb1f4283b1b97959eec

Contents?: true

Size: 960 Bytes

Versions: 3

Compression:

Stored size: 960 Bytes

Contents

module SoberSwag
  ##
  # A variant of Dry::Struct that allows you to set a "model name" that is publically visible.
  # If you do not set one, it will be the Ruby class name, with any '::' replaced with a '.'.
  #
  # This otherwise behaves exactly like a Dry::Struct.
  # Please see the documentation for that class to see how it works.
  class InputObject < Dry::Struct
    transform_keys(&:to_sym)

    class << self
      ##
      # The name to use for this type in external documentation.
      def identifier(arg = nil)
        @identifier = arg if arg

        @identifier || name.to_s.gsub('::', '.')
      end

      def meta(*args)
        super(*args).tap do |result|
          result.identifier(identifier) if result.is_a?(Class) # pass on identifier
        end
      end

      def primitive(sym)
        SoberSwag::Types.const_get(sym)
      end

      def param(sym)
        SoberSwag::Types::Params.const_get(sym)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sober_swag-0.14.0 lib/sober_swag/input_object.rb
sober_swag-0.13.0 lib/sober_swag/input_object.rb
sober_swag-0.12.0 lib/sober_swag/input_object.rb