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

********* Methods



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/iqvoc/versioning.rb', line 69

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)



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

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

#in_review?Boolean



126
127
128
# File 'lib/iqvoc/versioning.rb', line 126

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

#lock_by_user(user_id) ⇒ Object



104
105
106
# File 'lib/iqvoc/versioning.rb', line 104

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

#locked?Boolean



108
109
110
# File 'lib/iqvoc/versioning.rb', line 108

def locked?
  locked_by?
end

#publishObject



84
85
86
87
88
# File 'lib/iqvoc/versioning.rb', line 84

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

#published?Boolean



94
95
96
# File 'lib/iqvoc/versioning.rb', line 94

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

#stateObject



112
113
114
115
116
117
118
119
120
# File 'lib/iqvoc/versioning.rb', line 112

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



130
131
132
# File 'lib/iqvoc/versioning.rb', line 130

def to_review
  write_attribute(:to_review, true)
end

#unlockObject



122
123
124
# File 'lib/iqvoc/versioning.rb', line 122

def unlock
  write_attribute(:locked_by, nil)
end

#unpublishObject



90
91
92
# File 'lib/iqvoc/versioning.rb', line 90

def unpublish
  write_attribute(:published_at, nil)
end