Sha256: 56820829f452ac0617a7a97ad9657c62b35ceb759841ad1447d31cf62dda3247

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

module Troo
  module Commands
    class RefreshAll
      # @return [String]
      def self.dispatch
        new.refresh_all
      end

      # @return [String]
      def refresh_all
        return success if refreshed?
        failure
      end

      private

      def success
        'All local data refreshed.'
      end

      def failure
        'Cannot refresh all local data.'
      end

      def refreshed?
        return false if resources.none?
        Troo::Refresh.completed!
        true
      end

      def resources
        @resources ||= external_ids.map do |id|
          Retrieval::Remote.fetch(Remote::Board, id, mode: :board)

          Retrieval::Remote.fetch(Remote::Comment, id, mode: :board)
        end
      end

      def external_ids
        all_boards.map(&:id)
      end

      def all_boards
        @boards ||= Retrieval::Remote
          .fetch(Remote::Board, nil, options)
      end

      def options
        {
          mode:    :all,
          persist: false
        }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
troo-0.0.13 lib/troo/cli/commands/refresh/all.rb
troo-0.0.12 lib/troo/cli/commands/refresh/all.rb
troo-0.0.11 lib/troo/cli/commands/refresh/all.rb