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
module ClassMethods.
- #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
- #unpublished? ⇒ Boolean
- #validatable_for_publishing? ⇒ Boolean
- #with_validations_for_publishing ⇒ Object
Instance Method Details
#branch(user) ⇒ Object
module ClassMethods
95 96 97 98 99 100 101 102 |
# File 'app/models/concerns/versioning.rb', line 95 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
158 159 160 |
# File 'app/models/concerns/versioning.rb', line 158 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)
106 107 108 |
# File 'app/models/concerns/versioning.rb', line 106 def editor_selectable? published? || read_attribute(:published_version_id).blank? end |
#enable_validations_for_publishing ⇒ Object
154 155 156 |
# File 'app/models/concerns/versioning.rb', line 154 def enable_validations_for_publishing @_run_validations_for_publishing = true end |
#in_review? ⇒ Boolean
136 137 138 |
# File 'app/models/concerns/versioning.rb', line 136 def in_review? read_attribute(:to_review).present? end |
#lock_by_user(user_id) ⇒ Object
110 111 112 113 114 |
# File 'app/models/concerns/versioning.rb', line 110 def lock_by_user(user_id) tap do write_attribute(:locked_by, user_id) end end |
#locked? ⇒ Boolean
116 117 118 |
# File 'app/models/concerns/versioning.rb', line 116 def locked? locked_by? end |
#publish ⇒ Object
166 167 168 169 170 171 172 |
# File 'app/models/concerns/versioning.rb', line 166 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
188 189 190 191 192 193 |
# File 'app/models/concerns/versioning.rb', line 188 def publish! with_validations_for_publishing do publish save! end end |
#publishable? ⇒ Boolean
195 196 197 198 199 |
# File 'app/models/concerns/versioning.rb', line 195 def publishable? with_validations_for_publishing do valid? end end |
#published? ⇒ Boolean
180 181 182 |
# File 'app/models/concerns/versioning.rb', line 180 def published? read_attribute(:published_at).present? end |
#state ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'app/models/concerns/versioning.rb', line 120 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
140 141 142 143 144 |
# File 'app/models/concerns/versioning.rb', line 140 def to_review tap do write_attribute(:to_review, true) end end |
#unlock ⇒ Object
130 131 132 133 134 |
# File 'app/models/concerns/versioning.rb', line 130 def unlock tap do write_attribute(:locked_by, nil) end end |
#unpublish ⇒ Object
174 175 176 177 178 |
# File 'app/models/concerns/versioning.rb', line 174 def unpublish tap do write_attribute(:published_at, nil) end end |
#unpublished? ⇒ Boolean
184 185 186 |
# File 'app/models/concerns/versioning.rb', line 184 def unpublished? !published? end |
#validatable_for_publishing? ⇒ Boolean
162 163 164 |
# File 'app/models/concerns/versioning.rb', line 162 def validatable_for_publishing? @_run_validations_for_publishing end |
#with_validations_for_publishing ⇒ Object
146 147 148 149 150 151 152 |
# File 'app/models/concerns/versioning.rb', line 146 def with_validations_for_publishing enable_validations_for_publishing status = yield disable_validations_for_publishing return status end |