Sha256: 5451d229491e1b2eb61f79213382b45c6a95ec255bcf4df9865ba03834d37d33

Contents?: true

Size: 529 Bytes

Versions: 1

Compression:

Stored size: 529 Bytes

Contents

require "enum_behavior/version"
require "enum_behavior/base"

require "active_support"
require "active_support/core_ext"

module EnumBehavior
  extend ActiveSupport::Concern

  class_methods do
    def enum_behavior(enum_name)
      behavior_name = "#{enum_name}_behavior"
      define_method(behavior_name) do
        current = public_send(enum_name)
        return nil if current.nil?
        class_name = "#{self.class.name.pluralize}::#{current.camelize}"
        class_name.constantize.new(self)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
enum_behavior-0.1.0 lib/enum_behavior.rb