Class: Metadata::ViewBuilder
- Inherits:
-
BuilderBase
- Object
- ActionView::Helpers::FormBuilder
- BuilderBase
- Metadata::ViewBuilder
- Defined in:
- app/models/metadata/view_builder.rb
Overview
rubocop:todo Style/Documentation
Instance Attribute Summary
Attributes inherited from BuilderBase
Instance Method Summary collapse
- #association_attribute(association_name, attribute, options = {}) ⇒ Object
- #file(field, options = {}) ⇒ Object
-
#initialize(*args, &block) ⇒ ViewBuilder
constructor
A new instance of ViewBuilder.
- #plain_value(field, options = {}) ⇒ Object
- #yes_or_no(field, options = {}) ⇒ Object
Methods inherited from BuilderBase
Constructor Details
#initialize(*args, &block) ⇒ ViewBuilder
Returns a new instance of 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
22 23 24 25 26 |
# File 'app/models/metadata/view_builder.rb', line 22 def association_attribute(association_name, attribute, = {}) render_view(:plain_value, :"#{association_name}_id", ) do |locals| locals.merge(value: @object.try(association_name).try(attribute)) end end |
#file(field, options = {}) ⇒ Object
18 19 20 |
# File 'app/models/metadata/view_builder.rb', line 18 def file(field, = {}) render_view(:file, field, ) { |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, = {}) render_view(:plain_value, field, ) { |locals| locals.merge(value: @object.send(field)) } end |
#yes_or_no(field, options = {}) ⇒ Object
12 13 14 15 16 |
# File 'app/models/metadata/view_builder.rb', line 12 def yes_or_no(field, = {}) render_view(:plain_value, field, ) do |locals| locals.merge(value: @object.send(field).present? ? 'Yes' : 'No') end end |