Class: Infold::DecoratorWriter

Inherits:
BaseWriter show all
Defined in:
lib/infold/writers/decorator_writer.rb

Instance Attribute Summary

Attributes inherited from BaseWriter

#resource

Instance Method Summary collapse

Methods inherited from BaseWriter

#edit_path, #indent, #index_path, #initialize, #new_path, #resource_name, #show_path

Constructor Details

This class inherits a constructor from Infold::BaseWriter

Instance Method Details

#decorator_codeObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/infold/writers/decorator_writer.rb', line 5

def decorator_code
  codes = @resource.decorator_fields&.map do |field|
    case field.decorator.kind
    when :enum
      enum_code(field).presence
    when :boolean
      boolean_code(field.name).presence
    when :datetime
      datetime_code(field.name).presence
    when :date
      date_code(field.name).presence
    when :number
      number_code(field.name, field.decorator).presence
    else
      string_code(field.name, field.decorator).presence
    end
  end
  indent(codes.compact.join("\n"), 2) if codes.present?
end