Sha256: 46e9cda38e6d1144bf8768fe5f0ad6c2a705f88e7321db1c932e6bd1bf9f5eec

Contents?: true

Size: 1.44 KB

Versions: 9

Compression:

Stored size: 1.44 KB

Contents

require 'active_support/concern'

module Georgia
  module Concerns
    module Statable
      extend ActiveSupport::Concern

      included do

        attr_accessible :state
        state_machine :state, initial: :draft do

          state :published
          state :draft
          state :review
          state :revision

          # Drafts
          event :review do
            transition all => :review
          end

          # Reviews
          event :approve do
            transition [:draft, :review] => :published
          end
          event :decline do
            transition :review => :draft
          end

          # Published
          event :store do
            transition :published => :revision
          end
          event :unpublish do
            transition :published => :draft
          end

          # Revisions
          event :restore do
            transition :revision => :published
          end

          before_transition any => :published do |revision, transition|
            revision.revisionable.approve_revision(revision)
          end

        end

        scope :published, with_states(:published)
        scope :drafts, with_states(:draft)
        scope :reviews, with_states(:review)
        scope :stored, with_states(:revision)

        def status_name
          warn "[DEPRECATION] `status_name` is deprecated.  Please use `human_state_name` instead."
          human_state_name
        end

      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
georgia-0.7.8 app/models/georgia/concerns/statable.rb
georgia-0.7.7 app/models/georgia/concerns/statable.rb
georgia-0.7.6 app/models/georgia/concerns/statable.rb
georgia-0.7.5 app/models/georgia/concerns/statable.rb
georgia-0.7.4 app/models/georgia/concerns/statable.rb
georgia-0.7.3 app/models/georgia/concerns/statable.rb
georgia-0.7.2 app/models/georgia/concerns/statable.rb
georgia-0.7.1 app/models/georgia/concerns/statable.rb
georgia-0.7.0 app/models/georgia/concerns/statable.rb