method
define_enum_methods
v6.1.3.1 -
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, enum_scopes)
private
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