Module: Versioning

Extended by:
ActiveSupport::Concern
Included in:
Concept::Base
Defined in:
app/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

Instance Method Details

#branch(user) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/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.send(:"#{Iqvoc.change_note_class_name.to_relation_name}").build(
    language: I18n.locale.to_s,
    annotations_attributes: [
      { namespace: 'dct', predicate: 'creator', value: user.name },
      { namespace: 'dct', predicate: 'modified', value: DateTime.now.to_s }
    ])
  new_version
end

#disable_validations_for_publishingObject



162
163
164
# File 'app/concerns/versioning.rb', line 162

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)

Returns:

  • (Boolean)


110
111
112
# File 'app/concerns/versioning.rb', line 110

def editor_selectable?
  published? || read_attribute(:published_version_id).blank?
end

#enable_validations_for_publishingObject



158
159
160
# File 'app/concerns/versioning.rb', line 158

def enable_validations_for_publishing
  @_run_validations_for_publishing = true
end

#in_review?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'app/concerns/versioning.rb', line 140

def in_review?
  read_attribute(:to_review).present?
end

#lock_by_user(user_id) ⇒ Object



114
115
116
117
118
# File 'app/concerns/versioning.rb', line 114

def lock_by_user(user_id)
  tap do
    write_attribute(:locked_by, user_id)
  end
end

#locked?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'app/concerns/versioning.rb', line 120

def locked?
  locked_by?
end

#publishObject



170
171
172
173
174
175
176
# File 'app/concerns/versioning.rb', line 170

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/concerns/versioning.rb', line 188

def publish!
  with_validations_for_publishing do
    publish
    save!
  end
end

#publishable?Boolean

Returns:

  • (Boolean)


195
196
197
198
199
# File 'app/concerns/versioning.rb', line 195

def publishable?
  with_validations_for_publishing do
    valid?
  end
end

#published?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'app/concerns/versioning.rb', line 184

def published?
  read_attribute(:published_at).present?
end

#stateObject



124
125
126
127
128
129
130
131
132
# File 'app/concerns/versioning.rb', line 124

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_reviewObject



144
145
146
147
148
# File 'app/concerns/versioning.rb', line 144

def to_review
  tap do
    write_attribute(:to_review, true)
  end
end

#unlockObject



134
135
136
137
138
# File 'app/concerns/versioning.rb', line 134

def unlock
  tap do
    write_attribute(:locked_by, nil)
  end
end

#unpublishObject



178
179
180
181
182
# File 'app/concerns/versioning.rb', line 178

def unpublish
  tap do
    write_attribute(:published_at, nil)
  end
end

#validatable_for_publishing?Boolean

Returns:

  • (Boolean)


166
167
168
# File 'app/concerns/versioning.rb', line 166

def validatable_for_publishing?
  @_run_validations_for_publishing
end

#with_validations_for_publishingObject



150
151
152
153
154
155
156
# File 'app/concerns/versioning.rb', line 150

def with_validations_for_publishing
  enable_validations_for_publishing
  status = yield
  disable_validations_for_publishing

  return status
end