Module: Serega::SeregaPlugins::Formatters::AttributeInstanceMethods

Defined in:
lib/serega/plugins/formatters/formatters.rb

Instance Method Summary collapse

Instance Method Details

#formatterObject



49
50
51
52
53
# File 'lib/serega/plugins/formatters/formatters.rb', line 49

def formatter
  return @formatter if instance_variable_defined?(:@formatter)

  @formatter = formatter_resolved
end

#formatter_resolvedObject



55
56
57
58
59
60
61
# File 'lib/serega/plugins/formatters/formatters.rb', line 55

def formatter_resolved
  formatter = opts[:format]
  return unless formatter

  formatter = self.class.serializer_class.config.formatters.opts.fetch(formatter) if formatter.is_a?(Symbol)
  formatter
end

#value_blockObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/serega/plugins/formatters/formatters.rb', line 63

def value_block
  return @value_block if instance_variable_defined?(:@value_block)
  return @value_block = super unless formatter

  new_value_block = formatted_block(formatter, super)

  # Format :const value in advance
  if opts.key?(:const)
    const_value = new_value_block.call
    new_value_block = proc { const_value }
  end

  @value_block = new_value_block
end