Class: Openapi3Parser::SourceInput::File
- Inherits:
-
Openapi3Parser::SourceInput
- Object
- Openapi3Parser::SourceInput
- Openapi3Parser::SourceInput::File
- Defined in:
- lib/openapi3_parser/source_input/file.rb
Overview
An input of a file on the file system
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
The absolute path to this file.
-
#working_directory ⇒ String
readonly
The abolsute path of the working directory to use when opening relative references to this file.
Attributes inherited from Openapi3Parser::SourceInput
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#initialize(path, working_directory: nil) ⇒ File
constructor
A new instance of File.
-
#inspect ⇒ Object
return [String].
-
#relative_to(source_input) ⇒ String
Attempt to return a shorter relative path to the other source input so we can produce succinct output.
- #resolve_next(reference) ⇒ SourceInput
- #to_s ⇒ String
Methods inherited from Openapi3Parser::SourceInput
Constructor Details
#initialize(path, working_directory: nil) ⇒ File
Returns a new instance of File.
23 24 25 26 27 28 |
# File 'lib/openapi3_parser/source_input/file.rb', line 23 def initialize(path, working_directory: nil) @path = ::File.absolute_path(path) working_directory ||= resolve_working_directory @working_directory = ::File.absolute_path(working_directory) super() end |
Instance Attribute Details
#path ⇒ String (readonly)
The absolute path to this file
14 15 16 |
# File 'lib/openapi3_parser/source_input/file.rb', line 14 def path @path end |
#working_directory ⇒ String (readonly)
The abolsute path of the working directory to use when opening relative references to this file
14 15 16 |
# File 'lib/openapi3_parser/source_input/file.rb', line 14 def working_directory @working_directory end |
Instance Method Details
#==(other) ⇒ Boolean
40 41 42 43 44 45 |
# File 'lib/openapi3_parser/source_input/file.rb', line 40 def ==(other) return false unless other.instance_of?(self.class) path == other.path && working_directory == other.working_directory end |
#inspect ⇒ Object
return [String]
48 49 50 51 |
# File 'lib/openapi3_parser/source_input/file.rb', line 48 def inspect %{#{self.class.name}(path: #{path}, working_directory: } + %{#{working_directory})} end |
#relative_to(source_input) ⇒ String
Attempt to return a shorter relative path to the other source input so we can produce succinct output
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/openapi3_parser/source_input/file.rb', line 62 def relative_to(source_input) other_path = if source_input.respond_to?(:path) ::File.dirname(source_input.path) elsif source_input.respond_to?(:working_directory) source_input.working_directory end return path unless other_path other_path ? relative_path(other_path, path) : path end |
#resolve_next(reference) ⇒ SourceInput
33 34 35 |
# File 'lib/openapi3_parser/source_input/file.rb', line 33 def resolve_next(reference) ResolveNext.call(reference, self, working_directory:) end |
#to_s ⇒ String
54 55 56 |
# File 'lib/openapi3_parser/source_input/file.rb', line 54 def to_s path end |