Class: Renderer::Component::MethodArgument

Inherits:
Renderer::Component show all
Defined in:
lib/renderer/component/method_argument.rb

Constant Summary collapse

REST_ARG_BY_TYPE =
{
  kwrest: :double,
  rest: :single,
  block: :block
}.freeze

Instance Attribute Summary

Attributes inherited from Renderer::Component

#id

Instance Method Summary collapse

Methods inherited from Renderer::Component

#initialize, prop, #props, #render, #template

Constructor Details

This class inherits a constructor from Renderer::Component

Instance Method Details

#continuation_for_typeObject



22
23
24
25
26
27
28
# File 'lib/renderer/component/method_argument.rb', line 22

def continuation_for_type
  if arg.keyword? && !arg.rest?
    :colon
  elsif arg.optional?
    :equal
  end
end

#prepareObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/renderer/component/method_argument.rb', line 8

def prepare
  @type = @arg.kind
  @name = @arg.name
  @value = @arg.value&.source
  @value_type = @arg.value_type

  @computed = {
    rest: rest_arg,
    name:,
    continuation: continuation_for_type,
    value: value_for_argument
  }
end

#rest_argObject



36
37
38
# File 'lib/renderer/component/method_argument.rb', line 36

def rest_arg
  REST_ARG_BY_TYPE[type]
end

#value_for_argumentObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/renderer/component/method_argument.rb', line 40

def value_for_argument
  return if value_type.nil?

  case value_type
  when :symbol, :bool
    { kind: :symbol, value: }
  when :nil
    { kind: :symbol, value: "nil" }
  when :number
    { kind: :number, value: }
  when :string
    { kind: :string, value: }
  when :call
    { kind: :call, value: }
  when :const
    { kind: :const, value: [value] }
  else
    { kind: :plain, value: }
  end
end