Class: HamlLint::Source
- Inherits:
-
Object
- Object
- HamlLint::Source
- 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
-
#path ⇒ String
readonly
File path associated with the given IO object.
Instance Method Summary collapse
-
#contents ⇒ String
Contents of the given IO object.
-
#initialize(path: nil, io: nil) ⇒ Source
constructor
Wraps an optional IO object and file path to a source object.
-
#stdin? ⇒ boolean
True if we’re reading from stdin rather than a file path.
Constructor Details
#initialize(path: nil, io: nil) ⇒ Source
Wraps an optional IO object and file path to a source object.
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
#path ⇒ String (readonly)
Returns 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
#contents ⇒ String
Returns 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 |
#stdin? ⇒ boolean
Returns true if we’re reading from stdin rather than a file path.
25 26 27 |
# File 'lib/haml_lint/source.rb', line 25 def stdin? !@io.nil? end |