Class: Peeky::Renderer::MethodCallMinimumParamsRender
- Inherits:
-
Object
- Object
- Peeky::Renderer::MethodCallMinimumParamsRender
- 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
-
#method_signature ⇒ Object
readonly
Method signature stores a MethodInfo object.
Instance Method Summary collapse
-
#initialize(method_signature, **opts) ⇒ MethodCallMinimumParamsRender
constructor
A new instance of MethodCallMinimumParamsRender.
-
#render ⇒ Object
Render the a method call with minimal parameters.
Constructor Details
#initialize(method_signature, **opts) ⇒ MethodCallMinimumParamsRender
Returns a new instance of MethodCallMinimumParamsRender.
14 15 16 17 18 19 |
# 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 = opts[:instance_name] @class_name = opts[:class_name] @method_signature = method_signature end |
Instance Attribute Details
#method_signature ⇒ Object (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
#render ⇒ Object
Render the a method call with minimal parameters
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/peeky/renderer/method_call_minimum_params_render.rb', line 22 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})" return "#{@instance_name}.#{name}#{params}" unless @instance_name.nil? return "#{@class_name}.#{name}#{params}" unless @class_name.nil? "#{name}#{params}" end |