Sha256: fa2a6563683778c92d79e80781b5026d5eb88e566fa11f26f7554bf3b63bfc41

Contents?: true

Size: 849 Bytes

Versions: 1

Compression:

Stored size: 849 Bytes

Contents

module GirFFI
  module Builder
    class DynamicType
      CACHE = {}

      def initialize gtype
        @gtype = gtype
      end

      def build_class
        CACHE[@gtype] ||= Class.new(parent).tap do |klass|
          interfaces.each do |iface|
            klass.class_eval do
              include iface
            end
          end
        end
      end

      private

      def parent
        parent_type = ::GObject.type_parent @gtype
        info = gir.find_by_gtype(parent_type)
        GirFFI::Builder.build_class info
      end

      def interfaces
        iface_types = ::GObject.type_interfaces @gtype
        iface_types.map do |gtype|
          info = gir.find_by_gtype gtype
          GirFFI::Builder.build_class info
        end
      end

      def gir
        @gir ||= GirFFI::IRepository.default
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gir_ffi-0.0.10 lib/gir_ffi/builder/dynamic_type.rb