Module: Workflow::WorkflowClassMethods

Defined in:
lib/workflow.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#workflow_specObject (readonly)

Returns the value of attribute workflow_spec.



98
99
100
# File 'lib/workflow.rb', line 98

def workflow_spec
  @workflow_spec
end

Instance Method Details

#workflow(&specification) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/workflow.rb', line 110

def workflow(&specification)
  @workflow_spec = Specification.new(Hash.new, &specification)
  @workflow_spec.states.values.each do |state|
    state_name = state.name
    module_eval do
      define_method "#{state_name}?" do
        state_name == current_state.name
      end
    end

    state.events.values.each do |event|
      event_name = event.name
      module_eval do
        define_method "#{event_name}!".to_sym do |*args|
          process_event!(event_name, *args)
        end

        define_method "can_#{event_name}?" do
          return self.current_state.events.include? event_name
        end
      end
    end
  end
end

#workflow_column(column_name = nil) ⇒ Object



100
101
102
103
104
105
106
107
108
# File 'lib/workflow.rb', line 100

def workflow_column(column_name=nil)
  if column_name
    @workflow_state_column_name = column_name.to_sym
  end
  if !@workflow_state_column_name && superclass.respond_to?(:workflow_column)
    @workflow_state_column_name = superclass.workflow_column
  end
  @workflow_state_column_name ||= :workflow_state
end