Class: Openapi3Parser::SourceInput::Raw

Inherits:
Openapi3Parser::SourceInput show all
Defined in:
lib/openapi3_parser/source_input/raw.rb

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Openapi3Parser::SourceInput

#access_error, #parse_error

Instance Method Summary collapse

Methods inherited from Openapi3Parser::SourceInput

#available?, #contents, #relative_to

Constructor Details

#initialize(raw_input, base_url: nil, working_directory: nil) ⇒ Raw

Returns a new instance of Raw.

Parameters:

  • raw_input (Object)
  • base_url (String, nil) (defaults to: nil)
  • working_directory (String, nil) (defaults to: nil)


24
25
26
27
28
29
30
# 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

Instance Attribute Details

#base_urlString? (readonly)

A url to be used for resolving relative references

Returns:

  • (String, nil)

    the current value of base_url



18
19
20
# File 'lib/openapi3_parser/source_input/raw.rb', line 18

def base_url
  @base_url
end

#raw_inputObject (readonly)

The data for the document

Returns:

  • (Object)

    the current value of raw_input



18
19
20
# File 'lib/openapi3_parser/source_input/raw.rb', line 18

def raw_input
  @raw_input
end

#working_directoryString? (readonly)

A path to be used for resolving relative references

Returns:

  • (String, nil)

    the current value of working_directory



18
19
20
# File 'lib/openapi3_parser/source_input/raw.rb', line 18

def working_directory
  @working_directory
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)

See Also:

  • SourceInput#other


45
46
47
48
49
50
51
# 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

#inspectObject

return [String]



54
55
56
57
# 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) ⇒ SourceInput

Parameters:

Returns:

See Also:



35
36
37
38
39
40
# File 'lib/openapi3_parser/source_input/raw.rb', line 35

def resolve_next(reference)
  ResolveNext.call(reference,
                   self,
                   base_url:,
                   working_directory:)
end

#to_sString

Returns:

  • (String)


60
61
62
# File 'lib/openapi3_parser/source_input/raw.rb', line 60

def to_s
  raw_input.to_s
end