Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moving all helper methods to a protected section to prevent showing u…

…p in 'ranger help' command
  • Loading branch information...
commit 982dff1dd48edba7165ef5d06ee46b400fc22832 1 parent e84a3cf
@jessmartin jessmartin authored
Showing with 67 additions and 66 deletions.
  1. +67 −66 init.rb
View
133 init.rb
@@ -4,20 +4,20 @@
raise "json gem is missing. Please install json: gem install json"
end
+Heroku::Command::Help.group("Ranger") do |group|
+ group.command "ranger", "show current app status"
+ group.command "ranger:domains", "list domains being monitored"
+ group.command "ranger:domains add <url>", "start monitoring a domain"
+ group.command "ranger:domains remove <url>", "stop monitoring a domain"
+ group.command "ranger:domains clear", "stop monitoring all domains"
+ group.command "ranger:watchers", "list current app watchers"
+ group.command "ranger:watchers add <email>", "add an app watcher"
+ group.command "ranger:watchers remove <email>", "remove an app watcher"
+ group.command "ranger:watchers clear", "remove all app watchers"
+end
+
module Heroku::Command
class Ranger < BaseWithApp
- Help.group("Ranger") do |group|
- group.command "ranger", "show current app status"
- group.command "ranger:domains", "list domains being monitored"
- group.command "ranger:domains add <url>", "start monitoring a domain"
- group.command "ranger:domains remove <url>", "stop monitoring a domain"
- group.command "ranger:domains clear", "stop monitoring all domains"
- group.command "ranger:watchers", "list current app watchers"
- group.command "ranger:watchers add <email>", "add an app watcher"
- group.command "ranger:watchers remove <email>", "remove an app watcher"
- group.command "ranger:watchers clear", "remove all app watchers"
- end
-
def initialize(*args)
super
@config_vars = heroku.config_vars(app)
@@ -26,11 +26,6 @@ def initialize(*args)
@app_owner = heroku.info(app)[:owner]
abort(" ! Please add the ranger addon first.") unless @ranger_api_key
end
-
- def authenticated_resource(path)
- host = "https://rangerapp.com/api/v1"
- RestClient::Resource.new("#{host}#{path}")
- end
def index
if get_status
@@ -51,6 +46,61 @@ def index
end
end
+ def domains
+ if args.empty?
+ domain_list
+ return
+ end
+
+ case args.shift
+ when "add"
+ url = args.shift
+ create_dependency(url)
+ puts "Added #{url} to the monitoring list"
+ return
+ when "remove"
+ url = args.shift
+ remove_url(url)
+ return
+ when "clear"
+ clear_all_dependencies
+ puts "All domains removed from the monitoring list"
+ return
+ end
+ raise(CommandFailed, "usage: heroku ranger:domains <add | remove | clear>")
+ end
+
+ def watchers
+ if args.empty?
+ watchers_list
+ return
+ end
+
+ case args.shift
+ when "add"
+ email = args.shift
+ create_watcher(email)
+ puts "Added #{email} as a watcher"
+ return
+ when "remove"
+ email = args.shift
+ remove_watcher(email)
+ return
+ when "clear"
+ clear_all_watchers
+ puts "All watchers removed"
+ return
+ end
+ raise(CommandFailed, "usage: heroku ranger:watchers <add | remove | clear>")
+ end
+
+ protected
+
+ def authenticated_resource(path)
+ host = "https://rangerapp.com/api/v1"
+ RestClient::Resource.new("#{host}#{path}")
+ end
+
def up_or_down(code)
case code
when 200
@@ -213,54 +263,5 @@ def delete_watcher(id)
false
end
end
-
- def domains
- if args.empty?
- domain_list
- return
- end
-
- case args.shift
- when "add"
- url = args.shift
- create_dependency(url)
- puts "Added #{url} to the monitoring list"
- return
- when "remove"
- url = args.shift
- remove_url(url)
- return
- when "clear"
- clear_all_dependencies
- puts "All domains removed from the monitoring list"
- return
- end
- raise(CommandFailed, "usage: heroku ranger:domains <add | remove | clear>")
- end
-
- def watchers
- if args.empty?
- watchers_list
- return
- end
-
- case args.shift
- when "add"
- email = args.shift
- create_watcher(email)
- puts "Added #{email} as a watcher"
- return
- when "remove"
- email = args.shift
- remove_watcher(email)
- return
- when "clear"
- clear_all_watchers
- puts "All watchers removed"
- return
- end
- raise(CommandFailed, "usage: heroku ranger:watchers <add | remove | clear>")
- end
-
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.