method

define_enum_methods

Importance_0
v6.1.3.1 - Show latest stable - 0 notes - Class: EnumMethods
define_enum_methods(name, value_method_name, value, enum_scopes) private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/enum.rb, line 234
          def define_enum_methods(name, value_method_name, value, enum_scopes)
            # def active?() status_for_database == 0 end
            klass.send(:detect_enum_conflict!, name, "#{value_method_name}?")
            define_method("#{value_method_name}?") { public_send(:"#{name}_for_database") == value }

            # def active!() update!(status: 0) end
            klass.send(:detect_enum_conflict!, name, "#{value_method_name}!")
            define_method("#{value_method_name}!") { update!(name => value) }

            # scope :active, -> { where(status: 0) }
            # scope :not_active, -> { where.not(status: 0) }
            if enum_scopes != false
              klass.send(:detect_enum_conflict!, name, value_method_name, true)
              klass.scope value_method_name, -> { where(name => value) }

              klass.send(:detect_enum_conflict!, name, "not_#{value_method_name}", true)
              klass.scope "not_#{value_method_name}", -> { where.not(name => value) }
            end
          end
Register or log in to add new notes.