Sha256: 59b6779d349bcb6a666cb954d22b3492d3f24cc3056085e3d9a6c8916731273b

Contents?: true

Size: 664 Bytes

Versions: 6

Compression:

Stored size: 664 Bytes

Contents

module Troo
  class ListRetrieval
    class << self
      def all
        Troo::List.all
      end

      def default
        new.retrieve
      end

      def retrieve(id = nil)
        new(id).retrieve
      end
    end

    def initialize(id = nil)
      @id = id
    end

    def retrieve
      return default unless id
      by_id || by_external_id || remote
    end

    private
    attr_reader :id

    def default
      Troo::List.default
    end

    def by_id
      Troo::List[id]
    end

    def by_external_id
      Troo::List.first(external_list_id: id)
    end

    def remote
      External::List.fetch(id, { mode: :list }).first
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
troo-0.0.7 lib/troo/models/list_retrieval.rb
troo-0.0.6 lib/troo/models/list_retrieval.rb
troo-0.0.5 lib/troo/models/list_retrieval.rb
troo-0.0.4 lib/troo/models/list_retrieval.rb
troo-0.0.3 lib/troo/models/list_retrieval.rb
troo-0.0.2 lib/troo/models/list_retrieval.rb