Class: ProjectAccumulator

Inherits:
Object
  • Object
show all
Defined in:
app/models/project_accumulator.rb

Instance Method Summary collapse

Constructor Details

#initialize(project:, session_id:) ⇒ ProjectAccumulator

Returns a new instance of ProjectAccumulator.



3
4
5
6
# File 'app/models/project_accumulator.rb', line 3

def initialize(project:, session_id:)
  @collection_id = project.mediaflux_id
  @session_id = session_id
end

Instance Method Details

#create!Object

Create accumulators for all newly created mediaflux projects



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/project_accumulator.rb', line 10

def create!
  accum_names = validate
  return false if accum_names == true # Return false if accumulators already exist, and no change is needed

  # Create accumulators if they do not exist
  if accum_names.exclude?("accum-count")
    create_accum_count(collection_id: @collection_id, session_id: @session_id)
  end
  if accum_names.exclude?("accum-size")
    create_accum_size(collection_id: @collection_id, session_id: @session_id)
  end
  if accum_names.exclude?("accum-store-size")
    create_accum_store_size(collection_id: @collection_id, session_id: @session_id)
  end

  true # Return true if accumulators were created
end

#validateObject

Validate that a project has the expected accumulators



30
31
32
33
34
# File 'app/models/project_accumulator.rb', line 30

def validate
   = Mediaflux::AssetMetadataRequest.new(session_token: @session_id, id: @collection_id).
  accum_names = [:accum_names].to_a.map(&:to_s)
  accum_names.size == 3 ? true : accum_names
end