data_collector 0.21.0 → 0.23.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: 919f205875cd4bdd02d951b50fba36833743c96eb887d8b183bdb4fabcff62d2
4
- data.tar.gz: 6feefeb606971a467dbf1cd47d39a3e76b5e23563fbd81c7be37f07f9c2f4bc2
3
+ metadata.gz: 1a6db4367b12a41101620cc818a1995868aab20b65157de8c19ea60c68aa90a0
4
+ data.tar.gz: 39a2cbcd665f85d71bda741a131c54d4f2871ae83ae63b86c9eed9f0d84e405a
5
5
  SHA512:
6
- metadata.gz: d51898627739f4047234e617ed10e8686cbcdc76782ea9cdf78ed5c566ed18801de0938d0abe6d57d734297a066904043a29027d33b3de6ef35fbe255cf19c2b
7
- data.tar.gz: cd05871afe0d9d9bcb698abb96292d7ed4780d41c3ddeb74db649abb7512f4c06f3991c11211cb2d574d7636de68a4fa1b23fa817943f894666fa64ff4aa31f8
6
+ metadata.gz: 5d7e6e243f9693603c4502b2f1bbe2fb64b8cf95718be257066940d6fafed24a8352ded805f285b617e25f5fbd703bf6e812dbd9f2b85d5c22cc143e7cdfdc1e
7
+ data.tar.gz: 73b0c03ef6ccb7855cfc1b6f424c543cc00fc79e182ccc2525c068f3b8d97535e4eaaaa66b0fd59225049d6a0dfb3dc55861319638dfb4c6df489ede6c1f9077
@@ -8,6 +8,17 @@ module DataCollector
8
8
  super
9
9
  end
10
10
 
11
+ def run(should_block = false, &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
20
+ end
21
+
11
22
  def running?
12
23
  @listener.processing?
13
24
  end
@@ -15,7 +26,10 @@ module DataCollector
15
26
  private
16
27
 
17
28
  def create_listener
18
- @listener ||= Listen.to("#{@uri.host}/#{@uri.path}", @options) do |modified, added, _|
29
+ absolute_path = File.absolute_path("#{URI.decode_uri_component(@uri.to_s)}")
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, _|
19
33
  files = added | modified
20
34
  files.each do |filename|
21
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))
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,8 @@ 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
+ absolute_path = File.absolute_path("#{URI.decode_uri_component(uri.to_s)}")
164
+ raise DataCollector::Error, "#{uri.to_s} not found" unless File.exist?("#{absolute_path}")
158
165
  unless options.has_key?('raw') && options['raw'] == true
159
166
  @raw = data = File.read("#{absolute_path}")
160
167
  case File.extname(absolute_path)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module DataCollector
3
- VERSION = "0.21.0"
3
+ VERSION = "0.23.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_collector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Celik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-17 00:00:00.000000000 Z
11
+ date: 2023-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport