class Gorails::Commands::Railsbytes

Public Class Methods

help() click to toggle source
# File lib/gorails/commands/railsbytes.rb, line 17
      def self.help
        <<~EOF
          View the latest Railsbytes templates or load a template by ID.
          Usage:
            {{command:#{Gorails::TOOL_NAME} railsbytes}}
            {{command:#{Gorails::TOOL_NAME} railsbytes x7msKX}}
        EOF
      end

Public Instance Methods

apply(id) click to toggle source
# File lib/gorails/commands/railsbytes.rb, line 39
def apply(id)
  byte = JSON.parse Net::HTTP.get(URI("https://railsbytes.com/public/templates/#{id}.json"))

  CLI::UI::Frame.open("Railsbyte") do
    puts CLI::UI.fmt "{{green:#{byte["name"]}}} by #{byte["created_by"]}"
    puts byte["short_description"]
    puts

    CLI::UI::Prompt.ask("What would you like to do?") do |handler|
      handler.option("Apply Railsbyte") do |selection|
        puts
        puts "Running Railsbyte..."
        puts

        system "rails app:template LOCATION=\"https://railsbytes.com/script/#{id}\""
      end

      handler.option("View source") do |selection|
        puts
        puts byte["script"]
      end

      handler.option("Exit") { |selection| exit 0 }
    end
  end
end
call(args, _name) click to toggle source
# File lib/gorails/commands/railsbytes.rb, line 9
def call(args, _name)
  if args.none?
    list
  else
    apply(args.first)
  end
end
list() click to toggle source
# File lib/gorails/commands/railsbytes.rb, line 26
def list
  bytes = JSON.parse Net::HTTP.get(URI("https://railsbytes.com/public/templates.json"))

  CLI::UI::Frame.open("Railsbytes") do
    bytes.each do |byte|
      puts CLI::UI.fmt "{{green:#{byte["name"]}}} by #{byte["created_by"]}"
      puts byte["short_description"]
      puts "#{byte["id"]} - #{byte["url"]}"
      puts
    end
  end
end