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?, #devcenter_base_url, #html_file_path, #md_file_path, #search_api_path, #slug_from_article_url, #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 30 |
# File 'lib/devcenter/commands/open.rb', line 16 def run path = article_path(@slug) log "Connecting to #{path}" head = Devcenter::Client.head(:path => path) case head.status when 200 log "Page found, opening" launchy = Launchy.open(devcenter_base_url + path) launchy.join if launchy.respond_to?(:join) when 301, 302 say "Redirected to #{head.headers['Location']}" when 404 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 |