tom 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.0
data/lib/dispatcher.rb CHANGED
@@ -13,14 +13,14 @@ module Tom
13
13
  def self.dispatch(env)
14
14
 
15
15
  # 1. hit APIs. All at the same time. Oh, mygodd!
16
- Tom::LOG.info "#{env['REQUEST_METHOD'].upcase} #{env['REQUEST_URI']}"
16
+ Tom::Log.logger.info "#{env['REQUEST_METHOD'].upcase} #{env['REQUEST_URI']}"
17
17
  responses = parallel_adapter_dispatch(env)
18
18
 
19
19
  # 2. merge
20
20
  merged = merge(env, responses)
21
21
 
22
22
  # 3. ???
23
- Tom::LOG.info "-------------------------------------------------------n"
23
+ Tom::Log.logger.info "-------------------------------------------------------"
24
24
 
25
25
  # 4. profit
26
26
  merged
@@ -40,8 +40,8 @@ module Tom
40
40
  def self.merge(env, responses)
41
41
  route, method = route_and_method(env)
42
42
  if merger = Tom::Routes.merger_for_route(route, method)
43
- Tom::LOG.info "Merging with:"
44
- Tom::LOG.info " -> #{merger}"
43
+ Tom::Log.logger.info "Merging with:"
44
+ Tom::Log.logger.info " -> #{merger}"
45
45
  merged = merger.new.merge(env, responses)
46
46
  else
47
47
  merged = [404, {}, ""]
@@ -78,9 +78,9 @@ module Tom
78
78
  adapters = Tom::Routes.adapters_for_route(route, method)
79
79
  return responses if adapters.empty?
80
80
 
81
- Tom::LOG.info "Dispatching to:"
81
+ Tom::Log.logger.info "Dispatching to:"
82
82
  EM::Synchrony::FiberIterator.new(adapters, adapters.count).map do |clazz|
83
- Tom::LOG.info " -> #{clazz}"
83
+ Tom::Log.logger.info " -> #{clazz}"
84
84
  (responses[clazz] ||= []) << clazz.new.handle(env)
85
85
  end
86
86
  responses
data/lib/goliath_api.rb CHANGED
@@ -22,8 +22,8 @@ module Tom
22
22
  # Hardcoded JSON stacktrace stuff for now...
23
23
  def handle_exception(e, env)
24
24
  trace = e.backtrace.join "\n"
25
- Tom::LOG.info e
26
- Tom::LOG.info trace
25
+ Tom::Log.logger.info e
26
+ Tom::Log.logger.info trace
27
27
  [500, {}, {error: e,
28
28
  stacktrace: trace,
29
29
  url: env["REQUEST_URI"]
data/lib/http.rb CHANGED
@@ -12,11 +12,13 @@ module Tom
12
12
  # @param options [Hash] Options to pass to EM::HttpRequest's
13
13
  # get/put/post/delete method
14
14
  def self.make_request(method, url, options = {})
15
- Tom::LOG.info " curl -X#{method.upcase} -d '#{options[:body]}' #{url}"
15
+ Tom::Log.logger.info " curl -X#{method.upcase} -d '#{options[:body]}' #{url}"
16
16
 
17
17
  conn = EM::HttpRequest.new(url, connection_options)
18
18
  result = conn.send(method, options)
19
- handle_errors(method, url, result)
19
+
20
+ # Disabling this for a while
21
+ # handle_errors(method, url, result)
20
22
 
21
23
  result
22
24
  end
data/lib/init.rb CHANGED
@@ -7,9 +7,9 @@ Goliath.env rescue Goliath.env = (ENV['RACK_ENV'] || 'development').to_sym
7
7
  # In dev mode, we do some logging (defaults to Logger::ERROR in other
8
8
  # envs)
9
9
  if Goliath.env == :development || ENV['BOBS']
10
- Tom::LOG.level = Logger::INFO
10
+ Tom::Log.logger.level = Logger::INFO
11
11
  end
12
- Tom::LOG.info "Started goliath in #{Goliath.env} environment (change with ruby your_app.rb -e development or by setting $RACK_ENV)"
12
+ Tom::Log.logger.info "Started goliath in #{Goliath.env} environment (change with ruby your_app.rb -e development or by setting $RACK_ENV)"
13
13
 
14
14
  # Fetch the codes
15
15
  require_relative 'goliath_api'
data/lib/tom/log.rb CHANGED
@@ -1,11 +1,28 @@
1
1
  require 'logger'
2
2
 
3
3
  module Tom
4
- LOG = ::Logger.new(STDOUT)
5
- LOG.level = ::Logger::ERROR
6
- LOG.datetime_format = "%H:%M:%S:"
7
- Logger::Formatter.module_eval(
8
- %q{ def call(severity, time, progname, msg)} +
9
- %q{ "#{format_datetime(time)} #{msg2str(msg)}\n" end}
10
- )
4
+ module Log
5
+
6
+
7
+ def self.logger=(logger)
8
+ @logger = logger
9
+ end
10
+
11
+ def self.logger
12
+ unless @logger
13
+ @logger = ::Logger.new(STDOUT)
14
+ init_logger_defaults
15
+ end
16
+ @logger
17
+ end
18
+
19
+ def self.init_logger_defaults
20
+ @logger.level = ::Logger::ERROR
21
+ @logger.datetime_format = "%H:%M:%S:"
22
+ Logger::Formatter.module_eval(
23
+ %q{ def call(severity, time, progname, msg)} +
24
+ %q{ "#{format_datetime(time)} #{msg2str(msg)}\n" end}
25
+ )
26
+ end
27
+ end
11
28
  end
data/tom.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "tom"
8
- s.version = "0.2.2"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jannis Hermanns"]
12
- s.date = "2011-12-09"
12
+ s.date = "2011-12-13"
13
13
  s.description = " Tom uses Goliath to dispatch HTTP requests to multiple other APIs (via Adapters) in parallel. In a next step, a Merger merges the result and responds to the clients request."
14
14
  s.email = "jannis@gmail.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-09 00:00:00.000000000Z
12
+ date: 2011-12-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: goliath
16
- requirement: &70294091681900 !ruby/object:Gem::Requirement
16
+ requirement: &70192164200580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70294091681900
24
+ version_requirements: *70192164200580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: em-synchrony
27
- requirement: &70294091681320 !ruby/object:Gem::Requirement
27
+ requirement: &70192164200000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70294091681320
35
+ version_requirements: *70192164200000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: em-http-request
38
- requirement: &70294091680840 !ruby/object:Gem::Requirement
38
+ requirement: &70192164199480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70294091680840
46
+ version_requirements: *70192164199480
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: json
49
- requirement: &70294091680220 !ruby/object:Gem::Requirement
49
+ requirement: &70192164198920 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70294091680220
57
+ version_requirements: *70192164198920
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &70294091679620 !ruby/object:Gem::Requirement
60
+ requirement: &70192164198340 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.9.2
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70294091679620
68
+ version_requirements: *70192164198340
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
- requirement: &70294091679080 !ruby/object:Gem::Requirement
71
+ requirement: &70192164197820 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.0.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70294091679080
79
+ version_requirements: *70192164197820
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: jeweler
82
- requirement: &70294091678600 !ruby/object:Gem::Requirement
82
+ requirement: &70192164197320 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.6.4
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70294091678600
90
+ version_requirements: *70192164197320
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: shoulda
93
- requirement: &70294091677960 !ruby/object:Gem::Requirement
93
+ requirement: &70192164196780 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70294091677960
101
+ version_requirements: *70192164196780
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rcov
104
- requirement: &70294091677440 !ruby/object:Gem::Requirement
104
+ requirement: &70192164196280 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70294091677440
112
+ version_requirements: *70192164196280
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: ruby-debug19
115
- requirement: &70294091676940 !ruby/object:Gem::Requirement
115
+ requirement: &70192164195780 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70294091676940
123
+ version_requirements: *70192164195780
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: rspec
126
- requirement: &70294091667620 !ruby/object:Gem::Requirement
126
+ requirement: &70192164195280 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70294091667620
134
+ version_requirements: *70192164195280
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: webmock
137
- requirement: &70294091667000 !ruby/object:Gem::Requirement
137
+ requirement: &70192164194780 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70294091667000
145
+ version_requirements: *70192164194780
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: yard
148
- requirement: &70294091666380 !ruby/object:Gem::Requirement
148
+ requirement: &70192164194220 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *70294091666380
156
+ version_requirements: *70192164194220
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: rdiscount
159
- requirement: &70294091665740 !ruby/object:Gem::Requirement
159
+ requirement: &70192164193660 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ! '>='
@@ -164,7 +164,7 @@ dependencies:
164
164
  version: '0'
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *70294091665740
167
+ version_requirements: *70192164193660
168
168
  description: ! ' Tom uses Goliath to dispatch HTTP requests to multiple other APIs
169
169
  (via Adapters) in parallel. In a next step, a Merger merges the result and responds
170
170
  to the clients request.'
@@ -212,7 +212,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
212
212
  version: '0'
213
213
  segments:
214
214
  - 0
215
- hash: -4134106071848066876
215
+ hash: 1893692767236117233
216
216
  required_rubygems_version: !ruby/object:Gem::Requirement
217
217
  none: false
218
218
  requirements: