Class: ViewSpec::SourceFile

Inherits:
Object
  • Object
show all
Defined in:
lib/view_spec/source_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pathObject (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_pathObject



25
26
27
# File 'lib/view_spec/source_file.rb', line 25

def app_path
  absolute_path.relative_path_from(Rails.root)
end

#lookup_pathObject



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_nameObject



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_pathObject



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

Returns:



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