Module: GLib

Defined in:
glib2/lib/glib2.rb,
glib2/lib/glib2.rb

Defined Under Namespace

Modules: Log, MetaSignal, Module Classes: Enum, Flags, Instantiatable, Object, Thread, Type, UserDirectory

Constant Summary collapse

SIGNAL_HANDLER_PREFIX =
"signal_do_"
VIRTUAL_FUNCTION_IMPLEMENTATION_PREFIX =
"virtual_do_"
LOG_DOMAIN =
"GLib"

Class Method Summary collapse

Class Method Details

.__add_one_arg_setter(klass) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'glib2/lib/glib2.rb', line 49

def __add_one_arg_setter(klass)
  # for Instance methods.
  method_names = klass.instance_methods(false)
  method_names.each do |method_name|
    next if /\Aset_/ !~ method_name
    property_name = $POSTMATCH
    next if klass.method_defined?("#{property_name}=")
    next if klass.instance_method(method_name).arity != 1
    begin
      klass.module_eval("def #{property_name}=(val); set_#{property_name}(val); val; end\n")
    rescue SyntaxError
      if $DEBUG
        $stderr.puts "Couldn't create #{klass}\##{property_name}=(v)."
      end
    end
  end

  # for Class methods/Module functions.
  if klass.method(:methods).arity == -1
    method_names = klass.methods(false)
  else
    method_names = klass.methods
  end
  singleton_klass = (class << klass; self; end)
  method_names.each do |method_name|
    next if /\Aset_/ !~ method_name
    property_name = $POSTMATCH
    next if singleton_klass.method_defined?("#{property_name}=")
    next if klass.method(method_name).arity != 1
    begin
      klass.module_eval("def self.#{property_name}=(val); set_#{property_name}(val); val; end\n")
    rescue SyntaxError
      if $DEBUG
        $stderr.puts "Couldn't create #{klass}.#{property_name}=(v)."
      end
    end
  end
end

.check_binding_version?(major, minor, micro) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
# File 'glib2/lib/glib2.rb', line 24

def check_binding_version?(major, minor, micro)
  BINDING_VERSION[0] > major ||
    (BINDING_VERSION[0] == major &&
     BINDING_VERSION[1] > minor) ||
    (BINDING_VERSION[0] == major &&
     BINDING_VERSION[1] == minor &&
     BINDING_VERSION[2] >= micro)
end

.exit_application(exception, status) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'glib2/lib/glib2.rb', line 33

def exit_application(exception, status)
  msg = exception.message || exception.to_s
  msg = exception.class.to_s if msg == ""
  backtrace = exception.backtrace || []
  first_line = backtrace.shift
  if first_line
    $stderr.puts("#{first_line}: #{msg}")
  else
    $stderr.puts(msg)
  end
  backtrace.each do |v|
    $stderr.puts("\t from #{v}")
  end
  exit(status)
end

.prepend_dll_path(path) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
# File 'glib2/lib/glib2.rb', line 103

def prepend_dll_path(path)
  path = Pathname(path) unless path.is_a?(Pathname)
  return unless path.exist?

  begin
    require "ruby_installer/runtime"
  rescue LoadError
  else
    RubyInstaller::Runtime.add_dll_directory(path.to_s)
  end
  prepend_path_to_environment_variable(path, "PATH")
end

.prepend_path_to_environment_variable(path, environment_name) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'glib2/lib/glib2.rb', line 88

def prepend_path_to_environment_variable(path, environment_name)
  path = Pathname(path) unless path.is_a?(Pathname)
  return unless path.exist?

  dir = path.to_s
  dir = dir.gsub(/\//, ::File::ALT_SEPARATOR) if ::File::ALT_SEPARATOR

  separator = ::File::PATH_SEPARATOR
  paths = (ENV[environment_name] || '').split(separator)
  unless paths.include?(dir)
    paths = [dir] + paths
    ENV[environment_name] = paths.join(separator)
  end
end