Class: Dato::Local::Loader
- Inherits:
-
Object
- Object
- Dato::Local::Loader
- Defined in:
- lib/dato/local/loader.rb
Constant Summary collapse
- PUSHER_API_KEY =
'75e6ef0fe5d39f481626'
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#entities_repo ⇒ Object
readonly
Returns the value of attribute entities_repo.
-
#items_repo ⇒ Object
readonly
Returns the value of attribute items_repo.
-
#preview_mode ⇒ Object
readonly
Returns the value of attribute preview_mode.
Instance Method Summary collapse
-
#initialize(client, preview_mode = false) ⇒ Loader
constructor
A new instance of Loader.
- #load ⇒ Object
- #stop_watch ⇒ Object
- #watch(&block) ⇒ Object
Constructor Details
#initialize(client, preview_mode = false) ⇒ Loader
Returns a new instance of Loader.
18 19 20 21 22 23 |
# File 'lib/dato/local/loader.rb', line 18 def initialize(client, preview_mode = false) @client = client @preview_mode = preview_mode @entities_repo = EntitiesRepo.new @items_repo = ItemsRepo.new(@entities_repo) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
11 12 13 |
# File 'lib/dato/local/loader.rb', line 11 def client @client end |
#entities_repo ⇒ Object (readonly)
Returns the value of attribute entities_repo.
12 13 14 |
# File 'lib/dato/local/loader.rb', line 12 def entities_repo @entities_repo end |
#items_repo ⇒ Object (readonly)
Returns the value of attribute items_repo.
13 14 15 |
# File 'lib/dato/local/loader.rb', line 13 def items_repo @items_repo end |
#preview_mode ⇒ Object (readonly)
Returns the value of attribute preview_mode.
14 15 16 |
# File 'lib/dato/local/loader.rb', line 14 def preview_mode @preview_mode end |
Instance Method Details
#load ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dato/local/loader.rb', line 25 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 |
#stop_watch ⇒ Object
65 66 67 |
# File 'lib/dato/local/loader.rb', line 65 def stop_watch pusher.disconnect if pusher && pusher.connected end |
#watch(&block) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dato/local/loader.rb', line 41 def watch(&block) site_id = client.get('/site')['data']['id'] return if pusher && pusher.connected channel_name = if client.environment "private-site-#{site_id}-environment-#{client.environment}" else "private-site-#{site_id}" end pusher.subscribe(channel_name) bind_on_site_upsert(&block) bind_on_item_destroy(&block) bind_on_item_upsert(&block) bind_on_item_type_upsert(&block) bind_on_item_type_destroy(&block) bind_on_upload_upsert(&block) bind_on_upload_destroy(&block) pusher.connect(true) end |