Sha256: abca92e7289d4d0ce906ea0bcacb7ce82ebc814e78e79e9bea82d3ca2eabcac4
Contents?: true
Size: 1.27 KB
Versions: 7
Compression:
Stored size: 1.27 KB
Contents
require 'gir_ffi/builders/registered_type_builder' require 'gir_ffi/enum_base' module GirFFI module Builders # Implements the creation of an enum or flags type. The type will be # attached to the appropriate namespace module, and will be defined # as an enum for FFI. class EnumBuilder < RegisteredTypeBuilder private def enum_sym @classname.to_sym end def value_spec info.values.map do|vinfo| val = GirFFI::ArgHelper.cast_uint32_to_int32(vinfo.value) [vinfo.name.to_sym, val] end.flatten end def setup_class setup_ffi_enum klass.extend superclass setup_constants stub_methods setup_inspect end def klass @klass ||= get_or_define_module namespace_module, @classname end def setup_ffi_enum @enum = optionally_define_constant klass, :Enum do lib.enum(enum_sym, value_spec) end end def setup_inspect klass.instance_eval <<-EOS def self.inspect "#{@namespace}::#{@classname}" end EOS end def already_set_up klass.respond_to? :gtype end def superclass @superclass ||= EnumBase end end end end
Version data entries
7 entries across 7 versions & 1 rubygems