class Agave::Local::Loader

Attributes

client[R]
entities_repo[R]
items_repo[R]
preview_mode[R]

Public Class Methods

new(client, preview_mode = false) click to toggle source
# File lib/agave/local/loader.rb, line 13
def initialize(client, preview_mode = false)
  @client = client
  @preview_mode = preview_mode
  @entities_repo = EntitiesRepo.new
  @items_repo = ItemsRepo.new(@entities_repo)
end

Public Instance Methods

load() click to toggle source
# File lib/agave/local/loader.rb, line 20
def load
  threads = [
    Thread.new { Thread.current[:output] = site },
    Thread.new { Thread.current[:output] = all_items },
    Thread.new { Thread.current[:output] = all_uploads }
  ]

  results = threads.map do |t|
    t.join
    t[:output]
  end

  @entities_repo = EntitiesRepo.new(*results)
  @items_repo = ItemsRepo.new(@entities_repo)
end

Private Instance Methods

all_items() click to toggle source
# File lib/agave/local/loader.rb, line 43
def all_items
  client.items.all(
    { version: preview_mode ? 'latest' : 'published' },
    deserialize_response: false,
    all_pages: true
  )
end
all_uploads() click to toggle source
# File lib/agave/local/loader.rb, line 51
def all_uploads
  client.uploads.all(
    { "filter[type]" => "used" },
    deserialize_response: false,
    all_pages: true
  )
end
site() click to toggle source
# File lib/agave/local/loader.rb, line 38
def site
  include = ['item_types', 'item_types.fields']
  client.request(:get, '/api/site', include: include)
end