Class: TypedEAV::Section

Inherits:
ApplicationRecord show all
Defined in:
app/models/typed_eav/section.rb

Instance Method Summary collapse

Instance Method Details

#insert_at(position) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/models/typed_eav/section.rb', line 84

def insert_at(position)
  reorder_within_partition do |siblings|
    idx = siblings.index { |r| r.id == id }
    next siblings if idx.nil?

    target = position.clamp(1, siblings.size) - 1
    next siblings if idx == target

    moving = siblings.delete_at(idx)
    siblings.insert(target, moving)
    siblings
  end
end

#move_higherObject

── Display ordering ──

Mirrors Field::Base ordering helpers byte-for-byte (per CONTEXT.md inline-duplication decision; see Phase 01 validate_parent_scope_invariant precedent). Keep the two implementations symmetric — when one changes, the other should change in the same commit. See field/base.rb for rationale comments on the partition-level FOR UPDATE locking strategy.



42
43
44
45
46
47
48
49
50
# File 'app/models/typed_eav/section.rb', line 42

def move_higher
  reorder_within_partition do |siblings|
    idx = siblings.index { |r| r.id == id }
    next siblings if idx.nil? || idx.zero?

    siblings[idx], siblings[idx - 1] = siblings[idx - 1], siblings[idx]
    siblings
  end
end

#move_lowerObject



52
53
54
55
56
57
58
59
60
# File 'app/models/typed_eav/section.rb', line 52

def move_lower
  reorder_within_partition do |siblings|
    idx = siblings.index { |r| r.id == id }
    next siblings if idx.nil? || idx == siblings.size - 1

    siblings[idx], siblings[idx + 1] = siblings[idx + 1], siblings[idx]
    siblings
  end
end

#move_to_bottomObject



73
74
75
76
77
78
79
80
81
82
# File 'app/models/typed_eav/section.rb', line 73

def move_to_bottom
  reorder_within_partition do |siblings|
    idx = siblings.index { |r| r.id == id }
    next siblings if idx.nil? || idx == siblings.size - 1

    moving = siblings.delete_at(idx)
    siblings.push(moving)
    siblings
  end
end

#move_to_topObject



62
63
64
65
66
67
68
69
70
71
# File 'app/models/typed_eav/section.rb', line 62

def move_to_top
  reorder_within_partition do |siblings|
    idx = siblings.index { |r| r.id == id }
    next siblings if idx.nil? || idx.zero?

    moving = siblings.delete_at(idx)
    siblings.unshift(moving)
    siblings
  end
end