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

#filter, #view_for

Constructor Details

#initialize(*args, &block) ⇒ ViewBuilder


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

def initialize(*args, &block)
  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


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

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

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


16
17
18
# File 'app/models/metadata/view_builder.rb', line 16

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

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


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

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


12
13
14
# File 'app/models/metadata/view_builder.rb', line 12

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