Module: Iqvoc::Versioning

Extended by:
ActiveSupport::Concern
Included in:
Concept::Base
Defined in:
lib/iqvoc/versioning.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#branch(user) ⇒ Object

********* Instance methods



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/iqvoc/versioning.rb', line 85

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

#editor_selectable?Boolean

Editor selectable if published or no published version exists (before first publication)

Returns:

  • (Boolean)


116
117
118
# File 'lib/iqvoc/versioning.rb', line 116

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

#in_review?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/iqvoc/versioning.rb', line 142

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

#lock_by_user(user_id) ⇒ Object



120
121
122
# File 'lib/iqvoc/versioning.rb', line 120

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

#locked?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/iqvoc/versioning.rb', line 124

def locked?
  locked_by?
end

#publishObject



100
101
102
103
104
# File 'lib/iqvoc/versioning.rb', line 100

def publish
  write_attribute(:published_at, Time.now)
  write_attribute(:to_review, nil)
  write_attribute(:published_version_id, nil)
end

#published?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/iqvoc/versioning.rb', line 110

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

#stateObject



128
129
130
131
132
133
134
135
136
# File 'lib/iqvoc/versioning.rb', line 128

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



146
147
148
# File 'lib/iqvoc/versioning.rb', line 146

def to_review
  write_attribute(:to_review, true)
end

#unlockObject



138
139
140
# File 'lib/iqvoc/versioning.rb', line 138

def unlock
  write_attribute(:locked_by, nil)
end

#unpublishObject



106
107
108
# File 'lib/iqvoc/versioning.rb', line 106

def unpublish
  write_attribute(:published_at, nil)
end