Class: Keinaufwand::Sync::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/keinaufwand/sync_core/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



6
7
8
9
10
11
12
# File 'lib/keinaufwand/sync_core/configuration.rb', line 6

def initialize
  @record_class = -> { Keinaufwand::Record }
  @sync_state_class = -> { Keinaufwand::SyncState }
  @asset_class = -> { Keinaufwand::Asset }
  @webhook_receipt_class = -> { Keinaufwand::WebhookReceipt }
  @local_asset_path_prefix = "/media"
end

Instance Attribute Details

#asset_classObject

Returns the value of attribute asset_class.



4
5
6
# File 'lib/keinaufwand/sync_core/configuration.rb', line 4

def asset_class
  @asset_class
end

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/keinaufwand/sync_core/configuration.rb', line 4

def client
  @client
end

#config_pathObject

Returns the value of attribute config_path.



4
5
6
# File 'lib/keinaufwand/sync_core/configuration.rb', line 4

def config_path
  @config_path
end

#local_asset_path_prefixObject

Returns the value of attribute local_asset_path_prefix.



4
5
6
# File 'lib/keinaufwand/sync_core/configuration.rb', line 4

def local_asset_path_prefix
  @local_asset_path_prefix
end

#record_classObject

Returns the value of attribute record_class.



4
5
6
# File 'lib/keinaufwand/sync_core/configuration.rb', line 4

def record_class
  @record_class
end

#resourcesObject

Returns the value of attribute resources.



4
5
6
# File 'lib/keinaufwand/sync_core/configuration.rb', line 4

def resources
  @resources
end

#storage_adapterObject

Returns the value of attribute storage_adapter.



4
5
6
# File 'lib/keinaufwand/sync_core/configuration.rb', line 4

def storage_adapter
  @storage_adapter
end

#sync_state_classObject

Returns the value of attribute sync_state_class.



4
5
6
# File 'lib/keinaufwand/sync_core/configuration.rb', line 4

def sync_state_class
  @sync_state_class
end

#webhook_receipt_classObject

Returns the value of attribute webhook_receipt_class.



4
5
6
# File 'lib/keinaufwand/sync_core/configuration.rb', line 4

def webhook_receipt_class
  @webhook_receipt_class
end

#webhook_secretObject

Returns the value of attribute webhook_secret.



4
5
6
# File 'lib/keinaufwand/sync_core/configuration.rb', line 4

def webhook_secret
  @webhook_secret
end

Instance Method Details

#app_configObject



49
50
51
52
53
# File 'lib/keinaufwand/sync_core/configuration.rb', line 49

def app_config
  return {}.with_indifferent_access unless resolved_config_path && File.exist?(resolved_config_path)

  YAML.load_file(resolved_config_path).with_indifferent_access
end

#clear!Object



55
56
57
58
59
60
# File 'lib/keinaufwand/sync_core/configuration.rb', line 55

def clear!
  resolve(:asset_class)&.delete_all
  fetch(:record_class).delete_all
  fetch(:sync_state_class).delete_all
  resolve(:webhook_receipt_class)&.delete_all
end

#index_managerObject



31
32
33
# File 'lib/keinaufwand/sync_core/configuration.rb', line 31

def index_manager
  IndexManager.new(sync_config: sync_config, adapter: storage_adapter || :sqlite3)
end

#resolved_webhook_secretObject



45
46
47
# File 'lib/keinaufwand/sync_core/configuration.rb', line 45

def resolved_webhook_secret
  fetch(:webhook_secret)
end

#sync_configObject



25
26
27
28
29
# File 'lib/keinaufwand/sync_core/configuration.rb', line 25

def sync_config
  return @sync_config if defined?(@sync_config)

  @sync_config = Array(app_config.dig(:sync, :resources))
end

#sync_serviceObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/keinaufwand/sync_core/configuration.rb', line 14

def sync_service
  SyncService.new(
    client: fetch(:client),
    record_class: fetch(:record_class),
    sync_state_class: fetch(:sync_state_class),
    receipt_class: resolve(:webhook_receipt_class),
    resources: resources || sync_config.map { |item| item.fetch("model") }.presence || SyncService::DEFAULT_RESOURCES,
    asset_class: resolve(:asset_class)
  )
end

#webhook_processor(payload) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/keinaufwand/sync_core/configuration.rb', line 35

def webhook_processor(payload)
  WebhookProcessor.new(
    payload: payload,
    record_class: fetch(:record_class),
    receipt_class: fetch(:webhook_receipt_class),
    resources: resources || sync_config.map { |item| item.fetch("model") }.presence || SyncService::DEFAULT_RESOURCES,
    asset_class: resolve(:asset_class)
  )
end