class GObjectIntrospection::Loader::Invoker
Public Class Methods
Source
# File lib/gobject-introspection/loader.rb, line 682 def initialize(info, method_name, full_method_name) @info = info @method_name = method_name @full_method_name = full_method_name @prepared = false ensure_prepared if defined?(Ractor) end
Public Instance Methods
Source
# File lib/gobject-introspection/loader.rb, line 690 def invoke(receiver, arguments, block, abort_tag=nil) ensure_prepared if receiver and @function_info_p arguments.unshift(receiver) end arguments, block = build(receiver, arguments, block) if wrong_number_of_arguments?(arguments) if abort_tag throw(abort_tag) else raise ArgumentError, invalid_error_message(arguments) end end unless normalize_arguments!(arguments, abort_tag) return @value_on_invalid end if block.nil? and @require_callback_p receiver.to_enum(@method_name, *arguments) else if @function_info_p return_value = @info.invoke(arguments, &block) else return_value = @info.invoke(receiver, arguments, &block) end if @have_return_value_p return_value else receiver end end end
Source
# File lib/gobject-introspection/loader.rb, line 725 def signature ensure_prepared argument_signatures = @in_args.collect(&:signature) "(" + argument_signatures.join(", ") + ")" end
Private Instance Methods
Source
# File lib/gobject-introspection/loader.rb, line 778 def build(receiver, arguments, block) if block and @last_in_arg_is_gclosure arguments << block block = nil end n_missing_arguments = @n_in_args - arguments.size n_in_arg_nil_indexes = @in_arg_nil_indexes.size if 0 < n_missing_arguments and n_missing_arguments < n_in_arg_nil_indexes @in_arg_nil_indexes[-n_missing_arguments..-1].each do |nil_index| arguments.insert(nil_index, nil) end end return arguments, block end
Source
# File lib/gobject-introspection/loader.rb, line 732 def ensure_prepared return if @prepared @in_args = @info.in_args @n_in_args = @in_args.size @n_required_in_args = @info.n_required_in_args @last_in_arg = @in_args.last if @last_in_arg @last_in_arg_is_gclosure = @last_in_arg.gclosure? else @last_in_arg_is_gclosure = false end @valid_n_args_range = (@n_required_in_args..@n_in_args) @in_arg_types = [] @in_arg_nils = [] @in_arg_nil_indexes = [] @in_args.each_with_index do |arg, i| @in_arg_types << arg.type may_be_null = arg.may_be_null? @in_arg_nils << may_be_null @in_arg_nil_indexes << i if may_be_null end @function_info_p = (@info.class == FunctionInfo) @have_return_value_p = @info.have_return_value? @require_callback_p = @info.require_callback? prepare_on_invalid @prepared = true end
Source
# File lib/gobject-introspection/loader.rb, line 819 def invalid_error_message(arguments) detail = "#{arguments.size} for " if @n_in_args == @n_required_in_args detail << "#{@n_in_args}" else detail << "#{@n_required_in_args}..#{@n_in_args}" end "#{@full_method_name}: wrong number of arguments (#{detail})" end
Source
# File lib/gobject-introspection/loader.rb, line 799 def normalize_arguments!(arguments, abort_tag) arguments.size.times do |i| argument = arguments[i] type = @in_arg_types[i] converted_argument = type.try_convert(argument) if converted_argument.nil? next if argument.nil? and @in_arg_nils[i] if abort_tag throw(abort_tag) elsif @on_invalid == :fallback return false else next end end arguments[i] = converted_argument end true end
Source
# File lib/gobject-introspection/loader.rb, line 765 def prepare_on_invalid case @method_name when "==" @value_on_invalid = false @on_invalid = :fallback when "!=" @value_on_invalid = true @on_invalid = :fallback else @on_invalid = :raise end end
Source
# File lib/gobject-introspection/loader.rb, line 795 def wrong_number_of_arguments?(arguments) not @valid_n_args_range.cover?(arguments.size) end