Module: ShowFor::Association

Included in:
Builder
Defined in:
lib/show_for/association.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) association(association_name, options = {}, &block)



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, options={}, &block)
  apply_default_options!(association_name, options)

  # 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, options)

    if options.delete(:to_sentence)
      values.to_sentence
    elsif joiner = options.delete(:join)
      values.join(joiner)
    else
      values
    end
  end

  wrap_label_and_content(association_name, value, options, &collection_block)
end

- (Object) attribute(attribute_name, options = {}, &block)



3
4
5
6
7
8
9
10
# File 'lib/show_for/association.rb', line 3

def attribute(attribute_name, options={}, &block)
  if association_name = options.delete(:in)
    options[:using] = attribute_name
    association(association_name, options, &block)
  else
    super
  end
end