Class: LD4L::OreRDF::PersistAggregation

Inherits:
Object
  • Object
show all
Defined in:
lib/ld4l/ore_rdf/services/aggregation/persist.rb

Class Method Summary collapse

Class Method Details

.call(aggregation) ⇒ Object

Persist the aggregation and all associated proxies.

Parameters:

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ld4l/ore_rdf/services/aggregation/persist.rb', line 15

def self.call( aggregation )
  raise ArgumentError, 'aggregation must be an LD4L::OreRDF::Aggregation'  unless
      aggregation && aggregation.kind_of?(LD4L::OreRDF::Aggregation)

  # TODO Probably shouldn't be ArgumentError
  raise ArgumentError, "title is required" unless
      aggregation.title && aggregation.title.kind_of?(String) && aggregation.title.size > 0

  count = 0
  agg_persisted = aggregation.aggregation_resource.persist!
  aggregation.proxy_resources.each { |proxy| count += 1 if proxy.persist! }  if agg_persisted
  percent_proxies = aggregation.proxy_resources.size > 0 ? count/aggregation.proxy_resources.size : 1
  all_persisted = agg_persisted && (percent_proxies == 1)
  ret = all_persisted ? all_persisted :
                        {
                          :aggregation_resource_persisted => agg_persisted,
                          :percent_proxies_persisted => percent_proxies
                        }
  ret
end