Sha256: 9b77256cd6d66a1cc615b4c368aba37203b302a33b8c597ca1b8cdd0fd7be38c

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'ostruct'
require_relative 'store'
require_relative 'api'
require_relative 'pad'

module Hackpad
  module Cli
    module Padlist
      module_function

      def get_list(refresh = false, output = STDOUT)
        all = []
        if refresh || !Store.exists?('padlist')
          output.print 'Refreshing '
          list = Api.list
          list.each do |a|
            output.print '.'
            all << get_pad(a, refresh)
          end
          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
          unless pad.cached?
            pad.load 'txt', false, false
            all << OpenStruct.new(id: a, title: pad.title)
          end
        end
        all
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hackpad-cli-0.1.0 lib/hackpad/cli/padlist.rb