Class: Formatic::Choices::Records
- Inherits:
-
Object
- Object
- Formatic::Choices::Records
- Includes:
- Calls
- Defined in:
- lib/formatic/choices/records.rb
Overview
Returns a list of countries suitable for a <select> box.
Instance Method Summary collapse
- #association ⇒ Object
- #call ⇒ Object
- #currently_associated_record ⇒ Object
- #include_current? ⇒ Boolean
- #records_to_options ⇒ Object
Instance Method Details
#association ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/formatic/choices/records.rb', line 38 def association model_klass = f&.object&.class return false unless model_klass.respond_to?(:reflect_on_all_associations) model_klass.reflect_on_all_associations(:belongs_to) .detect { it.foreign_key == attribute_name.to_s } end |
#call ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/formatic/choices/records.rb', line 14 def call candidates = || [] return candidates unless currently_associated_record && include_current? return candidates if records&.include?(currently_associated_record) candidates.prepend currently_associated_record.presenters.for_select candidates end |
#currently_associated_record ⇒ Object
31 32 33 34 35 36 |
# File 'lib/formatic/choices/records.rb', line 31 def currently_associated_record return unless association return unless f.object f.object.public_send(association.name) end |
#include_current? ⇒ Boolean
23 24 25 |
# File 'lib/formatic/choices/records.rb', line 23 def include_current? include_current != false end |
#records_to_options ⇒ Object
27 28 29 |
# File 'lib/formatic/choices/records.rb', line 27 def records&.map(&:presenters)&.map(&:for_select) end |