Module: Sipity::Commands::AdditionalAttributeCommands

Extended by:
ActiveSupport::Concern
Defined in:
app/repositories/sipity/commands/additional_attribute_commands.rb

Overview

Commands

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_sip_attribute_values!(sip:, key:, values:) ⇒ Object


29
30
31
32
33
# File 'app/repositories/sipity/commands/additional_attribute_commands.rb', line 29

def create_sip_attribute_values!(sip:, key:, values:)
  Array.wrap(values).each do |value|
    Models::AdditionalAttribute.create!(sip: sip, key: key, value: value)
  end
end

.destroy_sip_attribute_values!(sip:, key:, values:) ⇒ Object


37
38
39
40
41
# File 'app/repositories/sipity/commands/additional_attribute_commands.rb', line 37

def destroy_sip_attribute_values!(sip:, key:, values:)
  values_to_destroy = Array.wrap(values)
  return true unless values_to_destroy.present?
  Models::AdditionalAttribute.where(sip: sip, key: key, value: values_to_destroy).destroy_all
end

.update_sip_attribute_values!(sip:, key:, values:) ⇒ Object


20
21
22
23
24
25
# File 'app/repositories/sipity/commands/additional_attribute_commands.rb', line 20

def update_sip_attribute_values!(sip:, key:, values:)
  input_values = Array.wrap(values)
  existing_values = Queries::AdditionalAttributeQueries.sip_attribute_values_for(sip: sip, key: key)
  create_sip_attribute_values!(sip: sip, key: key, values: (input_values - existing_values))
  destroy_sip_attribute_values!(sip: sip, key: key, values: (existing_values - input_values))
end

.update_sip_publication_date!(sip:, publication_date:) ⇒ Object


11
12
13
14
15
16
# File 'app/repositories/sipity/commands/additional_attribute_commands.rb', line 11

def update_sip_publication_date!(sip:, publication_date:)
  return true unless publication_date.present?
  update_sip_attribute_values!(
    sip: sip, key: Models::AdditionalAttribute::PUBLICATION_DATE_PREDICATE_NAME, values: publication_date
  )
end

Instance Method Details

#create_sip_attribute_values!(sip:, key:, values:) ⇒ Object


29
30
31
32
33
# File 'app/repositories/sipity/commands/additional_attribute_commands.rb', line 29

def create_sip_attribute_values!(sip:, key:, values:)
  Array.wrap(values).each do |value|
    Models::AdditionalAttribute.create!(sip: sip, key: key, value: value)
  end
end

#destroy_sip_attribute_values!(sip:, key:, values:) ⇒ Object


37
38
39
40
41
# File 'app/repositories/sipity/commands/additional_attribute_commands.rb', line 37

def destroy_sip_attribute_values!(sip:, key:, values:)
  values_to_destroy = Array.wrap(values)
  return true unless values_to_destroy.present?
  Models::AdditionalAttribute.where(sip: sip, key: key, value: values_to_destroy).destroy_all
end

#update_sip_attribute_values!(sip:, key:, values:) ⇒ Object


20
21
22
23
24
25
# File 'app/repositories/sipity/commands/additional_attribute_commands.rb', line 20

def update_sip_attribute_values!(sip:, key:, values:)
  input_values = Array.wrap(values)
  existing_values = Queries::AdditionalAttributeQueries.sip_attribute_values_for(sip: sip, key: key)
  create_sip_attribute_values!(sip: sip, key: key, values: (input_values - existing_values))
  destroy_sip_attribute_values!(sip: sip, key: key, values: (existing_values - input_values))
end

#update_sip_publication_date!(sip:, publication_date:) ⇒ Object


11
12
13
14
15
16
# File 'app/repositories/sipity/commands/additional_attribute_commands.rb', line 11

def update_sip_publication_date!(sip:, publication_date:)
  return true unless publication_date.present?
  update_sip_attribute_values!(
    sip: sip, key: Models::AdditionalAttribute::PUBLICATION_DATE_PREDICATE_NAME, values: publication_date
  )
end