dbhijacker 0.10.1 → 0.10.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
  SHA1:
3
- metadata.gz: 966aefde0da55519c0a6f7138a3fe37fcffd82bd
4
- data.tar.gz: 64dd3131653b3bf6bcae3ada058526bb0b952929
3
+ metadata.gz: 18973a9ed00b466a40b0e395681ec42969ef9eb8
4
+ data.tar.gz: 4fb1e3627227267b236e3ec240f1ef580b8375e9
5
5
  SHA512:
6
- metadata.gz: 79b6c3859bbd2d26dffc9f97a2a93c29df41d6588b41a8e19a25fcfb76de7849c323f73a5f1ef345662c79de5ab999367070358c5c2ecc92b93d0a8763b6c79b
7
- data.tar.gz: cfaa5431f940684f06da86d316a9197591c0a72a04289a2681a54b87e0316de63d4ad98a1b8e4ffd2f29280bf3ed2de7fefd658c4ac481ef132a01c3cb8a8763
6
+ metadata.gz: 6869a27406d577b763c99f7e927ec56f2cdfdedcbd0348be729e90d46fb7545cb5077fffddf6beec15eae9e346bd0ec7dc4ce01c237ad5703e07ffe44df88514
7
+ data.tar.gz: 7819f37c2a3d7b0132827fb88c915ba338bb3fa3c16a12638b9b108cd02a74de2c8744ef96d04c14996926ca8663ec20fb0eaeca6d2d61967c90a37dfbeacd74
data/dbhijacker.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{dbhijacker}
5
5
  s.homepage = "https://github.com/crystalcommerce/hijacker"
6
- s.version = "0.10.1"
6
+ s.version = "0.10.2"
7
7
 
8
8
  s.license = "MIT"
9
9
 
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
45
45
  lib/hijacker/database.rb
46
46
  lib/hijacker/host.rb
47
47
  lib/hijacker/middleware.rb
48
+ lib/hijacker/request_parser.rb
48
49
  spec/hijacker/alias_spec.rb
49
50
  spec/hijacker/database_spec.rb
50
51
  spec/hijacker/host_spec.rb
@@ -0,0 +1,48 @@
1
+ require 'rack/request'
2
+
3
+ module Hijacker
4
+ class RequestParser
5
+ attr_reader :host
6
+
7
+ def self.from_env(env)
8
+ request = Rack::Request.new(env)
9
+ from_request(request)
10
+ end
11
+
12
+ def self.from_request(request)
13
+ new(request.host)
14
+ end
15
+
16
+ def initialize(host)
17
+ @host = host
18
+ end
19
+
20
+ def determine_databases
21
+ raise Hijacker::UnparseableURL, "cannot parse '#{host}'" if client.nil?
22
+
23
+ Hijacker::Database.find_master_and_sister_for(client)
24
+ end
25
+
26
+ private
27
+
28
+ def client
29
+ @client ||= do_hijacking? ? client_from_domain_pattern : base_client
30
+ end
31
+
32
+ def client_from_domain_pattern
33
+ Hijacker.config.
34
+ fetch(:domain_patterns).
35
+ map {|pattern| host.scan(pattern).flatten.first}.
36
+ compact.
37
+ first
38
+ end
39
+
40
+ def base_client
41
+ ActiveRecord::Base.configurations.fetch(Rails.env).fetch('database')
42
+ end
43
+
44
+ def do_hijacking?
45
+ Hijacker.do_hijacking?
46
+ end
47
+ end
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbhijacker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Xavier
@@ -194,6 +194,7 @@ files:
194
194
  - lib/hijacker/database.rb
195
195
  - lib/hijacker/host.rb
196
196
  - lib/hijacker/middleware.rb
197
+ - lib/hijacker/request_parser.rb
197
198
  - spec/hijacker/alias_spec.rb
198
199
  - spec/hijacker/database_spec.rb
199
200
  - spec/hijacker/host_spec.rb