Module: Zena::Use::Workflow::VersionMethods
- Included in:
- Version
- Defined in:
- lib/zena/use/workflow.rb
Overview
The Workflow::VersionMethods module should be included in the model used as version.
Instance Attribute Summary collapse
-
#backup ⇒ Object
Enable the use of version.backup = ‘true’ to force clone.
-
#no_clone_on_change ⇒ Object
Enable the use of version.backup = ‘true’ to force clone.
-
#status_set ⇒ Object
readonly
Returns the value of attribute status_set.
-
#stored_workflow ⇒ Object
readonly
Return stored values before save.
Class Method Summary collapse
Instance Method Summary collapse
-
#clone_on_change? ⇒ Boolean
Return true if the version should be cloned if it was changed.
-
#edited? ⇒ Boolean
Returns true if the version has been edited (not just a status change).
-
#should_clone? ⇒ Boolean
Return true if the version should clone itself before save.
- #status=(status) ⇒ Object
-
#status_set? ⇒ Boolean
Return true if the ‘status’ value was set.
Instance Attribute Details
#backup ⇒ Object
Enable the use of version.backup = ‘true’ to force clone
15 16 17 |
# File 'lib/zena/use/workflow.rb', line 15 def backup @backup end |
#no_clone_on_change ⇒ Object
Enable the use of version.backup = ‘true’ to force clone
15 16 17 |
# File 'lib/zena/use/workflow.rb', line 15 def no_clone_on_change @no_clone_on_change end |
#status_set ⇒ Object (readonly)
Returns the value of attribute status_set.
13 14 15 |
# File 'lib/zena/use/workflow.rb', line 13 def status_set @status_set end |
#stored_workflow ⇒ Object (readonly)
Return stored values before save
22 23 24 |
# File 'lib/zena/use/workflow.rb', line 22 def stored_workflow @stored_workflow end |
Class Method Details
.included(base) ⇒ Object
17 18 19 |
# File 'lib/zena/use/workflow.rb', line 17 def self.included(base) base.before_save :store_workflow_changes end |
Instance Method Details
#clone_on_change? ⇒ Boolean
Return true if the version should be cloned if it was changed.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/zena/use/workflow.rb', line 45 def clone_on_change? # List of changed versioned properties if @no_clone_on_change false else # not same user user_id != visitor.id || # changed lang lang_changed? || # new version on top of publication status_changed? || # not in redit time Time.now > created_at + current_site[:redit_time].to_i end end |
#edited? ⇒ Boolean
Returns true if the version has been edited (not just a status change)
62 63 64 65 66 67 68 |
# File 'lib/zena/use/workflow.rb', line 62 def edited? new_record? || (changes.keys - WORKFLOW_ATTRIBUTES != []) || # The node loaded here is guaranteed to be the same as the one where props are changed: # node.version.node.object_id == node.object_id nprop.changed? end |
#should_clone? ⇒ Boolean
Return true if the version should clone itself before save
39 40 41 42 |
# File 'lib/zena/use/workflow.rb', line 39 def should_clone? edited? && ( @backup || clone_on_change? ) end |
#status=(status) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/zena/use/workflow.rb', line 26 def status=(status) self[:status] = status # We need this to know if the status was set, even if the value was the same # as the current value (force published state while editing published version). @status_set = true end |
#status_set? ⇒ Boolean
Return true if the ‘status’ value was set.
34 35 36 |
# File 'lib/zena/use/workflow.rb', line 34 def status_set? @status_set end |