eat 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,6 +12,10 @@ Try
12
12
  eat('http://169.254.169.254/latest/meta-data/security-groups')
13
13
  eat('/home/seamus/foo.txt')
14
14
 
15
+ ==Global configuration
16
+
17
+ ::Eat.config.remote_timeout = 10 #seconds
18
+
15
19
  ==Supported schemas
16
20
 
17
21
  * local filesystem (it will try to use <tt>sudo</tt> if it can't read the file)
data/lib/eat.rb CHANGED
@@ -1,30 +1,44 @@
1
1
  require 'uri'
2
+ require 'singleton'
2
3
 
3
4
  module Eat
4
- TIMEOUT = 2 # seconds
5
- def eat(filesystem_path_or_uri)
6
- uri = ::URI.parse filesystem_path_or_uri
7
- case uri.scheme
8
- when nil
9
- if ::File.readable? uri.path
10
- ::IO.read uri.path
11
- else
12
- `sudo cat #{uri.path}`
13
- end
14
- when 'http', 'https'
15
- require 'net/http'
16
- require 'net/https' if uri.scheme == 'https'
17
- (defined?(::SystemTimer) ? ::SystemTimer : ::Timeout).timeout(::Eat::TIMEOUT) do
18
- http = ::Net::HTTP.new uri.host, uri.port
19
- if uri.scheme == 'https'
20
- http.use_ssl = true
21
- # if you were trying to be real safe, you wouldn't use this library
22
- http.verify_mode = ::OpenSSL::SSL::VERIFY_NONE
5
+ def self.config
6
+ ::Eat::Config.instance
7
+ end
8
+
9
+ class Config
10
+ include ::Singleton
11
+ attr_writer :remote_timeout
12
+ def remote_timeout
13
+ @remote_timeout || 2 #seconds
14
+ end
15
+ end
16
+
17
+ module ObjectExtensions
18
+ def eat(filesystem_path_or_uri)
19
+ uri = ::URI.parse filesystem_path_or_uri
20
+ case uri.scheme
21
+ when nil
22
+ if ::File.readable? uri.path
23
+ ::IO.read uri.path
24
+ else
25
+ `sudo cat #{uri.path}`
23
26
  end
24
- http.start { |session| session.get uri.request_uri }
25
- end.body
27
+ when 'http', 'https'
28
+ require 'net/http'
29
+ require 'net/https' if uri.scheme == 'https'
30
+ (defined?(::SystemTimer) ? ::SystemTimer : ::Timeout).timeout(::Eat.config.remote_timeout) do
31
+ http = ::Net::HTTP.new uri.host, uri.port
32
+ if uri.scheme == 'https'
33
+ http.use_ssl = true
34
+ # if you were trying to be real safe, you wouldn't use this library
35
+ http.verify_mode = ::OpenSSL::SSL::VERIFY_NONE
36
+ end
37
+ http.start { |session| session.get uri.request_uri }
38
+ end.body
39
+ end
26
40
  end
27
41
  end
28
42
  end
29
43
 
30
- ::Object.send :include, ::Eat
44
+ ::Object.send :include, ::Eat::ObjectExtensions
@@ -1,3 +1,3 @@
1
1
  module Eat
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -9,6 +9,10 @@ class Tempfile
9
9
  end
10
10
 
11
11
  class TestEat < Test::Unit::TestCase
12
+ def setup
13
+ ::Eat.config.remote_timeout = 10
14
+ end
15
+
12
16
  def test_filesystem
13
17
  assert eat(__FILE__).include?('class TestEat < Test::Unit::TestCase')
14
18
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eat
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seamus Abshere
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-12 00:00:00 -06:00
18
+ date: 2011-01-18 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency