buddy 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/buddy/middleware.rb +36 -0
- data/lib/buddy/railtie.rb +3 -0
- data/lib/buddy/version.rb +1 -1
- metadata +4 -4
data/lib/buddy/middleware.rb
CHANGED
@@ -1,6 +1,42 @@
|
|
1
1
|
module Buddy
|
2
2
|
module Middleware
|
3
3
|
|
4
|
+
class Logger < ::Rails::Rack::Logger
|
5
|
+
private
|
6
|
+
def before_dispatch(env)
|
7
|
+
request = ActionDispatch::Request.new(env)
|
8
|
+
path = request.fullpath
|
9
|
+
|
10
|
+
method_s = request.request_method
|
11
|
+
method_s += " (#{env['rack.methodoverride.original_method']})" if env['rack.methodoverride.original_method']
|
12
|
+
|
13
|
+
info "\n\nStarted #{method_s} \"#{path}\" " \
|
14
|
+
"for #{request.ip} at #{Time.now.to_default_s}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class MethodOverride
|
19
|
+
HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS)
|
20
|
+
|
21
|
+
def initialize(app)
|
22
|
+
@app = app
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
request = Rack::Request.new(env)
|
27
|
+
|
28
|
+
method = 'GET' if request.post? && !request.xhr? && request.params['authenticity_token'].nil? && request.params['_method'].nil?
|
29
|
+
method = request.params['_method'].to_s.upcase unless request.params['_method'].nil?
|
30
|
+
|
31
|
+
if method && HTTP_METHODS.include?(method)
|
32
|
+
env['rack.methodoverride.original_method'] = env['REQUEST_METHOD']
|
33
|
+
env['REQUEST_METHOD'] = method
|
34
|
+
end
|
35
|
+
|
36
|
+
@app.call(env)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
4
40
|
# This Rack middleware checks the signed_request, and
|
5
41
|
# appends the payload to Rails params.
|
6
42
|
#
|
data/lib/buddy/railtie.rb
CHANGED
@@ -5,7 +5,10 @@ require 'rails'
|
|
5
5
|
module Buddy
|
6
6
|
class Railtie < ::Rails::Railtie
|
7
7
|
initializer "buddy.configure_rails_initialization" do |app|
|
8
|
+
app.config.middleware.swap(::Rails::Rack::Logger, Buddy::Middleware::Logger)
|
9
|
+
app.config.middleware.insert_before(Buddy::Middleware::Logger, Buddy::Middleware::MethodOverride)
|
8
10
|
app.config.middleware.insert_before(ActionDispatch::ParamsParser, Buddy::Middleware::ParamsParser)
|
11
|
+
|
9
12
|
ActionView::Helpers::UrlHelper.send(:include, Buddy::Rails::UrlHelper)
|
10
13
|
Buddy.logger = ::Rails.logger
|
11
14
|
end
|
data/lib/buddy/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buddy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.3
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ole Riesenberg
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-07 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|