Sha256: 8cc3385609e5a9f04946f1d116b4a1d866c4f4fa0fb6106e17ca25fbd2c78511

Contents?: true

Size: 1.6 KB

Versions: 7

Compression:

Stored size: 1.6 KB

Contents

module GirFFI
  module Builder
    module Type

      # Implements method creation for types such as, :union, :struct,
      # :object, :interface.
      module WithMethods
        def setup_method method
          klass = build_class
          meta = (class << klass; self; end)

          go = method_introspection_data method
          attach_and_define_method method, go, meta
        end

        def setup_instance_method method
          go = instance_method_introspection_data method
          attach_and_define_method method, go, build_class
        end

        private

        def method_introspection_data method
          info.find_method method
        end

        def instance_method_introspection_data method
          data = method_introspection_data method
          return !data.nil? && data.method? ? data : nil
        end

        def function_definition go
          Builder::Function.new(go, lib).generate
        end

        def attach_and_define_method method, go, modul
          return false if go.nil?
          Builder.attach_ffi_function lib, go
          modul.class_eval { remove_method method }
          modul.class_eval function_definition(go)
          true
        end

        def stub_methods
          info.get_methods.each do |minfo|
            @klass.class_eval method_stub(minfo.name, minfo.method?)
          end
        end

        def method_stub symbol, is_instance_method
          "
            def #{is_instance_method ? '' : 'self.'}#{symbol} *args, &block
              setup_and_call :#{symbol}, *args, &block
            end
          "
        end

      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gir_ffi-0.2.1 lib/gir_ffi/builder/type/with_methods.rb
gir_ffi-0.2.0 lib/gir_ffi/builder/type/with_methods.rb
gir_ffi-0.1.0 lib/gir_ffi/builder/type/with_methods.rb
gir_ffi-0.0.14 lib/gir_ffi/builder/type/with_methods.rb
gir_ffi-0.0.13 lib/gir_ffi/builder/type/with_methods.rb
gir_ffi-0.0.12 lib/gir_ffi/builder/type/with_methods.rb
gir_ffi-0.0.11 lib/gir_ffi/builder/type/with_methods.rb