Class: PactBroker::Integrations::Repository
- Inherits:
-
Object
- Object
- PactBroker::Integrations::Repository
- Includes:
- Repositories::Scopes
- Defined in:
- lib/pact_broker/integrations/repository.rb
Instance Method Summary collapse
- #create_for_pact(consumer_id, provider_id) ⇒ Object
- #delete(consumer_id, provider_id) ⇒ Object
- #find(filter_options = {}, pagination_options = {}, eager_load_associations = []) ⇒ Object
-
#set_contract_data_updated_at(consumer, provider) ⇒ Object
Sets the contract_data_updated_at for the integration(s) as specified by the consumer and provider.
-
#set_contract_data_updated_at_for_multiple_integrations(objects_with_consumer_and_provider) ⇒ Object
Sets the contract_data_updated_at for the integrations as specified by an array of objects which each have a consumer and provider.
Methods included from Repositories::Scopes
#scope_for, #unscoped, #with_no_scope
Instance Method Details
#create_for_pact(consumer_id, provider_id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pact_broker/integrations/repository.rb', line 19 def create_for_pact(consumer_id, provider_id) if Integration.where(consumer_id: consumer_id, provider_id: provider_id).empty? Integration.new( consumer_id: consumer_id, provider_id: provider_id, created_at: Sequel.datetime_class.now, contract_data_updated_at: Sequel.datetime_class.now ).insert_ignore end nil end |
#delete(consumer_id, provider_id) ⇒ Object
31 32 33 |
# File 'lib/pact_broker/integrations/repository.rb', line 31 def delete(consumer_id, provider_id) Integration.where(consumer_id: consumer_id, provider_id: provider_id).delete end |
#find(filter_options = {}, pagination_options = {}, eager_load_associations = []) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/pact_broker/integrations/repository.rb', line 10 def find( = {}, = {}, eager_load_associations = []) query = scope_for(PactBroker::Integrations::Integration).select_all_qualified query = query.filter_by_pacticipant([:query_string]) if [:query_string] query .eager(*eager_load_associations) .order(Sequel.desc(:contract_data_updated_at, nulls: :last)) .() end |
#set_contract_data_updated_at(consumer, provider) ⇒ Object
Sets the contract_data_updated_at for the integration(s) as specified by the consumer and provider
38 39 40 41 42 |
# File 'lib/pact_broker/integrations/repository.rb', line 38 def set_contract_data_updated_at(consumer, provider) Integration .where({ consumer_id: consumer&.id, provider_id: provider.id }.compact ) .update(contract_data_updated_at: Sequel.datetime_class.now) end |
#set_contract_data_updated_at_for_multiple_integrations(objects_with_consumer_and_provider) ⇒ Object
Sets the contract_data_updated_at for the integrations as specified by an array of objects which each have a consumer and provider
47 48 49 50 51 52 |
# File 'lib/pact_broker/integrations/repository.rb', line 47 def set_contract_data_updated_at_for_multiple_integrations(objects_with_consumer_and_provider) consumer_and_provider_ids = objects_with_consumer_and_provider.collect{ | object | [object.consumer.id, object.provider.id] }.uniq Integration .where([:consumer_id, :provider_id] => consumer_and_provider_ids) .update(contract_data_updated_at: Sequel.datetime_class.now) end |