Class: Spree::Themes::Duplicator

Inherits:
Object
  • Object
show all
Defined in:
app/services/spree/themes/duplicator.rb

Instance Method Summary collapse

Constructor Details

#initialize(theme) ⇒ Duplicator

Returns a new instance of Duplicator.



4
5
6
# File 'app/services/spree/themes/duplicator.rb', line 4

def initialize(theme)
  @theme = theme
end

Instance Method Details

#duplicateObject



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

def duplicate
  duplicated_theme = @theme.dup
  duplicated_theme.duplicating = true
  duplicated_theme.default = false
  duplicated_theme.ready = false
  duplicated_theme.name = generate_new_name(@theme.name)
  duplicated_theme.save!

  # We need to duplicate files, pages and sections in the background
  Spree::Themes::DuplicateComponentsJob.set(wait: 5.seconds).perform_later(@theme.id, duplicated_theme.id)

  duplicated_theme
end