Class: ArchiveStorage::Planner
- Inherits:
-
Object
- Object
- ArchiveStorage::Planner
- Defined in:
- lib/archive_storage/planner.rb
Instance Attribute Summary collapse
-
#estimate_sizes ⇒ Object
readonly
Returns the value of attribute estimate_sizes.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_name.
-
#mounted_as ⇒ Object
readonly
Returns the value of attribute mounted_as.
-
#older_than ⇒ Object
readonly
Returns the value of attribute older_than.
-
#uploader_name ⇒ Object
readonly
Returns the value of attribute uploader_name.
Instance Method Summary collapse
- #call ⇒ Object
- #each_candidate ⇒ Object
-
#initialize(uploader: nil, model: nil, mounted_as: nil, older_than: nil, limit: nil, estimate_sizes: false) ⇒ Planner
constructor
A new instance of Planner.
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_sizes ⇒ Object (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 |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
23 24 25 |
# File 'lib/archive_storage/planner.rb', line 23 def limit @limit end |
#model_name ⇒ Object (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_as ⇒ Object (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_than ⇒ Object (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_name ⇒ Object (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
#call ⇒ Object
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_candidate ⇒ Object
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 |