Module: Versioning
- Extended by:
- ActiveSupport::Concern
- Included in:
- Concept::Base
- Defined in:
- app/models/concerns/versioning.rb
Overview
Copyright 2011-2013 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #branch(user) ⇒ Object
- #disable_validations_for_publishing ⇒ Object
-
#editor_selectable? ⇒ Boolean
Editor selectable if published or no published version exists (before first publication).
- #enable_validations_for_publishing ⇒ Object
- #in_review? ⇒ Boolean
- #lock_by_user(user_id) ⇒ Object
- #locked? ⇒ Boolean
- #publish ⇒ Object
- #publish! ⇒ Object
- #publishable? ⇒ Boolean
- #published? ⇒ Boolean
- #state ⇒ Object
- #to_review ⇒ Object
- #unlock ⇒ Object
- #unpublish ⇒ Object
- #validatable_for_publishing? ⇒ Boolean
- #with_validations_for_publishing ⇒ Object
Instance Method Details
#branch(user) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'app/models/concerns/versioning.rb', line 93 def branch(user) new_version = self.dup(include: self.class.includes_to_deep_cloning) new_version.lock_by_user(user.id) new_version.increment(:rev) new_version.published_version_id = self.id new_version.unpublish new_version end |
#disable_validations_for_publishing ⇒ Object
156 157 158 |
# File 'app/models/concerns/versioning.rb', line 156 def disable_validations_for_publishing @_run_validations_for_publishing = false end |
#editor_selectable? ⇒ Boolean
Editor selectable if published or no published version exists (before first publication)
104 105 106 |
# File 'app/models/concerns/versioning.rb', line 104 def editor_selectable? published? || read_attribute(:published_version_id).blank? end |
#enable_validations_for_publishing ⇒ Object
152 153 154 |
# File 'app/models/concerns/versioning.rb', line 152 def enable_validations_for_publishing @_run_validations_for_publishing = true end |
#in_review? ⇒ Boolean
134 135 136 |
# File 'app/models/concerns/versioning.rb', line 134 def in_review? read_attribute(:to_review).present? end |
#lock_by_user(user_id) ⇒ Object
108 109 110 111 112 |
# File 'app/models/concerns/versioning.rb', line 108 def lock_by_user(user_id) tap do write_attribute(:locked_by, user_id) end end |
#locked? ⇒ Boolean
114 115 116 |
# File 'app/models/concerns/versioning.rb', line 114 def locked? locked_by? end |
#publish ⇒ Object
164 165 166 167 168 169 170 |
# File 'app/models/concerns/versioning.rb', line 164 def publish tap do write_attribute(:published_at, Time.now) write_attribute(:to_review, nil) write_attribute(:published_version_id, nil) end end |
#publish! ⇒ Object
182 183 184 185 186 187 |
# File 'app/models/concerns/versioning.rb', line 182 def publish! with_validations_for_publishing do publish save! end end |
#publishable? ⇒ Boolean
189 190 191 192 193 |
# File 'app/models/concerns/versioning.rb', line 189 def publishable? with_validations_for_publishing do valid? end end |
#published? ⇒ Boolean
178 179 180 |
# File 'app/models/concerns/versioning.rb', line 178 def published? read_attribute(:published_at).present? end |
#state ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'app/models/concerns/versioning.rb', line 118 def state if published? I18n.t('txt.common.state.published') elsif !published? && in_review? I18n.t('txt.common.state.in_review') elsif !published? && !in_review? I18n.t('txt.common.state.checked_out') end end |
#to_review ⇒ Object
138 139 140 141 142 |
# File 'app/models/concerns/versioning.rb', line 138 def to_review tap do write_attribute(:to_review, true) end end |
#unlock ⇒ Object
128 129 130 131 132 |
# File 'app/models/concerns/versioning.rb', line 128 def unlock tap do write_attribute(:locked_by, nil) end end |
#unpublish ⇒ Object
172 173 174 175 176 |
# File 'app/models/concerns/versioning.rb', line 172 def unpublish tap do write_attribute(:published_at, nil) end end |
#validatable_for_publishing? ⇒ Boolean
160 161 162 |
# File 'app/models/concerns/versioning.rb', line 160 def validatable_for_publishing? @_run_validations_for_publishing end |
#with_validations_for_publishing ⇒ Object
144 145 146 147 148 149 150 |
# File 'app/models/concerns/versioning.rb', line 144 def with_validations_for_publishing enable_validations_for_publishing status = yield disable_validations_for_publishing return status end |