Class: HamlLint::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/haml_lint/source.rb

Overview

Wrapper class representing a single target for HamlLint::Runner to run against, comprised of a file path to eventually read from, and an optional IO argument to override with.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: nil, io: nil) ⇒ Source

Wraps an optional IO object and file path to a source object.

Parameters:

  • path (String) (defaults to: nil)
  • io (IO) (defaults to: nil)


14
15
16
17
# File 'lib/haml_lint/source.rb', line 14

def initialize(path: nil, io: nil)
  @path = path
  @io = io
end

Instance Attribute Details

#pathString (readonly)

Returns File path associated with the given IO object.

Returns:

  • (String)

    File path associated with the given IO object.



8
9
10
# File 'lib/haml_lint/source.rb', line 8

def path
  @path
end

Instance Method Details

#contentsString

Returns Contents of the given IO object.

Returns:

  • (String)

    Contents of the given IO object.



20
21
22
# File 'lib/haml_lint/source.rb', line 20

def contents
  @contents ||= @io&.read || File.read(path)
end