Class: Metadata::ViewBuilder
- Inherits:
-
BuilderBase
- Object
- ActionView::Helpers::FormBuilder
- BuilderBase
- Metadata::ViewBuilder
- Defined in:
- app/models/metadata/view_builder.rb
Instance Attribute Summary
Attributes inherited from BuilderBase
Instance Method Summary collapse
- #association_attribute(association_name, attribute, options = {}) ⇒ Object
- #file(field, options = {}) ⇒ Object
-
#initialize(*args) ⇒ 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) ⇒ 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, = {}) render_view(:plain_value, :"#{association_name}_id", ) 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, = {}) render_view(:file, field, ) { |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, = {}) render_view(:plain_value, field, ) { |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, = {}) render_view(:plain_value, field, ) do |locals| locals.merge(value: @object.send(field).present? ? 'Yes' : 'No') end end |