Class: ViewSpec::SourceFile
- Inherits:
-
Object
- Object
- ViewSpec::SourceFile
- Defined in:
- lib/view_spec/source_file.rb
Instance Attribute Summary collapse
-
#absolute_path ⇒ Object
(also: #to_pathname)
readonly
Returns the value of attribute absolute_path.
Instance Method Summary collapse
- #app_path ⇒ Object
-
#initialize(absolute_path) ⇒ SourceFile
constructor
A new instance of SourceFile.
- #lang_from_line(lineno, fallback) ⇒ Object
- #line(lineno) ⇒ Object
- #lookup_path ⇒ Object
- #normalized_name ⇒ Object
- #relative_path ⇒ Object
- #spec_file? ⇒ Boolean
Constructor Details
#initialize(absolute_path) ⇒ SourceFile
Returns a new instance of SourceFile.
8 9 10 |
# File 'lib/view_spec/source_file.rb', line 8 def initialize(absolute_path) @absolute_path = Pathname(absolute_path) end |
Instance Attribute Details
#absolute_path ⇒ Object (readonly) Also known as: to_pathname
Returns the value of attribute absolute_path.
3 4 5 |
# File 'lib/view_spec/source_file.rb', line 3 def absolute_path @absolute_path end |
Instance Method Details
#app_path ⇒ Object
25 26 27 |
# File 'lib/view_spec/source_file.rb', line 25 def app_path absolute_path.relative_path_from(Rails.root) end |
#lang_from_line(lineno, fallback) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/view_spec/source_file.rb', line 33 def lang_from_line(lineno, fallback) unless lineno.nil? source_line = line(lineno) if source_line.present? tag = Utils.heredoc_tag(source_line) return tag.downcase.to_sym if tag.present? end end fallback end |
#line(lineno) ⇒ Object
45 46 47 |
# File 'lib/view_spec/source_file.rb', line 45 def line(lineno) File.readlines(absolute_path)[lineno.to_i - 1] end |
#lookup_path ⇒ Object
20 21 22 23 |
# File 'lib/view_spec/source_file.rb', line 20 def lookup_path relative_dirname = relative_path.dirname.to_s.delete_prefix(".") [relative_dirname.presence, normalized_name].compact.join("/") end |
#normalized_name ⇒ Object
12 13 14 |
# File 'lib/view_spec/source_file.rb', line 12 def normalized_name basename(".rb").to_s.delete_suffix(ViewSpec.config.spec_file_suffix) end |
#relative_path ⇒ Object
16 17 18 |
# File 'lib/view_spec/source_file.rb', line 16 def relative_path spec_file? ? absolute_path.relative_path_from(base_path) : app_path end |
#spec_file? ⇒ Boolean
29 30 31 |
# File 'lib/view_spec/source_file.rb', line 29 def spec_file? absolute_path.to_s.end_with?("#{ViewSpec.config.spec_file_suffix}.rb") end |