Class: Plutonium::Kanban::Positioning::Config
- Inherits:
-
Object
- Object
- Plutonium::Kanban::Positioning::Config
- Defined in:
- lib/plutonium/kanban/positioning.rb
Overview
Strategy configuration object created by the position_on DSL.
Three modes:
Mode A (:delegate) — delegate reposition! to Plutonium::Positioning concern
Mode B (:block) — call a user-supplied block with a Move
Mode C (:disabled) — no ordering; relation returned unchanged
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
Class Method Summary collapse
-
.attribute(attr) ⇒ Object
Mode A, custom attribute.
-
.default ⇒ Object
Mode A, default attribute :position.
-
.disabled ⇒ Object
Mode C — disabled.
-
.with_block(attr, block) ⇒ Object
Mode B — orders by attr, write delegated to block.
Instance Method Summary collapse
- #disabled? ⇒ Boolean
-
#initialize(mode, attribute, block) ⇒ Config
constructor
A new instance of Config.
-
#order(relation) ⇒ Object
Apply positional ordering to a relation.
-
#reposition!(record:, column:, prev_record:, next_record:, index:) ⇒ Object
Persist the new position for a dropped record.
Constructor Details
#initialize(mode, attribute, block) ⇒ Config
Returns a new instance of Config.
40 41 42 43 44 |
# File 'lib/plutonium/kanban/positioning.rb', line 40 def initialize(mode, attribute, block) @mode = mode @attribute = attribute @block = block end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
38 39 40 |
# File 'lib/plutonium/kanban/positioning.rb', line 38 def attribute @attribute end |
Class Method Details
.attribute(attr) ⇒ Object
Mode A, custom attribute
24 25 26 |
# File 'lib/plutonium/kanban/positioning.rb', line 24 def self.attribute(attr) new(:delegate, attr.to_sym, nil) end |
.default ⇒ Object
Mode A, default attribute :position
19 20 21 |
# File 'lib/plutonium/kanban/positioning.rb', line 19 def self.default new(:delegate, :position, nil) end |
.disabled ⇒ Object
Mode C — disabled
34 35 36 |
# File 'lib/plutonium/kanban/positioning.rb', line 34 def self.disabled new(:disabled, nil, nil) end |
.with_block(attr, block) ⇒ Object
Mode B — orders by attr, write delegated to block
29 30 31 |
# File 'lib/plutonium/kanban/positioning.rb', line 29 def self.with_block(attr, block) new(:block, attr.to_sym, block) end |
Instance Method Details
#disabled? ⇒ Boolean
46 47 48 |
# File 'lib/plutonium/kanban/positioning.rb', line 46 def disabled? @mode == :disabled end |
#order(relation) ⇒ Object
Apply positional ordering to a relation. Mode A/B: relation.reorder(attribute) Mode C: return relation unchanged
53 54 55 56 |
# File 'lib/plutonium/kanban/positioning.rb', line 53 def order(relation) return relation if disabled? relation.reorder(@attribute) end |
#reposition!(record:, column:, prev_record:, next_record:, index:) ⇒ Object
Persist the new position for a dropped record. Mode A: delegate to record.reposition!(prev_record:, next_record:) Mode B: call the user block with a Move Mode C: no-op
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/plutonium/kanban/positioning.rb', line 62 def reposition!(record:, column:, prev_record:, next_record:, index:) case @mode when :delegate record.reposition!(prev_record:, next_record:) when :block @block.call(Move.new(record:, column:, prev: prev_record, next: next_record, index:)) when :disabled nil end end |