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 ⇒ 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
- #never_published? ⇒ Boolean
- #publish ⇒ Object
- #publish! ⇒ Object
- #publishable? ⇒ Boolean
- #published? ⇒ Boolean
- #state ⇒ Object
- #to_review ⇒ Object
- #unpublish ⇒ Object
- #unpublished? ⇒ Boolean
- #validatable_for_publishing? ⇒ Boolean
- #with_validations_for_publishing ⇒ Object
Instance Method Details
#branch ⇒ Object
module ClassMethods
89 90 91 92 93 94 95 |
# File 'app/models/concerns/versioning.rb', line 89 def branch new_version = self.deep_clone(include: self.class.includes_to_deep_cloning) new_version.increment(:rev) new_version.published_version_id = self.id new_version.unpublish new_version end |
#disable_validations_for_publishing ⇒ Object
139 140 141 |
# File 'app/models/concerns/versioning.rb', line 139 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)
99 100 101 |
# File 'app/models/concerns/versioning.rb', line 99 def editor_selectable? published? || read_attribute(:published_version_id).blank? end |
#enable_validations_for_publishing ⇒ Object
135 136 137 |
# File 'app/models/concerns/versioning.rb', line 135 def enable_validations_for_publishing @_run_validations_for_publishing = true end |
#in_review? ⇒ Boolean
117 118 119 |
# File 'app/models/concerns/versioning.rb', line 117 def in_review? read_attribute(:to_review).present? end |
#never_published? ⇒ Boolean
103 104 105 |
# File 'app/models/concerns/versioning.rb', line 103 def never_published? unpublished? && rev == 1 end |
#publish ⇒ Object
147 148 149 150 151 152 153 |
# File 'app/models/concerns/versioning.rb', line 147 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
169 170 171 172 173 174 |
# File 'app/models/concerns/versioning.rb', line 169 def publish! with_validations_for_publishing do publish save! end end |
#publishable? ⇒ Boolean
176 177 178 179 180 |
# File 'app/models/concerns/versioning.rb', line 176 def publishable? with_validations_for_publishing do valid? end end |
#published? ⇒ Boolean
161 162 163 |
# File 'app/models/concerns/versioning.rb', line 161 def published? read_attribute(:published_at).present? end |
#state ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'app/models/concerns/versioning.rb', line 107 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
121 122 123 124 125 |
# File 'app/models/concerns/versioning.rb', line 121 def to_review tap do write_attribute(:to_review, true) end end |
#unpublish ⇒ Object
155 156 157 158 159 |
# File 'app/models/concerns/versioning.rb', line 155 def unpublish tap do write_attribute(:published_at, nil) end end |
#unpublished? ⇒ Boolean
165 166 167 |
# File 'app/models/concerns/versioning.rb', line 165 def unpublished? !published? end |
#validatable_for_publishing? ⇒ Boolean
143 144 145 |
# File 'app/models/concerns/versioning.rb', line 143 def validatable_for_publishing? @_run_validations_for_publishing end |
#with_validations_for_publishing ⇒ Object
127 128 129 130 131 132 133 |
# File 'app/models/concerns/versioning.rb', line 127 def with_validations_for_publishing enable_validations_for_publishing status = yield disable_validations_for_publishing return status end |