lib/power_enum/enumerated.rb in power_enum-1.3.1 vs lib/power_enum/enumerated.rb in power_enum-1.3.2

- old
+ new

@@ -1,12 +1,14 @@ # Copyright (c) 2005 Trevor Squires # Copyright (c) 2012 Arthur Shagall # Released under the MIT License. See the LICENSE file for more details. +# Implementation of acts_as_enumerated module PowerEnum::Enumerated extend ActiveSupport::Concern + # Class level methods injected into ActiveRecord. module ClassMethods # Returns false for ActiveRecord models that do not act as enumerated. def acts_as_enumerated? false @@ -127,10 +129,12 @@ end end private :get_name_column end + # These are class level methods which are patched into classes that act as + # enumerated module EnumClassMethods attr_accessor :enumeration_model_updates_permitted # Returns true for ActiveRecord models that act as enumerated. def acts_as_enumerated? @@ -275,12 +279,12 @@ # ---Private methods--- def load_all conditions = self.acts_enumerated_conditions - order = self.acts_enumerated_order - where(conditions).order(order) + order = self.acts_enumerated_order + unscoped.where(conditions).order(order) end private :load_all # Looks up the enum based on the type of the argument. def lookup_enum_by_type(arg) @@ -334,55 +338,58 @@ raise end end private :all_by_name - def all_by_attribute(attr) + def all_by_attribute(attr) # :nodoc: aba = all.inject({}) { |memo, item| memo[item.send(attr)] = item memo } aba.freeze unless enumerations_model_updating? aba end private :all_by_attribute - def enforce_none(arg) + def enforce_none(arg) # :nodoc: nil end private :enforce_none - def enforce_strict(arg) + def enforce_strict(arg) # :nodoc: raise_record_not_found(arg) end private :enforce_strict - def enforce_strict_literals(arg) + def enforce_strict_literals(arg) # :nodoc: raise_record_not_found(arg) if (Fixnum === arg) || (Symbol === arg) nil end private :enforce_strict_literals - def enforce_strict_ids(arg) + def enforce_strict_ids(arg) # :nodoc: raise_record_not_found(arg) if Fixnum === arg nil end private :enforce_strict_ids - def enforce_strict_symbols(arg) + def enforce_strict_symbols(arg) # :nodoc: raise_record_not_found(arg) if Symbol === arg nil end private :enforce_strict_symbols + # raise the {ActiveRecord::RecordNotFound} error. + # @private def raise_record_not_found(arg) raise ActiveRecord::RecordNotFound, "Couldn't find a #{self.name} identified by (#{arg.inspect})" end private :raise_record_not_found end + # These are instance methods for objects which are enums. module EnumInstanceMethods # Behavior depends on the type of +arg+. # # * If +arg+ is +nil+, returns +false+. # * If +arg+ is an instance of +Symbol+, +Fixnum+ or +String+, returns the result of +BookingStatus[:foo] == BookingStatus[arg]+. @@ -463,6 +470,6 @@ false end end private :enumeration_model_update end # module EnumInstanceMethods -end # module PowerEnum::Enumerated \ No newline at end of file +end # module PowerEnum::Enumerated