class YAPI::Commands::Init

Public Instance Methods

perform() click to toggle source
# File lib/yapi/commands/init.rb, line 8
def perform
  create_config
end

Private Instance Methods

ask_filename() click to toggle source
# File lib/yapi/commands/init.rb, line 21
def ask_filename
  @filename = prompt.ask("Filename:",
                         convert: :string,
                         default: "#{File.basename(Dir.getwd)}.yapi.yml")
  if File.exist? @filename
    prompt.warn("#{@filename} already exists, please choose another.")
    ask_filename
  end
end
ask_root() click to toggle source
# File lib/yapi/commands/init.rb, line 31
def ask_root
  @root_path = prompt.ask("Root Path:",
                          convert: :string,
                          default: "http://localhost:3000")
end
create_config() click to toggle source
# File lib/yapi/commands/init.rb, line 14
def create_config
  ask_filename
  ask_root
  write_file
  prompt.ok("Created #{@filename}")
end
prompt() click to toggle source
# File lib/yapi/commands/init.rb, line 48
def prompt
  @prompt ||= TTY::Prompt.new(interrupt: :exit, enable_color: false)
end
write_file() click to toggle source
# File lib/yapi/commands/init.rb, line 37
      def write_file
        contents = <<~HEREDOC
          ---
          root: #{@root_path}

          sample_route:
            path: /user
        HEREDOC
        File.write(@filename, contents)
      end