class YAPI::Commands::Fetch

Public Class Methods

new(arg) click to toggle source
# File lib/yapi/commands/fetch.rb, line 10
def initialize(arg)
  match = arg.match(/(.*?):?(\d+)?$/)
  if match
    _, @filename, @line_number = match.to_a
  else
    @filename = arg
  end
rescue StandardError => e
  puts e
end

Public Instance Methods

config() click to toggle source
# File lib/yapi/commands/fetch.rb, line 52
def config
  @config ||= YAPI::Config.new(@filename)
end
find_route_name() click to toggle source
# File lib/yapi/commands/fetch.rb, line 33
def find_route_name
  row = @line_number.to_i
  while row > 0 do
    match = lines[row - 1].match(/(^\S.*):$/)
    return match[1] if match
    row -= 1
  end
end
lines() click to toggle source
# File lib/yapi/commands/fetch.rb, line 48
def lines
  @lines ||= File.readlines(@filename)
end
perform() click to toggle source
# File lib/yapi/commands/fetch.rb, line 21
def perform
  YAPI::Fetcher.new(config, route_name).perform
end
prompt() click to toggle source
# File lib/yapi/commands/fetch.rb, line 56
def prompt
  @prompt ||= TTY::Prompt.new(active_color: :bold, interrupt: :exit)
end
prompt_route_name() click to toggle source
# File lib/yapi/commands/fetch.rb, line 42
def prompt_route_name
  prompt.select("Choose request to run (Ctrl-C to exit):",
                config.requests,
                filter: true)
end
route_name() click to toggle source
# File lib/yapi/commands/fetch.rb, line 25
def route_name
  if @line_number
    find_route_name
  else
    prompt_route_name
  end
end