module WorkFlow

Public Instance Methods

aasm_state() click to toggle source
# File lib/buweb/concerns/work_flow.rb, line 117
def aasm_state
  self[:aasm_state] || "draft"
end
aasm_transition(event) click to toggle source
# File lib/buweb/concerns/work_flow.rb, line 121
def aasm_transition(event)
  self.send(event) if aasm.events.include?(event)
end
archive_at_cannot_be_before_publish_at() click to toggle source
# File lib/buweb/concerns/work_flow.rb, line 108
def archive_at_cannot_be_before_publish_at
  errors.add(:archive_at, "can't be earlier than the publish date.") if archive_at.present? && publish_at.present? && archive_at <= publish_at
end
enforce_publication_times() click to toggle source
# File lib/buweb/concerns/work_flow.rb, line 134
def enforce_publication_times
  if should_transition_to_published?
    self.publish
  elsif should_transition_to_archived?
    self.archive
  end
end
only_archive() click to toggle source
# File lib/buweb/concerns/work_flow.rb, line 112
def only_archive
  errors.add(:archive_at, "can't be set without a publish date.") if archive_at.present? && publish_at.blank?
end
should_transition_to_archived?() click to toggle source
# File lib/buweb/concerns/work_flow.rb, line 130
def should_transition_to_archived?
  published? && archive_at && archive_at.past?
end
should_transition_to_published?() click to toggle source

Only transition to published automatically like this if it has been approved

# File lib/buweb/concerns/work_flow.rb, line 126
def should_transition_to_published?
  approved? && publish_at && publish_at.past? && (archive_at.blank? || archive_at.future?)
end

Private Instance Methods

broadcast_workflow_event(event) click to toggle source

wrapper for Wisper::Publisher broadcast method

# File lib/buweb/concerns/work_flow.rb, line 145
def broadcast_workflow_event(event)
  broadcast(event, self.class, self.id, self.modifier.try(:class), self.modifier.try(:id))
end