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 title meta_description meta_keywords ]- METADATA_ATTRIBUTES_TO_COPY =
Metadata to copy via nested attributes (title is derived from page.name)
(Alchemy::PageVersion::METADATA_ATTRIBUTES - %w[title]).freeze
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.
43 44 45 |
# File 'app/services/alchemy/copy_page.rb', line 43 def initialize(page:) @page = page end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
39 40 41 |
# File 'app/services/alchemy/copy_page.rb', line 39 def page @page end |
Instance Method Details
#call(changed_attributes:) ⇒ Alchemy::Page
52 53 54 55 56 57 58 59 60 61 |
# File 'app/services/alchemy/copy_page.rb', line 52 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 |