Class: Metadata::ViewBuilder

Inherits:
BuilderBase
  • Object
show all
Defined in:
app/models/metadata/view_builder.rb

Instance Attribute Summary

Attributes inherited from BuilderBase

#locals

Instance Method Summary collapse

Methods inherited from BuilderBase

#view_for

Constructor Details

#initialize(*args) ⇒ ViewBuilder

Returns a new instance of ViewBuilder.



3
4
5
6
7
# File 'app/models/metadata/view_builder.rb', line 3

def initialize(*args, &)
  super
  view_for(:plain_value, 'shared/metadata/plain_field')
  view_for(:file, 'shared/metadata/file')
end

Instance Method Details

#association_attribute(association_name, attribute, options = {}) ⇒ Object



23
24
25
26
27
# File 'app/models/metadata/view_builder.rb', line 23

def association_attribute(association_name, attribute, options = {})
  render_view(:plain_value, :"#{association_name}_id", options) do |locals|
    locals.merge(value: @object.try(association_name).try(attribute))
  end
end

#file(field, options = {}) ⇒ Object



19
20
21
# File 'app/models/metadata/view_builder.rb', line 19

def file(field, options = {})
  render_view(:file, field, options) { |locals| locals.merge(document: @object.send(field)) }
end

#plain_value(field, options = {}) ⇒ Object



9
10
11
# File 'app/models/metadata/view_builder.rb', line 9

def plain_value(field, options = {})
  render_view(:plain_value, field, options) { |locals| locals.merge(value: @object.send(field)) }
end

#yes_or_no(field, options = {}) ⇒ Object



13
14
15
16
17
# File 'app/models/metadata/view_builder.rb', line 13

def yes_or_no(field, options = {})
  render_view(:plain_value, field, options) do |locals|
    locals.merge(value: @object.send(field).present? ? 'Yes' : 'No')
  end
end