Sha256: 0ee8975ec026fa4e16f6fbd41c5c514468e23b0c9e1d092c389760eac4b22006

Contents?: true

Size: 965 Bytes

Versions: 27

Compression:

Stored size: 965 Bytes

Contents

module Fulmar
  module Service
    # Provides internal helper methods
    class HelperService
      class << self
        ##
        # Reverse file lookup in path
        # @param path [String]
        # @param filename [String]
        def reverse_file_lookup(path, filename)
          paths = get_parent_directory_paths(path)

          paths.each do |directory|
            file_path = directory + '/' + filename
            return file_path if File.exist? file_path
          end

          false
        end

        private

        ##
        # Get paths of each parent directory
        # @param path [String]
        # @param paths [Array]
        # @return [Array] A list of paths
        def get_parent_directory_paths(path, paths = [])
          paths << path

          parent_dir_path = File.expand_path('..', path)

          parent_dir_path == '/' ? paths : get_parent_directory_paths(parent_dir_path, paths)
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
fulmar-2.2.0 lib/fulmar/service/helper_service.rb
fulmar-2.1.2 lib/fulmar/service/helper_service.rb
fulmar-2.1.1 lib/fulmar/service/helper_service.rb
fulmar-2.1.0 lib/fulmar/service/helper_service.rb
fulmar-2.0.2 lib/fulmar/service/helper_service.rb
fulmar-2.0.1 lib/fulmar/service/helper_service.rb
fulmar-2.0.0 lib/fulmar/service/helper_service.rb
fulmar-1.10.1 lib/fulmar/service/helper_service.rb
fulmar-1.10.0 lib/fulmar/service/helper_service.rb
fulmar-1.9.2 lib/fulmar/service/helper_service.rb
fulmar-1.9.1 lib/fulmar/service/helper_service.rb
fulmar-1.9.0 lib/fulmar/service/helper_service.rb
fulmar-1.8.15 lib/fulmar/service/helper_service.rb
fulmar-1.8.14 lib/fulmar/service/helper_service.rb
fulmar-1.8.13 lib/fulmar/service/helper_service.rb
fulmar-1.8.12 lib/fulmar/service/helper_service.rb
fulmar-1.8.11 lib/fulmar/service/helper_service.rb
fulmar-1.8.10 lib/fulmar/service/helper_service.rb
fulmar-1.8.9 lib/fulmar/service/helper_service.rb
fulmar-1.8.8 lib/fulmar/service/helper_service.rb