class Openapi3Parser::SourceInput::Raw

An input of data (typically a Hash) to for initialising an OpenAPI document. Most likely used in development scenarios when you want to test things without creating/tweaking an OpenAPI source file

@attr_reader [Object] raw_input The data for the document @attr_reader [String, nil] base_url A url to be used for

resolving relative
references

@attr_reader [String, nil] working_directory A path to be used for

resolving relative
references

Attributes

base_url[R]
raw_input[R]
working_directory[R]

Public Class Methods

new(raw_input, base_url: nil, working_directory: nil) click to toggle source

@param [Object] raw_input @param [String, nil] base_url @param [String, nil] working_directory

Calls superclass method Openapi3Parser::SourceInput::new
# File lib/openapi3_parser/source_input/raw.rb, line 24
def initialize(raw_input, base_url: nil, working_directory: nil)
  @raw_input = raw_input
  @base_url = base_url
  working_directory ||= resolve_working_directory
  @working_directory = ::File.absolute_path(working_directory)
  super()
end

Public Instance Methods

==(other) click to toggle source

@see SourceInput#other @param [SourceInput] other @return [Boolean]

# File lib/openapi3_parser/source_input/raw.rb, line 45
def ==(other)
  return false unless other.instance_of?(self.class)

  raw_input == other.raw_input &&
    base_url == other.base_url &&
    working_directory == other.working_directory
end
inspect() click to toggle source

return [String]

# File lib/openapi3_parser/source_input/raw.rb, line 54
def inspect
  %{#{self.class.name}(input: #{raw_input.inspect}, base_url: } +
    %{#{base_url}, working_directory: #{working_directory})}
end
resolve_next(reference) click to toggle source

@see SourceInput#resolve_next @param [Source::Reference] reference @return [SourceInput]

# File lib/openapi3_parser/source_input/raw.rb, line 35
def resolve_next(reference)
  ResolveNext.call(reference,
                   self,
                   base_url: base_url,
                   working_directory: working_directory)
end
to_s() click to toggle source

@return [String]

# File lib/openapi3_parser/source_input/raw.rb, line 60
def to_s
  raw_input.to_s
end

Private Instance Methods

input_to_string(input) click to toggle source
# File lib/openapi3_parser/source_input/raw.rb, line 83
def input_to_string(input)
  return input.read if input.respond_to?(:read)
  return input.to_s if input.respond_to?(:to_s)

  input
end
parse_contents() click to toggle source
# File lib/openapi3_parser/source_input/raw.rb, line 74
def parse_contents
  return raw_input if raw_input.respond_to?(:keys)

  StringParser.call(
    input_to_string(raw_input),
    raw_input.respond_to?(:path) ? ::File.basename(raw_input.path) : nil
  )
end
resolve_working_directory() click to toggle source
# File lib/openapi3_parser/source_input/raw.rb, line 66
def resolve_working_directory
  if raw_input.respond_to?(:path)
    ::File.dirname(raw_input)
  else
    Dir.pwd
  end
end