Class: Keinaufwand::Sync::Configuration
- Inherits:
-
Object
- Object
- Keinaufwand::Sync::Configuration
- Defined in:
- lib/keinaufwand/sync_core/configuration.rb
Instance Attribute Summary collapse
-
#asset_class ⇒ Object
Returns the value of attribute asset_class.
-
#client ⇒ Object
Returns the value of attribute client.
-
#config_path ⇒ Object
Returns the value of attribute config_path.
-
#local_asset_path_prefix ⇒ Object
Returns the value of attribute local_asset_path_prefix.
-
#record_class ⇒ Object
Returns the value of attribute record_class.
-
#resources ⇒ Object
Returns the value of attribute resources.
-
#storage_adapter ⇒ Object
Returns the value of attribute storage_adapter.
-
#sync_state_class ⇒ Object
Returns the value of attribute sync_state_class.
-
#webhook_receipt_class ⇒ Object
Returns the value of attribute webhook_receipt_class.
-
#webhook_secret ⇒ Object
Returns the value of attribute webhook_secret.
Instance Method Summary collapse
- #app_config ⇒ Object
- #clear! ⇒ Object
- #index_manager ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #resolved_webhook_secret ⇒ Object
- #sync_config ⇒ Object
- #sync_service(output: nil) ⇒ Object
- #webhook_processor(payload) ⇒ Object
Constructor Details
#initialize ⇒ 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_class ⇒ Object
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 |
#client ⇒ Object
Returns the value of attribute client.
4 5 6 |
# File 'lib/keinaufwand/sync_core/configuration.rb', line 4 def client @client end |
#config_path ⇒ Object
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_prefix ⇒ Object
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_class ⇒ Object
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 |
#resources ⇒ Object
Returns the value of attribute resources.
4 5 6 |
# File 'lib/keinaufwand/sync_core/configuration.rb', line 4 def resources @resources end |
#storage_adapter ⇒ Object
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_class ⇒ Object
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_class ⇒ Object
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_secret ⇒ Object
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_config ⇒ Object
50 51 52 53 54 |
# File 'lib/keinaufwand/sync_core/configuration.rb', line 50 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
56 57 58 59 60 61 |
# File 'lib/keinaufwand/sync_core/configuration.rb', line 56 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_manager ⇒ Object
32 33 34 |
# File 'lib/keinaufwand/sync_core/configuration.rb', line 32 def index_manager IndexManager.new(sync_config: sync_config, adapter: storage_adapter || :sqlite3) end |
#resolved_webhook_secret ⇒ Object
46 47 48 |
# File 'lib/keinaufwand/sync_core/configuration.rb', line 46 def resolved_webhook_secret fetch(:webhook_secret) end |
#sync_config ⇒ Object
26 27 28 29 30 |
# File 'lib/keinaufwand/sync_core/configuration.rb', line 26 def sync_config return @sync_config if defined?(@sync_config) @sync_config = Array(app_config.dig(:sync, :resources)) end |
#sync_service(output: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/keinaufwand/sync_core/configuration.rb', line 14 def sync_service(output: nil) 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), output: output ) end |
#webhook_processor(payload) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/keinaufwand/sync_core/configuration.rb', line 36 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 |