Class: Alchemy::CopyPage
- Inherits:
-
Object
- Object
- Alchemy::CopyPage
- Defined in:
- app/services/alchemy/copy_page.rb
Overview
Creates a copy of given source page.
Also copies all elements included in source page.
Note:
It prevents the element auto generator from running.
Constant Summary collapse
- DEFAULT_ATTRIBUTES_FOR_COPY =
{ autogenerate_elements: false, public_on: nil, public_until: nil, locked_at: nil, locked_by: nil }
- SKIPPED_ATTRIBUTES_ON_COPY =
%w[ id updated_at created_at creator_id updater_id lft rgt depth urlname cached_tag_list ]
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
- #call(changed_attributes:) ⇒ Alchemy::Page
-
#initialize(page:) ⇒ CopyPage
constructor
A new instance of CopyPage.
Constructor Details
#initialize(page:) ⇒ CopyPage
Returns a new instance of CopyPage.
37 38 39 |
# File 'app/services/alchemy/copy_page.rb', line 37 def initialize(page:) @page = page end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
33 34 35 |
# File 'app/services/alchemy/copy_page.rb', line 33 def page @page end |
Instance Method Details
#call(changed_attributes:) ⇒ Alchemy::Page
46 47 48 49 50 51 52 53 54 55 |
# File 'app/services/alchemy/copy_page.rb', line 46 def call(changed_attributes:) Alchemy::Page.transaction do new_page = Alchemy::Page.new(attributes_from_source_for_copy(changed_attributes)) new_page.tag_list = page.tag_list if new_page.save! Alchemy::Page.copy_elements(page, new_page) end new_page end end |