Sha256: f4fa2bcfc9e6c8006e03b4ecd0b890dfb15faa046f5eb585f71eef57f87fabb1

Contents?: true

Size: 1.12 KB

Versions: 26

Compression:

Stored size: 1.12 KB

Contents

require_relative "array_desugarizer"

module Foobara
  module TypeDeclarations
    module Handlers
      class ExtendArrayTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
        # TODO: make a quick way to convert a couple simple procs into a transformer
        class TypeSetToArrayDesugarizer < ArrayDesugarizer
          def applicable?(sugary_type_declaration)
            if sugary_type_declaration.is_a?(::Hash) && sugary_type_declaration.key?(:type)
              extra_keys = sugary_type_declaration.keys - %i[type description]

              return false if extra_keys.any?

              type = sugary_type_declaration[:type]

              if type.is_a?(::Array)
                super(type)
              end
            end
          end

          def desugarize(sugary_type_declaration)
            strict_type_declaration = super(sugary_type_declaration[:type])

            if sugary_type_declaration.key?(:description)
              strict_type_declaration[:description] = sugary_type_declaration[:description]
            end

            strict_type_declaration
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.25 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.24 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.23 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.22 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.21 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.20 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.19 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.18 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.17 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.16 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.15 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.14 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.13 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.12 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.11 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.10 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.9 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.8 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
foobara-0.0.7 projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb