Class: GridCLI::UpdateCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- GridCLI::UpdateCommand
- Defined in:
- lib/gridcli/commands/update.rb
Instance Attribute Summary
Attributes inherited from BaseCommand
Instance Method Summary collapse
-
#initialize ⇒ UpdateCommand
constructor
A new instance of UpdateCommand.
- #run(args) ⇒ Object
- #run_since_sha(last_sha) ⇒ Object
- #save(posts) ⇒ Object
Methods inherited from BaseCommand
#add_format_option, #add_option, #error, #log, #output_format, #parse_dates, #parse_opts, #pop_arg, #pprint, #usage
Constructor Details
#initialize ⇒ UpdateCommand
Returns a new instance of UpdateCommand.
3 4 5 6 |
# File 'lib/gridcli/commands/update.rb', line 3 def initialize super "update", "Download all messages" add_format_option end |
Instance Method Details
#run(args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gridcli/commands/update.rb', line 8 def run(args) parse_opts args posts = run_since_sha(@stats['last_sha']) total_posts = posts.length @stats['last_sha'] = save(posts) if posts.length > 0 # If we're doing this in chunks, get more while posts.length == 300 posts = run_since_sha(@stats['last_sha']) total_posts += posts.length @stats['last_sha'] = save(posts) if posts.length > 0 end @stats.save puts "Saved #{total_posts} posts. Now up to date." end |
#run_since_sha(last_sha) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gridcli/commands/update.rb', line 27 def run_since_sha(last_sha) GridCLI.hooker.invoke :before_update posts = [] begin if last_sha.nil? log "Trying to download all messages." posts = Post::Message.find(:all) else log "Trying to download all messages since '#{last_sha}'" posts = Post::Message.find(:all, :params => { :id => last_sha }) end rescue ActiveResource::ClientError puts "There was an error updating your messages." end GridCLI.hooker.invoke :after_update, posts end |