Class: ArchiveStorage::Planner

Inherits:
Object
  • Object
show all
Defined in:
lib/archive_storage/planner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uploader: nil, model: nil, mounted_as: nil, older_than: nil, limit: nil, estimate_sizes: false) ⇒ Planner

Returns a new instance of Planner.



30
31
32
33
34
35
36
37
# File 'lib/archive_storage/planner.rb', line 30

def initialize(uploader: nil, model: nil, mounted_as: nil, older_than: nil, limit: nil, estimate_sizes: false)
  @uploader_name = uploader
  @model_name = model
  @mounted_as = mounted_as&.to_sym
  @older_than = DurationParser.parse(older_than)
  @limit = limit&.to_i
  @estimate_sizes = estimate_sizes
end

Instance Attribute Details

#estimate_sizesObject (readonly)

Returns the value of attribute estimate_sizes.



23
24
25
# File 'lib/archive_storage/planner.rb', line 23

def estimate_sizes
  @estimate_sizes
end

#limitObject (readonly)

Returns the value of attribute limit.



23
24
25
# File 'lib/archive_storage/planner.rb', line 23

def limit
  @limit
end

#model_nameObject (readonly)

Returns the value of attribute model_name.



23
24
25
# File 'lib/archive_storage/planner.rb', line 23

def model_name
  @model_name
end

#mounted_asObject (readonly)

Returns the value of attribute mounted_as.



23
24
25
# File 'lib/archive_storage/planner.rb', line 23

def mounted_as
  @mounted_as
end

#older_thanObject (readonly)

Returns the value of attribute older_than.



23
24
25
# File 'lib/archive_storage/planner.rb', line 23

def older_than
  @older_than
end

#uploader_nameObject (readonly)

Returns the value of attribute uploader_name.



23
24
25
# File 'lib/archive_storage/planner.rb', line 23

def uploader_name
  @uploader_name
end

Instance Method Details

#callObject



39
40
41
42
43
# File 'lib/archive_storage/planner.rb', line 39

def call
  result = PlanResult.new(uploader_name: uploader_name)
  each_candidate { |candidate| result.add(candidate) }
  result
end

#each_candidateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/archive_storage/planner.rb', line 45

def each_candidate
  return enum_for(:each_candidate) unless block_given?

  count = 0
  mounts.each do |mount|
    each_record(mount) do |record|
      candidates_for(record, mount).each do |candidate|
        yield candidate
        count += 1
        return if limit && count >= limit
      end
    end
  end
end