Class: Spree::Classifications::Reposition Deprecated

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

Overview

Deprecated.

This service is deprecated and will be removed in Spree 5.5.

Instance Method Summary collapse

Methods included from ServiceModule::Base

prepended

Instance Method Details

#call(classification:, position:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/spree/classifications/reposition.rb', line 7

def call(classification:, position:)
  Spree::Deprecation.warn(
    "#{self.class.name} is deprecated and will be removed in Spree 5.5.",
    caller_locations(2)
  )
  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