Class: Georgia::CopyPage
- Inherits:
-
Object
- Object
- Georgia::CopyPage
- Defined in:
- app/services/georgia/copy_page.rb
Instance Attribute Summary collapse
-
#duplicate ⇒ Object
Returns the value of attribute duplicate.
-
#instance ⇒ Object
Returns the value of attribute instance.
Instance Method Summary collapse
-
#call ⇒ Object
Returns an exact persisted version of itself with all Georgia::Page associations The resulting instance has a ‘(Copy)’ title and ‘-copy’ slug.
-
#initialize(instance, attributes = {}) ⇒ CopyPage
constructor
A new instance of CopyPage.
-
#store ⇒ Object
Returns a copy of the current revision in ‘revision’ state.
Constructor Details
#initialize(instance, attributes = {}) ⇒ CopyPage
Returns a new instance of CopyPage.
6 7 8 9 10 11 |
# File 'app/services/georgia/copy_page.rb', line 6 def initialize instance, attributes={} raise 'Instance must be persisted to be copied' if instance.new_record? @instance = instance @duplicate = instance.class.new @attributes = attributes end |
Instance Attribute Details
#duplicate ⇒ Object
Returns the value of attribute duplicate.
4 5 6 |
# File 'app/services/georgia/copy_page.rb', line 4 def duplicate @duplicate end |
#instance ⇒ Object
Returns the value of attribute instance.
4 5 6 |
# File 'app/services/georgia/copy_page.rb', line 4 def instance @instance end |
Instance Method Details
#call ⇒ Object
Returns an exact persisted version of itself with all Georgia::Page associations The resulting instance has a ‘(Copy)’ title and ‘-copy’ slug
15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/georgia/copy_page.rb', line 15 def call copy_page revision = CloneRevision.create(instance.current_revision) revision.revisionable = duplicate duplicate.current_revision = revision alter_slug alter_title duplicate.save! revision.save! duplicate end |
#store ⇒ Object
Returns a copy of the current revision in ‘revision’ state
28 29 30 31 |
# File 'app/services/georgia/copy_page.rb', line 28 def store @instance.revisions << CloneRevision.create(instance.current_revision, status: 'revision') @instance.save end |