whiplash-app 0.9.1 → 0.9.2

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: dccfbc052c641052a83cdaeeda9231a5303c96041f9755187cf59a0b5f48b7a8
4
- data.tar.gz: 3dfb8c5cd0ac077c817a628bed55323907484ac32ccf566f1e7f778071942cc8
3
+ metadata.gz: 90618c9787cb8660f4fcb0be146bdb14736ce8635274f9b262f68813268bd35d
4
+ data.tar.gz: a26cca38e01f5c5642b94afe39cbc0be6ea08f05c9ccf446d0d802e5548aa100
5
5
  SHA512:
6
- metadata.gz: dc050d5563f89987d926714a04806f473f1df4f4943efbce813b61e22400061f620b95e3ec27396497e051d1267d3abd230252c402ca36fc579cb7cfcf9b592a
7
- data.tar.gz: 53345d8bc82e9a3e8ac09e91cab22a7db12b0cc1c8e0bc1eaf80caf330384d08974d8b622cba21790bd1f4456a3a6607ccc27da216983c82b4ccb2f60570b6d2
6
+ metadata.gz: d67a3f4a633319407cb8dd9a6717a92b57480825dab3fa36b4e77fda280f58c16089aa833a39fade900dee77efeaa169b868e3ba5f0e25832e37105da40ad53b
7
+ data.tar.gz: 94df31ed65be70e565fb5ea8ba2744dbfbbfe386500d8ae5c57bce4bd72474ff0af70f4ea9620e02f2a108282d24821c6477b0107d0b55146249c690010f8d07
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ module Whiplash
3
+ class App
4
+ module CanonicalHost
5
+ extend ActiveSupport::Concern
6
+
7
+ private
8
+
9
+ def require_canonical_host!
10
+ canonical_host = ENV.fetch('CANONICAL_HOST', false).in?([true, 'true', 1, '1'])
11
+ return unless canonical_host
12
+ application_host = URI.parse(Rails.configuration.app_url).host
13
+ return if application_host == request.host
14
+ return unless request.method_symbol == :get # can't redirect PUT, POST, DELETE
15
+
16
+ redirect_to_canonical_host request.query_parameters
17
+ end
18
+
19
+ def redirect_to_canonical_host(query_params, status=301)
20
+ redirect_to "#{Rails.configuration.app_url}#{request.path}#{'?' if query_params.to_query.present?}#{query_params.to_query}", status: status
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whiplash
4
+ module Logs
5
+ class Railtie < Rails::Railtie
6
+ initializer "whiplash_app.action_controller" do
7
+ ActiveSupport.on_load(:action_controller) do
8
+ puts "Extending #{self} with YourGemsModuleName::Controller"
9
+ include Whiplash::App::CanonicalHost
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  module Whiplash
2
2
  class App
3
- VERSION = "0.9.1"
3
+ VERSION = "0.9.2"
4
4
  end
5
5
  end
data/lib/whiplash/app.rb CHANGED
@@ -7,6 +7,12 @@ require "errors/whiplash_api_error"
7
7
  require "oauth2"
8
8
  require "faraday"
9
9
 
10
+ # Rails app stuff
11
+ if defined?(Rails::Railtie)
12
+ require "whiplash/app/canonical_host"
13
+ require "whiplash/app/railtie"
14
+ end
15
+
10
16
  module Whiplash
11
17
  class App
12
18
  include Whiplash::App::ApiConfig
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whiplash-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Don Sullivan, Mark Dickson
@@ -115,8 +115,10 @@ files:
115
115
  - lib/errors/whiplash_api_error.rb
116
116
  - lib/whiplash/app.rb
117
117
  - lib/whiplash/app/api_config.rb
118
+ - lib/whiplash/app/canonical_host.rb
118
119
  - lib/whiplash/app/connections.rb
119
120
  - lib/whiplash/app/finder_methods.rb
121
+ - lib/whiplash/app/railtie.rb
120
122
  - lib/whiplash/app/signing.rb
121
123
  - lib/whiplash/app/version.rb
122
124
  - whiplash-app.gemspec