class Supa::Command

Constants

UnsupportedModifier

Public Class Methods

new(subject, representer:, tree:, name:, options: {}, &block) click to toggle source
# File lib/supa/command.rb, line 5
def initialize(subject, representer:, tree:, name:, options: {}, &block)
  @subject = subject
  @representer = representer
  @tree = tree
  @name = name
  @options = options
  @block = block
end

Public Instance Methods

represent() click to toggle source
# File lib/supa/command.rb, line 14
def represent
  raise NotImplementedError
end

Private Instance Methods

apply_render_flags(val) click to toggle source
# File lib/supa/command.rb, line 37
def apply_render_flags(val)
  val
end
empty_when_nil?() click to toggle source
# File lib/supa/command.rb, line 66
def empty_when_nil?
  @options.fetch(:empty_when_nil, false)
end
exec_on_representer?() click to toggle source
# File lib/supa/command.rb, line 54
def exec_on_representer?
  @options[:exec_context] == :representer
end
getter() click to toggle source
# File lib/supa/command.rb, line 58
def getter
  @options[:getter] || @name
end
hide?() click to toggle source
# File lib/supa/command.rb, line 70
def hide?
  false
end
hide_when_empty?() click to toggle source
# File lib/supa/command.rb, line 62
def hide_when_empty?
  @options.fetch(:hide_when_empty, false)
end
modifier() click to toggle source
# File lib/supa/command.rb, line 26
def modifier
  return @modifier if defined?(@modifier)

  if @options.key?(:modifier) && !@options[:modifier].is_a?(Symbol)
    raise UnsupportedModifier,
      "Object #{@options[:modifier].inspect} is not a valid modifier. Please provide symbolized method name."
  end

  @modifier = @options[:modifier]
end
raw_value() click to toggle source
# File lib/supa/command.rb, line 41
def raw_value
  exec_on_representer? ? value_from_representer : value_from_subject
end
value() click to toggle source
# File lib/supa/command.rb, line 20
def value
  return @value if defined?(@value)
  value = apply_render_flags(raw_value)
  @value = modifier ? @representer.send(modifier, value) : value
end
value_from_representer() click to toggle source
# File lib/supa/command.rb, line 50
def value_from_representer
  @representer.send(getter)
end
value_from_subject() click to toggle source
# File lib/supa/command.rb, line 45
def value_from_subject
  return @subject[getter] if @subject.is_a?(Hash)
  @subject.send(getter) if @subject
end