Class: DRbFileClientReader

Inherits:
Object
  • Object
show all
Defined in:
lib/drb_fileclient-reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(location = nil, host: nil, port: '61010', debug: false) ⇒ DRbFileClientReader

Returns a new instance of DRbFileClientReader.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/drb_fileclient-reader.rb', line 12

def initialize(location=nil, host: nil, port: '61010', debug: false)

  @debug = debug
  @@file ||= nil

  if location then

    host = location[/(?<=^dfs:\/\/)[^\/:]+/]
    port = location[/(?<=^dfs:\/\/)[^:]+:(\d+)/,1]  || '61010'
    @@directory ||= location[/(?<=^dfs:\/\/)[^\/]+\/(.*)/,1]
  else
    @@directory ||= nil
  end

  DRb.start_service

end

Instance Method Details

#exist?(filename = @@filename) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/drb_fileclient-reader.rb', line 30

def exist?(filename=@@filename)

  return File.exist? filename unless @@directory or filename =~ /^dfs:\/\//

  if filename =~ /^dfs:\/\// then

    file, filename2 = parse_path(filename)
    @@file ||= file

  else

    filename2 = File.join(@@directory, filename)
  end

  @@file.exist?(filename2)

end

#read(filename = @@filename) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/drb_fileclient-reader.rb', line 48

def read(filename=@@filename)

  return File.read(filename) unless @@directory or filename =~ /^dfs:\/\//

  if filename =~ /^dfs:\/\// then
    file, path = parse_path(filename)
    @@file ||= file
  else
    path = File.join(@@directory, filename)
  end

  @@file.read path
end