drb_fileclient-reader 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9410a7898afe8a74312baf93ec46b2820856f6fe9440835e4c77d203fad4bce
4
- data.tar.gz: 8203ae4e5c60e2eb48c8d3d743f5bb08c7837ce0255aa48a8e080b520e7aa8aa
3
+ metadata.gz: 35e7b5fb46fc689b46d8fd08096bee947c0f15530d70c66b1f0e90777b061b41
4
+ data.tar.gz: cdf706aa2b13c2071d9c03ec7532df068d6a5ba06b0ffd1fd3b16e4ea050ec30
5
5
  SHA512:
6
- metadata.gz: 9dc14a72dd41c645f0c905ecb64cddb1b5548a3dcbd833de8530707b6864f851a450d2eca780312ea0f118be5cf501835711a8d4d2b40b94093b76341c528bfe
7
- data.tar.gz: 430fc33bdab44ba1244bd13468f6e3d4b0e303f8e27b8eed2c4bf00ff28bd8cce9c0df38bd284a94e1452140e62843c7184d876b2e254440edc32e8875d02385
6
+ metadata.gz: 3d9d7f66b117d210ab42bfb2221c1422b4235f5b68952640754eff19bbea197b76d978d06a689ac567675bbb4e0e14c434a78f8b89b06bcb7f558d0661626403
7
+ data.tar.gz: aa9bdd3b7ef96ba9c1b035c34f7cd5744848075ab0ca873cd108b0baf0b1e0c7d7965c46a1e6b4cf6fa2e0951cf76b2e8b66d17775b9a1189bf2f4e4aea23413
checksums.yaml.gz.sig CHANGED
Binary file
@@ -2,8 +2,85 @@
2
2
 
3
3
  # file: drb_fileclient-reader.rb
4
4
 
5
+ require 'drb/drb'
6
+ require 'c32'
5
7
 
6
- # testing, please ignore this version
7
8
 
8
9
  class DRbFileClientReader
10
+ using ColouredText
11
+
12
+ def initialize(location=nil, host: nil, port: '61010', debug: false)
13
+
14
+ @debug = debug
15
+ @@file ||= nil
16
+
17
+ if location then
18
+
19
+ host = location[/(?<=^dfs:\/\/)[^\/:]+/]
20
+ port = location[/(?<=^dfs:\/\/)[^:]+:(\d+)/,1] || '61010'
21
+ @@directory ||= location[/(?<=^dfs:\/\/)[^\/]+\/(.*)/,1]
22
+ else
23
+ @@directory ||= nil
24
+ end
25
+
26
+ DRb.start_service
27
+
28
+ end
29
+
30
+ def exist?(filename=@@filename)
31
+
32
+ return File.exist? filename unless @@directory or filename =~ /^dfs:\/\//
33
+
34
+ if filename =~ /^dfs:\/\// then
35
+
36
+ file, filename2 = parse_path(filename)
37
+ @@file ||= file
38
+
39
+ else
40
+
41
+ filename2 = File.join(@@directory, filename)
42
+ end
43
+
44
+ @@file.exist?(filename2)
45
+
46
+ end
47
+
48
+ def read(filename=@@filename)
49
+
50
+ return File.read(filename) unless @@directory or filename =~ /^dfs:\/\//
51
+
52
+ if filename =~ /^dfs:\/\// then
53
+ file, path = parse_path(filename)
54
+ @@file ||= file
55
+ else
56
+ path = File.join(@@directory, filename)
57
+ end
58
+
59
+ @@file.read path
60
+ end
61
+
62
+ protected
63
+
64
+ def parse_path(filename)
65
+
66
+ host = filename[/(?<=^dfs:\/\/)[^\/:]+/]
67
+ @host = host if host
68
+
69
+ port = filename[/(?<=^dfs:\/\/)[^:]+:(\d+)/,1] || '61010'
70
+
71
+ file_server = DRbObject.new nil, "druby://#{host || @host}:#{port}"
72
+ [file_server, filename[/(?<=^dfs:\/\/)[^\/]+\/(.*)/,1], ("dfs://%s:%s" % [host, port])]
73
+
74
+ end
75
+
76
+ end
77
+
78
+ class DfsFile
79
+
80
+ @client = DRbFileClientReader.new
81
+
82
+ def self.exist?(filename) @client.exist?(filename) end
83
+ def self.exists?(filename) @client.exist?(filename) end
84
+ def self.read(filename) @client.read(filename) end
85
+
9
86
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drb_fileclient-reader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file