Sha256: a80d633e43296ec6a7cec0bafbfb641df190cb6d370fe34d8c7c6b1bc845978a
Contents?: true
Size: 1.3 KB
Versions: 5
Compression:
Stored size: 1.3 KB
Contents
require 'active_enum/base' require 'active_enum/extensions' require 'active_enum/storage/abstract_store' module ActiveEnum autoload :VERSION, 'active_enum/version' mattr_accessor :enum_classes @@enum_classes = [] mattr_accessor :use_name_as_value @@use_name_as_value = false mattr_accessor :storage @@storage = :memory mattr_accessor :storage_options @@storage_options = {} def storage=(*args) @@storage_options = args.extract_options! @@storage = args.first end mattr_accessor :extend_classes @@extend_classes = [] # Setup method for plugin configuration def self.setup yield self extend_classes! end class EnumDefinitions def enum(name, &block) class_name = name.to_s.camelize eval("class #{class_name} < ActiveEnum::Base; end", TOPLEVEL_BINDING) new_enum = Module.const_get(class_name) new_enum.class_eval(&block) end end # Define enums in bulk def self.define(&block) raise "Define requires block" unless block_given? EnumDefinitions.new.instance_eval(&block) end def self.storage_class @@storage_class ||= "ActiveEnum::Storage::#{storage.to_s.classify}Store".constantize end private def self.extend_classes! extend_classes.each {|klass| klass.send(:include, ActiveEnum::Extensions) } end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
active_enum-0.9.7 | lib/active_enum.rb |
active_enum-0.9.6 | lib/active_enum.rb |
active_enum-0.9.5 | lib/active_enum.rb |
active_enum-0.9.4 | lib/active_enum.rb |
active_enum-0.9.3 | lib/active_enum.rb |