method
define_enum_methods
v7.1.3.2 -
Show latest stable
-
0 notes -
Class: EnumMethods
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
define_enum_methods(name, value_method_name, value, scopes, instance_methods)
private
Hide source
# File activerecord/lib/active_record/enum.rb, line 305 def define_enum_methods(name, value_method_name, value, scopes, instance_methods) if instance_methods # 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) } end if scopes # scope :active, -> { where(status: 0) } klass.send(:detect_enum_conflict!, name, value_method_name, true) klass.scope value_method_name, -> { where(name => value) } # scope :not_active, -> { where.not(status: 0) } klass.send(:detect_enum_conflict!, name, "not_#{value_method_name}", true) klass.scope "not_#{value_method_name}", -> { where.not(name => value) } end end