Class: InOrder::Update

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Aux::SortElements

sort_elements

Methods included from Aux::VarKeys

included, #initialize

Instance Attribute Details

#appendObject 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

#maxObject

Returns the value of attribute max.



10
11
12
# File 'app/models/in_order/update.rb', line 10

def max
  @max
end

#uniqObject 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, **options)
  set_options(**options)

  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 set_options(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