Module: ShowFor::Association
- Included in:
- Builder
- Defined in:
- lib/show_for/association.rb
Instance Method Summary collapse
- #association(association_name, options = {}, &block) ⇒ Object
- #attribute(attribute_name, options = {}, &block) ⇒ Object
Instance Method Details
#association(association_name, options = {}, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/show_for/association.rb', line 12 def association(association_name, = {}, &block) (association_name, ) # If a block with an iterator was given, no need to calculate the labels # since we want the collection to be yielded. Otherwise, calculate the values. value = if collection_block?(block) collection_block = block @object.send(association_name) elsif block block else association = @object.send(association_name) values = values_from_association(association, ) if .delete(:to_sentence) values.to_sentence elsif joiner = .delete(:join) values.join(joiner) else values end end wrap_label_and_content(association_name, value, , &collection_block) end |
#attribute(attribute_name, options = {}, &block) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/show_for/association.rb', line 3 def attribute(attribute_name, = {}, &block) if association_name = .delete(:in) [:using] = attribute_name association(association_name, , &block) else super end end |