Class: Peeky::Renderer::MethodCallMinimumParamsRender

Inherits:
Object
  • Object
show all
Defined in:
lib/peeky/renderer/method_call_minimum_params_render.rb

Overview

Render: Simple instance method calls with minimum parameters

Example output:

instance.simple('first_param')
instance.complex('aaa', ddd: 'ddd')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_signature, **opts) ⇒ MethodCallMinimumParamsRender

Returns a new instance of MethodCallMinimumParamsRender.


14
15
16
17
18
# File 'lib/peeky/renderer/method_call_minimum_params_render.rb', line 14

def initialize(method_signature, **opts)
  instance_name = opts[:instance_name] || 'instance'
  @instance_name = instance_name
  @method_signature = method_signature
end

Instance Attribute Details

#method_signatureObject (readonly)

Method signature stores a MethodInfo object


12
13
14
# File 'lib/peeky/renderer/method_call_minimum_params_render.rb', line 12

def method_signature
  @method_signature
end

Instance Method Details

#renderObject

Render the a method call with minimal parameters


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/peeky/renderer/method_call_minimum_params_render.rb', line 21

def render
  name = method_signature.name

  minimal_call_parameters = method_signature
                            .parameters
                            .map(&:minimal_call_format)
                            .reject { |minimal_call| minimal_call.nil? || minimal_call.strip.empty? }
                            .join(', ')

  params = minimal_call_parameters.length.zero? ? '' : "(#{minimal_call_parameters})"

  "#{@instance_name}.#{name}#{params}"
end