eat 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -0
- data/lib/eat.rb +36 -22
- data/lib/eat/version.rb +1 -1
- data/test/test_eat.rb +4 -0
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
25
|
-
|
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
|
data/lib/eat/version.rb
CHANGED
data/test/test_eat.rb
CHANGED
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:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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-
|
18
|
+
date: 2011-01-18 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|