Sha256: bf83d879b3886519fec4741af8044cc6115143edf8ff274014f41b34a1552f17

Contents?: true

Size: 562 Bytes

Versions: 1

Compression:

Stored size: 562 Bytes

Contents

require 'stateful_enum/machine'

module StatefulEnum
  module ActiveRecordEnumExtension
    #   enum status: {unassigned: 0, assigned: 1, resolved: 2, closed: 3} do
    #     event :assign do
    #       transition :unassigned => :assigned
    #     end
    #   end
    def enum(definitions, &block)
      enum = super definitions

      if block
        definitions.each_key do |column|
          states = enum[column]
          StatefulEnum::Machine.new self, column, (states.is_a?(Hash) ? states.keys : states), &block
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stateful_enum-0.2.1 lib/stateful_enum/active_record_extension.rb