class GirFFI::Builders::MethodTemplate
Encapsulates the general structure of generated methods, consisting of a preparation phase where arguments are converted to the form needed by the main call of the method, the main call itself, a post-processing phase where the return values and any 'out' arguments of the main call are converted into a form suitable for returning, and finally the returning of said values to the caller.
The different method builders collaborate with MethodTemplate
to build the desired method.
Public Class Methods
new(builder, argument_builder_collection)
click to toggle source
# File lib/gir_ffi/builders/method_template.rb, line 15 def initialize(builder, argument_builder_collection) @builder = builder @argument_builder_collection = argument_builder_collection end
Public Instance Methods
method_definition()
click to toggle source
# File lib/gir_ffi/builders/method_template.rb, line 20 def method_definition code = "def #{qualified_method_name}" code += "(#{method_arguments.join(', ')})" if method_arguments.any? method_lines.each { |line| code += "\n #{line}" } code + "\nend\n" end
Private Instance Methods
capturing_invocation()
click to toggle source
# File lib/gir_ffi/builders/method_template.rb, line 74 def capturing_invocation ["#{result_name_list} = #{@builder.invocation}"] end
invocation()
click to toggle source
# File lib/gir_ffi/builders/method_template.rb, line 53 def invocation if result_name_list.empty? plain_invocation else capturing_invocation end end
method_arguments()
click to toggle source
# File lib/gir_ffi/builders/method_template.rb, line 33 def method_arguments @builder.method_arguments end
method_lines()
click to toggle source
# File lib/gir_ffi/builders/method_template.rb, line 37 def method_lines method_preparation + parameter_preparation + invocation + return_value_conversion + result end
method_preparation()
click to toggle source
# File lib/gir_ffi/builders/method_template.rb, line 45 def method_preparation @builder.preparation end
parameter_preparation()
click to toggle source
# File lib/gir_ffi/builders/method_template.rb, line 49 def parameter_preparation @argument_builder_collection.parameter_preparation end
plain_invocation()
click to toggle source
# File lib/gir_ffi/builders/method_template.rb, line 78 def plain_invocation [@builder.invocation].compact end
qualified_method_name()
click to toggle source
# File lib/gir_ffi/builders/method_template.rb, line 29 def qualified_method_name "#{@builder.singleton_method? ? 'self.' : ''}#{@builder.method_name}" end
result()
click to toggle source
# File lib/gir_ffi/builders/method_template.rb, line 65 def result @builder.result end
result_name_list()
click to toggle source
# File lib/gir_ffi/builders/method_template.rb, line 69 def result_name_list @result_name_list ||= @argument_builder_collection.capture_variable_names.join(", ") end
return_value_conversion()
click to toggle source
# File lib/gir_ffi/builders/method_template.rb, line 61 def return_value_conversion @argument_builder_collection.return_value_conversion end