lib/ar_enums/enum.rb in ar-enums-0.3.8 vs lib/ar_enums/enum.rb in ar-enums-0.3.9

- old
+ new

@@ -24,11 +24,16 @@ def == other return id == other.id if other.is_a?(Enum) [id.to_s, name].include?(other.to_s) end + alias_method :eql?, :== + def hash + id.hash + end + def to_s try_labelize(self, :desc) || try_labelize(name, :titleize) end def to_sym @@ -40,9 +45,12 @@ define_enums_getter ActiveRecord::Enumerations::Factory.make_enums(*config, &block) end def self.[] name_or_id all.detect { |enum| enum == name_or_id } + end + class << self + alias_method :find_by_id, :[] end def self.find_all_by_id ids, options = {} all.select { |enum| ids.include? enum.id } end