Module: Splot::CorrespondingFile
- Extended by:
- CorrespondingFile
- Included in:
- CorrespondingFile
- Defined in:
- lib/splot/corresponding_file.rb
Instance Method Summary collapse
-
#extract_gem_name(lib_file) ⇒ Object
my_gem/my_namespace/foo.rb -> my_namespace/foo.rb.
- #fetch(file) ⇒ Object
- #file_exists?(file) ⇒ Boolean
- #try_file(test_path) ⇒ Object
Instance Method Details
#extract_gem_name(lib_file) ⇒ Object
my_gem/my_namespace/foo.rb -> my_namespace/foo.rb
34 35 36 |
# File 'lib/splot/corresponding_file.rb', line 34 def extract_gem_name(lib_file) File.join lib_file.split(File::Separator, 2).tap(&:shift) end |
#fetch(file) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/splot/corresponding_file.rb', line 5 def fetch(file) catch :test_file do root_path = Pathname.new File. Dir.pwd file_path = Pathname.new File. file relative_path = file_path.relative_path_from(root_path).to_s if %r{\Alib/(?<bit>.*)\.rb} =~ relative_path ['test', 'spec'].each do |e| try_file "#{e}/lib/#{bit}_#{e}.rb" try_file "#{e}/#{bit}_#{e}.rb" bit_without_gem_name = extract_gem_name bit try_file "#{e}/lib/#{bit_without_gem_name}_#{e}.rb" try_file "#{e}/#{bit_without_gem_name}_#{e}.rb" end end if %r{\Aapp/(?<subdir>[a-z_]+)/(?<bit>.*)\.rb} =~ relative_path ['test', 'spec'].each do |e| alternate_subdir = { models: "unit", controllers: "functional", }[subdir.to_sym] try_file "#{e}/#{subdir}/#{bit}_#{e}.rb" try_file "#{e}/#{alternate_subdir}/#{bit}_#{e}.rb" if alternate_subdir end end file end end |
#file_exists?(file) ⇒ Boolean
42 43 44 |
# File 'lib/splot/corresponding_file.rb', line 42 def file_exists?(file) File.size? file end |
#try_file(test_path) ⇒ Object
38 39 40 |
# File 'lib/splot/corresponding_file.rb', line 38 def try_file(test_path) throw :test_file, test_path if file_exists? test_path end |