Permalink
Browse files

A bit more rubyish.

  • Loading branch information...
1 parent a15244a commit 4841827901fa6d6baff5e2bfe05781d12364f867 @botanicus botanicus committed Jul 6, 2012
Showing with 11 additions and 19 deletions.
  1. +0 −2 lib/apiary/cli.rb
  2. +0 −1 lib/apiary/cmd.rb
  3. +2 −4 lib/apiary/commands/base.rb
  4. +8 −11 lib/apiary/commands/preview.rb
  5. +1 −1 lib/apiary/version.rb
View
@@ -2,11 +2,9 @@
require "apiary/cmd"
class Apiary::CLI
-
def self.start(*args)
command = args.shift.strip rescue "help"
Apiary::Command.load
Apiary::Command.run(command, args)
end
-
end
View
@@ -5,7 +5,6 @@
module Apiary
module Command
class CommandFailed < RuntimeError; end
-
def self.commands
@@commands ||= {}
end
@@ -1,9 +1,8 @@
class Apiary::Command::Base
-
attr_reader :args
attr_reader :options
- def initialize(args=[], options={})
+ def initialize(args = [], options = {})
@args = args
@options = options
end
@@ -22,7 +21,7 @@ def self.method_added(method)
# help = extract_help_from_caller(caller.first)
resolved_method = (method.to_s == "index") ? nil : method.to_s
- command = [ self.namespace, resolved_method ].compact.join(":")
+ command = [self.namespace, resolved_method].compact.join(":")
# banner = extract_banner(help) || command
Apiary::Command.register_command(
@@ -37,5 +36,4 @@ def self.method_added(method)
# :options => extract_options(help)
)
end
-
end
@@ -1,27 +1,24 @@
require "apiary/commands/base"
# Display preview of local blueprint file
-#
class Apiary::Command::Preview < Apiary::Command::Base
# preview
#
# Launch web browser and display preview of local blueprint file
- #
def index
+ api_server = ENV.fetch("APIARY_API_HOST") { "api.apiary.io" }
- api_server = ENV['APIARY_API_HOST'] || "api.apiary.io"
- require 'launchy'
- require 'rest_client'
+ require "launchy"
+ require "rest_client"
- headers = {:accept => "text/html",:content_type => "text/plain"}
- response = RestClient.post "https://#{api_server}/blueprint/generate", IO.read('apiary.apib'), headers
+ headers = {:accept => "text/html", :content_type => "text/plain"}
+ response = RestClient.post "https://#{api_server}/blueprint/generate", IO.read("apiary.apib"), headers
- aFile = File.new("/tmp/apiarypreview.html", "w")
- aFile.write(response)
- aFile.close
+ file = File.new("/tmp/apiarypreview.html", "w")
+ file.write(response)
+ file.close
Launchy.open("file:///tmp/apiarypreview.html")
end
-
end
View
@@ -1,3 +1,3 @@
module Apiary
- VERSION = "0.0.1"
+ VERSION ||= "0.0.1"
end

0 comments on commit 4841827

Please sign in to comment.