Sha256: 0dfd0e88cfbb72905561071877c87830b4a269565947690b572fcb362c472069

Contents?: true

Size: 710 Bytes

Versions: 3

Compression:

Stored size: 710 Bytes

Contents

# frozen_string_literal: true

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)
      prefix, suffix = definitions[:_prefix], definitions[:_suffix] if Rails::VERSION::STRING >= '5'
      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), prefix, suffix, &block
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stateful_enum-0.5.0 lib/stateful_enum/active_record_extension.rb
stateful_enum-0.4.0 lib/stateful_enum/active_record_extension.rb
stateful_enum-0.3.1 lib/stateful_enum/active_record_extension.rb