Sha256: d79f4ffaad554f200de8173d9a0553028a9ca37dc1f751d3db4f32d4d097dcea

Contents?: true

Size: 877 Bytes

Versions: 31

Compression:

Stored size: 877 Bytes

Contents

require 'workflow'
class Article
  include Workflow
  workflow do
    state :new do
      event :submit, :transitions_to => :awaiting_review
    end
    state :awaiting_review do
      event :review, :transitions_to => :being_reviewed
    end
    state :being_reviewed do
      event :accept, :transitions_to => :accepted
      event :reject, :transitions_to => :rejected
    end
    state :accepted
    state :rejected
  end
end

article = Article.new
article.accepted? # => false
article.new? # => true
article.submit!
article.review!

puts article.current_state # => being_reviewed


class Article
  def reject
    puts "send email to the author here explaining the reason for the rejection"
  end
end

article.reject! # will cause a state transition, would persist the new
  # state (if inherited from ActiveRecord), and invoke the callback -
  # send email to the author.

Version data entries

31 entries across 31 versions & 7 rubygems

Version Path
validating-workflow-0.7.12 test/readme_example.rb
validating-workflow-0.7.11 test/readme_example.rb
validating-workflow-0.7.10 test/readme_example.rb
validating-workflow-0.7.9 test/readme_example.rb
workflow-orchestrator-1.3.1 test/readme_example.rb
workflow-orchestrator-1.3.0 test/readme_example.rb
validating-workflow-0.7.7 test/readme_example.rb
workflow-1.2.0 test/readme_example.rb
validating-workflow-0.7.6 test/readme_example.rb
workflow-1.1.0 test/readme_example.rb
workflow-rails4-1.1.0 test/readme_example.rb
workflow_on_mongoid-1.0.0.0 test/readme_example.rb
workflow-1.0.0 test/readme_example.rb
workflow-0.8.7 test/readme_example.rb
workflow_on_mongoid-0.8.0.7 test/readme_example.rb
workflow-0.8.6 test/readme_example.rb
workflow-0.8.4 test/readme_example.rb
workflow-0.8.3 test/readme_example.rb
workflow_on_mongoid-0.8.0.6 test/readme_example.rb
workflow_on_mongoid-0.8.0.5 test/readme_example.rb