data_collector 0.22.0 → 0.24.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: e8333bf619cbafbac678351542ff0680abafd8d02fbe79ef286a1998eb85d3e4
4
- data.tar.gz: bac65514f7f0314004feec335b20bc512e09ec1c62526321eefd61e7b98beece
3
+ metadata.gz: 7745e79eb3836ab3c469cc5da39f395d42c144940b98115c96058fb01f8a629c
4
+ data.tar.gz: 77aeb246a6a23477d07195c020091999825af21c9639c0a9679017daefeea9e9
5
5
  SHA512:
6
- metadata.gz: d4b60f51ba32d710f89b396379847785c36d522fbfa190eb3a27527dea53e87a277e7f7d814e01a0639f8c64705b40b4621a21f19b0aa3afb1d8ee4aa56edd86
7
- data.tar.gz: 1566edaa8ca58544d5747cd86b73b9f1d66ed52f684aecba62c4ceb695a096cb7b1f5063e973b42eafda65732bd6f5664210bd53ec83489f9c3b5d5b9d233935
6
+ metadata.gz: e48596ac6e5fc14be89c2aadc50416558fa4a08594d28cccee630c1157dc365a556999c82d303e4669c94e1db88d6b0cf3f044730d0057586220a6c3172b72a6
7
+ data.tar.gz: 2112dfa9191e8aa948317a16d581a9ea487327030cb013b43937757c144c33ca4fc975faee91fd6731d8f043ed0cefd5ecc28a562351c5de9b96196167871e36
@@ -9,8 +9,14 @@ module DataCollector
9
9
  end
10
10
 
11
11
  def run(should_block = false, &block)
12
- @listener.start
13
- sleep if should_block
12
+ @listener.start unless running?
13
+ if block_given?
14
+ while should_block && !paused?
15
+ yield
16
+ end
17
+ else
18
+ sleep if should_block && running? && !paused?
19
+ end
14
20
  end
15
21
 
16
22
  def running?
@@ -20,7 +26,10 @@ module DataCollector
20
26
  private
21
27
 
22
28
  def create_listener
23
- @listener ||= Listen.to("#{@uri.host}#{@uri.path}", @options) do |modified, added, _|
29
+ absolute_path = File.absolute_path("#{@uri.host}#{@uri.path}")
30
+ raise DataCollector::Error, "#{@uri.to_s} not found" unless File.exist?(absolute_path)
31
+
32
+ @listener ||= Listen.to(absolute_path, @options) do |modified, added, _|
24
33
  files = added | modified
25
34
  files.each do |filename|
26
35
  handle_on_message(@input, @output, filename)
@@ -4,7 +4,7 @@ module DataCollector
4
4
  class Input
5
5
  class Generic
6
6
  def initialize(uri, options = {})
7
- @uri = uri
7
+ @uri = URI(URI.decode_uri_component(uri.to_s)) #"#{uri.scheme}://#{URI.decode_uri_component(uri.host)}#{URI.decode_uri_component(uri.path)}"
8
8
  @options = options
9
9
  @running = false
10
10
 
@@ -28,6 +28,10 @@ module DataCollector
28
28
  def from_uri(source, options = {})
29
29
  source = CGI.unescapeHTML(source)
30
30
  @logger.info("Reading #{source}")
31
+ raise DataCollector::Error 'from_uri expects a scheme like file:// of https://' unless source =~ /:\/\//
32
+
33
+ scheme, path = source.split('://')
34
+ source="#{scheme}://#{URI.encode_uri_component(path)}"
31
35
  uri = URI(source)
32
36
  begin
33
37
  data = nil
@@ -37,11 +41,12 @@ module DataCollector
37
41
  when 'https'
38
42
  data = from_https(uri, options)
39
43
  when 'file'
40
- if File.directory?("#{uri.host}/#{uri.path}")
41
- raise DataCollector::Error, "#{uri.host}/#{uri.path} not found" unless File.exist?("#{uri.host}/#{uri.path}")
44
+ absolute_path = File.absolute_path("#{URI.decode_uri_component("#{uri.host}#{uri.path}")}")
45
+ if File.directory?(absolute_path)
46
+ #raise DataCollector::Error, "#{uri.host}/#{uri.path} not found" unless File.exist?("#{uri.host}/#{uri.path}")
42
47
  return from_dir(uri, options)
43
48
  else
44
- raise DataCollector::Error, "#{uri.host}/#{uri.path} not found" unless File.exist?("#{uri.host}/#{uri.path}")
49
+ # raise DataCollector::Error, "#{uri.host}/#{uri.path} not found" unless File.exist?("#{uri.host}/#{uri.path}")
45
50
  data = from_file(uri, options)
46
51
  end
47
52
  when /amqp/
@@ -75,6 +80,7 @@ module DataCollector
75
80
  end
76
81
 
77
82
  def from_https(uri, options = {})
83
+ uri = URI.decode_uri_component("#{uri.to_s}")
78
84
  data = nil
79
85
  if options.with_indifferent_access.include?(:logging) && options.with_indifferent_access[:logging]
80
86
  HTTP.default_options = HTTP::Options.new(features: { logging: { logger: @logger } })
@@ -154,7 +160,9 @@ module DataCollector
154
160
 
155
161
  def from_file(uri, options = {})
156
162
  data = nil
157
- absolute_path = File.absolute_path("#{uri.host}#{uri.path}")
163
+ uri = normalize_uri(uri)
164
+ absolute_path = File.absolute_path(uri)
165
+ raise DataCollector::Error, "#{uri.to_s} not found" unless File.exist?("#{absolute_path}")
158
166
  unless options.has_key?('raw') && options['raw'] == true
159
167
  @raw = data = File.read("#{absolute_path}")
160
168
  case File.extname(absolute_path)
@@ -226,5 +234,8 @@ module DataCollector
226
234
  return file_type
227
235
  end
228
236
 
237
+ def normalize_uri(uri)
238
+ "#{URI.decode_uri_component(uri.host)}#{URI.decode_uri_component(uri.path)}"
239
+ end
229
240
  end
230
241
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module DataCollector
3
- VERSION = "0.22.0"
3
+ VERSION = "0.24.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_collector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Celik