Class: Devcenter::Commands::Open
- Defined in:
- lib/devcenter/commands/open.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ Open
constructor
A new instance of Open.
- #run ⇒ Object
- #validate ⇒ Object
Methods inherited from Base
Methods included from Helpers
#article_api_path, #article_path, #article_url?, #broken_link_checks_path, #devcenter_base_url, #get_oauth_token, #html_file_path, #md_file_path, #netrc_path, #search_api_path, #slug_from_article_url, #update_article_path, #validate_article_path, #write_file
Methods included from Logger
Constructor Details
#initialize(*args) ⇒ Open
Returns a new instance of Open.
5 6 7 8 |
# File 'lib/devcenter/commands/open.rb', line 5 def initialize(*args) @slug = args[0] super end |
Instance Method Details
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/devcenter/commands/open.rb', line 16 def run path = article_path(@slug) log "Connecting to #{path}" response = Devcenter::Client.head(:path => path) if response.ok? log "Page found, opening" launchy = Launchy.open(devcenter_base_url + path) launchy.join if launchy.respond_to?(:join) elsif response.redirect? abort "Redirected to #{response.location}" elsif response.not_found? article_not_found!(@slug) end end |
#validate ⇒ Object
10 11 12 13 14 |
# File 'lib/devcenter/commands/open.rb', line 10 def validate unless @slug && !@slug.strip.empty? @validation_errors << 'Please provide a slug (e.g: ps is the slug for https://devcenter.heroku.com/articles/ps)' end end |