module Faraday::CLI::MiddlewareFetcher

Constants

NAME_PATH_MATCHER

Public Instance Methods

extend!(faraday_connection_builder, *config_file_paths) click to toggle source
# File lib/faraday/cli/middleware_fetcher.rb, line 9
def extend!(faraday_connection_builder, *config_file_paths)
  container = Faraday::CLI::MiddlewareFetcher::Container.new(faraday_connection_builder)
  get_file_paths(config_file_paths).each { |file_path| container.merge!(file_path) }
end

Protected Instance Methods

get_file_paths(config_file_paths) click to toggle source
# File lib/faraday/cli/middleware_fetcher.rb, line 16
def get_file_paths(config_file_paths)
  case

    when !config_file_paths.empty?
      config_file_paths.reduce([]) do |file_paths, given_path|
        if File.directory?(given_path)
          given_path = File.join(given_path,'*.rb')
        end

        file_paths.push(*Dir.glob(given_path)); file_paths
      end

    when !(file_paths = fetch_file_paths(Dir.pwd)).empty?
      file_paths

    when !(file_paths = fetch_file_paths_from_folder(Dir.pwd)).empty?
      file_paths

    when !(file_paths = fetch_file_paths(PWD.pwd)).empty?
      file_paths

    when !(file_paths = fetch_file_paths_from_folder(PWD.pwd)).empty?
      file_paths

    when !(file_paths = fetch_file_paths(ENV['HOME'])).empty?
      file_paths

    when !(file_paths = fetch_file_paths_from_folder(ENV['HOME'])).empty?
      file_paths

    else
      []

  end
end

Private Instance Methods

fetch_file_paths(*from_folder) click to toggle source
# File lib/faraday/cli/middleware_fetcher.rb, line 58
def fetch_file_paths(*from_folder)
  select_file_paths(Dir.glob(File.join(*from_folder, NAME_PATH_MATCHER)))
end
fetch_file_paths_from_folder(*from_folder) click to toggle source
# File lib/faraday/cli/middleware_fetcher.rb, line 54
def fetch_file_paths_from_folder(*from_folder)
  select_file_paths(Dir.glob(File.join(*from_folder,NAME_PATH_MATCHER, '*.{rb,ru}')))
end
select_file_paths(file_paths) click to toggle source
# File lib/faraday/cli/middleware_fetcher.rb, line 62
def select_file_paths(file_paths)
  file_paths.select { |path| File.exists?(path) and not File.directory?(path)  }
end