Class: Devcenter::Commands::Pull
- Defined in:
- lib/devcenter/commands/pull.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ Pull
constructor
A new instance of Pull.
- #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) ⇒ Pull
Returns a new instance of Pull.
5 6 7 8 9 |
# File 'lib/devcenter/commands/pull.rb', line 5 def initialize(*args) @slug = slug_from_article_url(args[0]) @force_overwrite = args[1] super end |
Instance Method Details
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/devcenter/commands/pull.rb', line 17 def run response = Devcenter::Client.get(path: article_api_path(@slug)) article_received = response.ok? && response.body['article'] && response.body['article']['id'] article_not_found!(@slug) unless article_received article = response.body['article'] = {'title' => article['title'], 'id' => article['id']} file_path = md_file_path(@slug) unless @force_overwrite cancel_save = File.exists?(file_path) && !agree("The file #{file_path} already exists - overwrite? (yes/no)") return if cancel_save end file_content = [YAML.dump(), article['content']].join("\n\n") write_file(file_path, file_content) say "\"#{metadata['title']}\" article saved as #{file_path}" end |
#validate ⇒ Object
11 12 13 14 15 |
# File 'lib/devcenter/commands/pull.rb', line 11 def validate unless @slug && !@slug.strip.empty? @validation_errors << 'Please provide an article slug or full (e.g: ps or https://devcenter.heroku.com/articles/ps)' end end |