Class: Spree::Classifications::Reposition

Inherits:
Object
  • Object
show all
Includes:
ServiceModule::Base
Defined in:
app/services/spree/classifications/reposition.rb

Instance Method Summary collapse

Methods included from ServiceModule::Base

prepended

Instance Method Details

#call(classification:, position:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'app/services/spree/classifications/reposition.rb', line 6

def call(classification:, position:)
  if position.is_a?(String) && !position.match(/^\d+$/)
    return failure(nil, I18n.t('errors.messages.not_a_number'))
  end

  # Because position we get back is 0-indexed.
  # acts_as_list is 1-indexed.
  classification.insert_at(position.to_i + 1)
  success(classification)
end