Class: Magick::BulkResult

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/magick/bulk_result.rb

Overview

What a bulk toggle actually did.

It iterates as the plain array of features Magick.bulk_enable and Magick.bulk_disable have always returned, so existing callers keep working. On top of that it names the features the call could not act on, so a partial run is distinguishable from a full one instead of being reported as a blanket success.

result = Magick.bulk_enable(%i[checkout api_version])
result.complete?        # => false
result.changed          # => [#<Magick::Feature checkout>]
result.skipped_reasons  # => { "api_version" => "cannot enable a string feature ..." }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(features, changed, skipped_reasons = {}) ⇒ BulkResult

Returns a new instance of BulkResult.



28
29
30
31
32
# File 'lib/magick/bulk_result.rb', line 28

def initialize(features, changed, skipped_reasons = {})
  @features = features.freeze
  @changed = changed.freeze
  @skipped_reasons = skipped_reasons.freeze
end

Instance Attribute Details

#changed ⇒ Object (readonly)

The features that were written.



23
24
25
# File 'lib/magick/bulk_result.rb', line 23

def changed
  @changed
end

#features ⇒ Object (readonly)

Every feature named in the call, in the order given.



20
21
22
# File 'lib/magick/bulk_result.rb', line 20

def features
  @features
end

#skipped_reasons ⇒ Object (readonly)

Feature name => why that feature was left untouched.



26
27
28
# File 'lib/magick/bulk_result.rb', line 26

def skipped_reasons
  @skipped_reasons
end

Instance Method Details

#[](index) ⇒ Object



56
57
58
# File 'lib/magick/bulk_result.rb', line 56

def [](index)
  features[index]
end

#complete? ⇒ Boolean

True when every named feature was written.

Returns:

  • (Boolean)


47
48
49
# File 'lib/magick/bulk_result.rb', line 47

def complete?
  skipped_reasons.empty?
end

#each(&block) ⇒ Object



34
35
36
37
38
39
# File 'lib/magick/bulk_result.rb', line 34

def each(&block)
  return features.each unless block

  features.each(&block)
  self
end

#empty? ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/magick/bulk_result.rb', line 65

def empty?
  features.empty?
end

#inspect ⇒ Object



69
70
71
# File 'lib/magick/bulk_result.rb', line 69

def inspect
  "#<#{self.class.name} changed=#{changed.map(&:name)} skipped=#{skipped_reasons}>"
end

#size ⇒ Object Also known as: length



60
61
62
# File 'lib/magick/bulk_result.rb', line 60

def size
  features.size
end

#skipped ⇒ Object

The features the call left untouched, in the order given.



42
43
44
# File 'lib/magick/bulk_result.rb', line 42

def skipped
  features.select { |feature| skipped_reasons.key?(feature.name) }
end

#to_a ⇒ Object Also known as: to_ary



51
52
53
# File 'lib/magick/bulk_result.rb', line 51

def to_a
  features.dup
end