Class: Gorails::Commands::Railsbytes
- Inherits:
-
Gorails::Command
- Object
- Gorails::Commands::Railsbytes
- Defined in:
- lib/gorails/commands/railsbytes.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
Instance Method Details
#apply(id) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/gorails/commands/railsbytes.rb', line 9 def call(args, _name) if args.none? list else apply(args.first) end end |
#list ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 |