lib/hackpad/cli/store.rb in hackpad-cli-0.0.6 vs lib/hackpad/cli/store.rb in hackpad-cli-0.0.7

- old
+ new

@@ -6,18 +6,21 @@ module Cli module Store extend self def prepare(config) - @refresh = config['refresh'] - @dir = File.join(config['configdir'], config['workspace']) - @pads_dir = File.join(@dir, 'pads') - @list_cache = File.join(@dir, 'pads.list') - FileUtils.mkdir_p @dir unless Dir.exists?(@dir) - (Hackpad::Cli::FORMATS + ['meta']).each { |f| FileUtils.mkdir_p File.join(@pads_dir, f) } + @refresh = config[:refresh] + dir = File.join(config[:configdir], config[:workspace]) + @pads_dir = File.join(dir, 'pads') + @list_cache = File.join(dir, 'pads.list') + prepare_dirs @pads_dir end + def prepare_dirs(base) + (Hackpad::Cli::FORMATS + ['meta']).each { |f| FileUtils.mkdir_p File.join(base, f) } + end + def exists?(*path) !@refresh && File.exists?(File.join(@pads_dir, *path)) end def save(pad, ext) @@ -50,11 +53,11 @@ JSON.parse File.read(file) end def read_list File.read(File.join(@pads_dir, 'padlist')).lines.reduce([]) { |a,line| - /(?<id>[a-zA-Z0-9]*) (?<title>.*)/ =~ line - a << OpenStruct.new( id: id, title: title ) + /(?<id>[a-zA-Z0-9]*) (\[(?<cached_at>[-a-zA-Z0-9: ]*)\] )?(?<title>.*)/ =~ line + a << OpenStruct.new( id: id, title: title, cached_at: cached_at ) a } end end