Module: Gio::File

Extended by:
GLib::Deprecatable
Defined in:
lib/gio2/file.rb,
lib/gio2/deprecated.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.open(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gio2/file.rb', line 20

def open(options={})
  arg = options[:arg]
  cwd = options[:cwd]
  path = options[:path]
  uri = options[:uri]

  if arg
    if cwd
      file = new_for_commandline_arg_and_cmd(arg, cwd)
    else
      file = new_for_commandline_arg(arg)
    end
  elsif path
    path = path.to_path if path.respond_to?(:to_path)
    file = new_for_path(path)
  elsif uri
    file = new_for_uri(uri)
  else
    message = "must specify :arg, :path or :uri: #{options.inspect}"
    raise ArgumentError, message
  end

  if block_given?
    yield(file)
  else
    file
  end
end

Instance Method Details

#read(cancellable = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/gio2/file.rb', line 51

def read(cancellable=nil)
  input_stream = read_raw(cancellable)
  return input_stream unless block_given?

  begin
    yield(input_stream)
  ensure
    input_stream.close unless input_stream.closed?
  end
end

#read_rawObject



50
# File 'lib/gio2/file.rb', line 50

alias_method :read_raw, :read