lib/hackpad/cli/padlist.rb in hackpad-cli-0.0.7 vs lib/hackpad/cli/padlist.rb in hackpad-cli-0.1.0

- old
+ new

@@ -1,45 +1,49 @@ require 'ostruct' -require_relative "store" -require_relative "api" -require_relative "pad" +require_relative 'store' +require_relative 'api' +require_relative 'pad' module Hackpad module Cli module Padlist - extend self + module_function - def get_list(refresh=false) + def get_list(refresh = false, output = STDOUT) all = [] - if refresh or !Store.exists? "padlist" - print "Refreshing " + if refresh || !Store.exists?('padlist') + output.print 'Refreshing ' list = Api.list list.each do |a| - print "." - pad = Pad.new a - pad.load 'txt', refresh - all << OpenStruct.new( id: a, title: pad.title ) + output.print '.' + all << get_pad(a, refresh) end - puts " all done." + output.puts ' all done.' Store.save_list all else all = Store.read_list end all end + def get_pad(id, refresh = false) + pad = Pad.new id + pad.load 'txt', refresh + OpenStruct.new(id: id, title: pad.title) + end + def check_list all = [] list = Api.list list.each do |a| pad = Pad.new a - if !pad.is_cached? - all << OpenStruct.new( id: a, title: pad.title ) + unless pad.cached? + pad.load 'txt', false, false + all << OpenStruct.new(id: a, title: pad.title) end end all end end end end -