method
define_delegated_type_methods
v6.1.7.7 -
Show latest stable
-
0 notes -
Class: DelegatedType
- 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)
- What's this?
define_delegated_type_methods(role, types:)
private
Hide source
# File activerecord/lib/active_record/delegated_type.rb, line 176 def define_delegated_type_methods(role, types)) role_type = "#{role}_type" role_id = "#{role}_id" define_method "#{role}_class" do public_send("#{role}_type").constantize end define_method "#{role}_name" do public_send("#{role}_class").model_name.singular.inquiry end types.each do |type| scope_name = type.tableize.gsub("/", "_") singular = scope_name.singularize query = "#{singular}?" scope scope_name, -> { where(role_type => type) } define_method query do public_send(role_type) == type end define_method singular do public_send(role) if public_send(query) end define_method "#{singular}_id" do public_send(role_id) if public_send(query) end end end