Sha256: 5b657f37373be79cee0c996eccaaf0180b744cefec41462c647bdc29578bf4ed

Contents?: true

Size: 602 Bytes

Versions: 1

Compression:

Stored size: 602 Bytes

Contents

# encoding: utf-8
module EnumField
  module DefineEnum
    def self.included(base)
      base.send :extend, ClassMethods
    end

    module ClassMethods
      def self.extended(base)
        base.class_eval do
          attr_reader :id, :name
        end
      end

      def define_enum(&block)
        @enum_builder ||= EnumField::Builder.new(self)
        yield @enum_builder

        EnumField::Builder::METHODS.each do |method|
          define_singleton_method method do |*args, &block|
            @enum_builder.send(method, *args, &block)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
galetahub-enum_field-0.4.0 lib/enum_field/define_enum.rb