Class: InOrder::Update
- Inherits:
-
Object
- Object
- InOrder::Update
- Includes:
- Aux::SortElements, Aux::VarKeys
- Defined in:
- app/models/in_order/update.rb
Overview
Adds new elements to an existing list, returning the whole new list. Effectively, it calls Create, Fetch Uniq and Trim.
Instance Attribute Summary collapse
-
#append ⇒ Object
(also: #append?)
Returns the value of attribute append.
-
#max ⇒ Object
Returns the value of attribute max.
-
#uniq ⇒ Object
(also: #uniq?)
Returns the value of attribute uniq.
Instance Method Summary collapse
- #call(models, **options) ⇒ Object (also: #elements)
- #set_options(append: true, uniq: true, max: nil) ⇒ Object
- #subjects(*args) ⇒ Object (also: #records)
Methods included from Aux::SortElements
Methods included from Aux::VarKeys
Instance Attribute Details
#append ⇒ Object Also known as: append?
Returns the value of attribute append.
10 11 12 |
# File 'app/models/in_order/update.rb', line 10 def append @append end |
#max ⇒ Object
Returns the value of attribute max.
10 11 12 |
# File 'app/models/in_order/update.rb', line 10 def max @max end |
#uniq ⇒ Object Also known as: uniq?
Returns the value of attribute uniq.
10 11 12 |
# File 'app/models/in_order/update.rb', line 10 def uniq @uniq end |
Instance Method Details
#call(models, **options) ⇒ Object Also known as: elements
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/in_order/update.rb', line 22 def call(models, **) (**) previous_elements = get_elements if uniq? and previous_elements.any? if purge_previous(previous_elements, models) previous_elements = get_elements end end new_elements = Create.new(keys).(models, append: append?) if previous_elements.any? new_elements = add_to_list(previous_elements, new_elements) end trim(new_elements) end |
#set_options(append: true, uniq: true, max: nil) ⇒ Object
14 15 16 17 18 19 20 |
# File 'app/models/in_order/update.rb', line 14 def (append: true, uniq: true, max: nil) self.append = append self.max = max&.to_i self.uniq = uniq end |
#subjects(*args) ⇒ Object Also known as: records
43 44 45 |
# File 'app/models/in_order/update.rb', line 43 def subjects(*args) call(*args).map &:subject end |