Class: Georgia::Clone
- Inherits:
-
Object
- Object
- Georgia::Clone
- Defined in:
- app/models/georgia/clone.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
-
#copy ⇒ Object
Returns an exact persisted version of itself with all Georgia::Page associations The resulting instance has a ‘(Copy)’ title and ‘-copy’ slug.
-
#draft ⇒ Object
Returns a copy of the current revision in ‘draft’ state.
-
#initialize(instance) ⇒ Clone
constructor
A new instance of Clone.
-
#store ⇒ Object
Returns a copy of the current revision in ‘revision’ state.
Constructor Details
#initialize(instance) ⇒ Clone
Returns a new instance of Clone.
6 7 8 9 10 |
# File 'app/models/georgia/clone.rb', line 6 def initialize instance raise 'Instance must be persisted to be copied' if instance.new_record? @instance = instance @duplicate = instance.class.new end |
Instance Attribute Details
#duplicate ⇒ Object
Returns the value of attribute duplicate.
4 5 6 |
# File 'app/models/georgia/clone.rb', line 4 def duplicate @duplicate end |
#instance ⇒ Object
Returns the value of attribute instance.
4 5 6 |
# File 'app/models/georgia/clone.rb', line 4 def instance @instance end |
Instance Method Details
#copy ⇒ Object
Returns an exact persisted version of itself with all Georgia::Page associations The resulting instance has a ‘(Copy)’ title and ‘-copy’ slug
14 15 16 17 18 19 20 21 |
# File 'app/models/georgia/clone.rb', line 14 def copy copy_page duplicate.current_revision = clone_current_revision alter_slug alter_title duplicate.save! duplicate end |
#draft ⇒ Object
Returns a copy of the current revision in ‘draft’ state
24 25 26 |
# File 'app/models/georgia/clone.rb', line 24 def draft clone_current_revision(state: 'draft') end |
#store ⇒ Object
Returns a copy of the current revision in ‘revision’ state
29 30 31 32 |
# File 'app/models/georgia/clone.rb', line 29 def store @instance.revisions << clone_current_revision(state: 'revision') @instance.save end |