Class: InOrder::Purge
- Inherits:
-
Object
- Object
- InOrder::Purge
- Includes:
- Aux::VarKeys
- Defined in:
- app/models/in_order/purge.rb
Overview
Removes unwanted subjects from a list. Identified (i.e. keyed) by an Owner and/or Scope.
Class Method Summary collapse
Instance Method Summary collapse
-
#call(keep_last: false) ⇒ Object
(also: #uniq)
keep_last
determines whether the first or last occurrence remains. - #exists?(subject) ⇒ Boolean
- #remove(*subjects, elements: get_elements) ⇒ Object
Methods included from Aux::VarKeys
Class Method Details
Instance Method Details
#call(keep_last: false) ⇒ Object Also known as: uniq
keep_last
determines whether the first or last occurrence remains
9 10 11 12 13 14 15 16 17 |
# File 'app/models/in_order/purge.rb', line 9 def call(keep_last: false) elements = get_elements elements.reverse! if keep_last traverse elements do |element, found_subjects, subject| Remove.new(element).call if found_subjects.include?(subject) end end |
#exists?(subject) ⇒ Boolean
36 37 38 |
# File 'app/models/in_order/purge.rb', line 36 def exists?(subject) InOrder::Element.has_subject?(keys) { subject } end |
#remove(*subjects, elements: get_elements) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/in_order/purge.rb', line 20 def remove(*subjects, elements: get_elements) did_remove = false subjects.flatten! if Array === subjects.first traverse elements do |element| if subjects.include?(element.subject) Remove.new(element).call did_remove = true end end did_remove end |