sitehub 0.4.3 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +31 -0
  3. data/.gitignore +2 -1
  4. data/.reek +41 -0
  5. data/.simplecov +7 -0
  6. data/Gemfile.lock +61 -33
  7. data/README.md +4 -0
  8. data/Rakefile +1 -1
  9. data/circle.yml +1 -1
  10. data/lib/sitehub/builder.rb +19 -36
  11. data/lib/sitehub/collection/split_route_collection.rb +18 -13
  12. data/lib/sitehub/collection/split_route_collection/split.rb +6 -4
  13. data/lib/sitehub/constants.rb +2 -1
  14. data/lib/sitehub/constants/http_header_keys.rb +2 -0
  15. data/lib/sitehub/constants/rack_http_header_keys.rb +2 -0
  16. data/lib/sitehub/cookie.rb +4 -13
  17. data/lib/sitehub/cookie/attribute.rb +10 -9
  18. data/lib/sitehub/cookie/flag.rb +5 -8
  19. data/lib/sitehub/cookie_rewriting.rb +12 -5
  20. data/lib/sitehub/downstream_client.rb +37 -0
  21. data/lib/sitehub/equality.rb +28 -0
  22. data/lib/sitehub/forward_proxy.rb +19 -62
  23. data/lib/sitehub/forward_proxy_builder.rb +70 -49
  24. data/lib/sitehub/getter_setter_methods.rb +21 -0
  25. data/lib/sitehub/http_headers.rb +45 -48
  26. data/lib/sitehub/location_rewriter.rb +29 -0
  27. data/lib/sitehub/location_rewriters.rb +23 -0
  28. data/lib/sitehub/memoize.rb +25 -0
  29. data/lib/sitehub/middleware.rb +16 -6
  30. data/lib/sitehub/middleware/error_handling.rb +20 -0
  31. data/lib/sitehub/middleware/forward_proxies.rb +54 -0
  32. data/lib/sitehub/{logging.rb → middleware/logging.rb} +0 -0
  33. data/lib/sitehub/middleware/logging/access_logger.rb +36 -0
  34. data/lib/sitehub/middleware/logging/error_logger.rb +38 -0
  35. data/lib/sitehub/middleware/logging/log_entry.rb +16 -0
  36. data/lib/sitehub/middleware/logging/log_stash.rb +12 -0
  37. data/lib/sitehub/middleware/logging/log_wrapper.rb +24 -0
  38. data/lib/sitehub/middleware/logging/request_log.rb +74 -0
  39. data/lib/sitehub/middleware/reverse_proxy.rb +37 -0
  40. data/lib/sitehub/middleware/transaction_id.rb +18 -0
  41. data/lib/sitehub/nil_location_rewriter.rb +7 -0
  42. data/lib/sitehub/nil_proxy.rb +11 -0
  43. data/lib/sitehub/request.rb +101 -0
  44. data/lib/sitehub/request_mapping.rb +16 -18
  45. data/lib/sitehub/resolver.rb +1 -1
  46. data/lib/sitehub/response.rb +10 -0
  47. data/lib/sitehub/string_utils.rb +13 -0
  48. data/lib/sitehub/version.rb +1 -1
  49. data/sitehub.gemspec +4 -1
  50. data/spec/equality_spec.rb +32 -0
  51. data/spec/sitehub/builder_spec.rb +29 -22
  52. data/spec/sitehub/collection/route_collection_spec.rb +15 -14
  53. data/spec/sitehub/collection/split_route_collection/split_spec.rb +26 -0
  54. data/spec/sitehub/collection/split_route_collection_spec.rb +15 -3
  55. data/spec/sitehub/cookie/flag_spec.rb +1 -1
  56. data/spec/sitehub/cookie_rewriting_spec.rb +6 -10
  57. data/spec/sitehub/downstream_client_spec.rb +72 -0
  58. data/spec/sitehub/equality_spec.rb +32 -0
  59. data/spec/sitehub/forward_proxy_builder_spec.rb +92 -55
  60. data/spec/sitehub/forward_proxy_spec.rb +29 -97
  61. data/spec/sitehub/http_headers_spec.rb +32 -52
  62. data/spec/sitehub/integration_spec.rb +1 -1
  63. data/spec/sitehub/location_rewriter_spec.rb +46 -0
  64. data/spec/sitehub/{path_directives_spec.rb → location_rewriters_spec.rb} +8 -8
  65. data/spec/sitehub/memoize_spec.rb +56 -0
  66. data/spec/sitehub/middleware/error_handling_spec.rb +34 -0
  67. data/spec/sitehub/middleware/forward_proxies_spec.rb +105 -0
  68. data/spec/sitehub/middleware/logging/access_logger_spec.rb +51 -0
  69. data/spec/sitehub/middleware/logging/error_logger_spec.rb +84 -0
  70. data/spec/sitehub/middleware/logging/log_entry_spec.rb +33 -0
  71. data/spec/sitehub/middleware/logging/log_stash_spec.rb +21 -0
  72. data/spec/sitehub/middleware/logging/log_wrapper_spec.rb +31 -0
  73. data/spec/sitehub/middleware/logging/request_log_spec.rb +108 -0
  74. data/spec/sitehub/middleware/reverse_proxy_spec.rb +113 -0
  75. data/spec/sitehub/middleware/transaction_id_spec.rb +30 -0
  76. data/spec/sitehub/middleware_spec.rb +23 -13
  77. data/spec/sitehub/nil_location_rewriter_spec.rb +10 -0
  78. data/spec/sitehub/nil_proxy_spec.rb +14 -0
  79. data/spec/sitehub/request_mapping_spec.rb +21 -23
  80. data/spec/sitehub/request_spec.rb +228 -0
  81. data/spec/sitehub/resolver_spec.rb +2 -5
  82. data/spec/sitehub/response_spec.rb +30 -0
  83. data/spec/spec_helper.rb +12 -6
  84. data/spec/support/async/middleware.rb +1 -0
  85. data/spec/support/patch/rack/response.rb +7 -5
  86. data/spec/support/shared_contexts.rb +3 -0
  87. data/spec/support/shared_contexts/http_proxy_rules_context.rb +36 -0
  88. data/spec/support/shared_contexts/middleware_context.rb +6 -6
  89. data/spec/support/shared_contexts/module_spec_context.rb +7 -0
  90. data/spec/support/shared_contexts/rack_request_context.rb +18 -0
  91. data/spec/support/shared_contexts/rack_test_context.rb +0 -1
  92. data/spec/support/shared_examples.rb +3 -0
  93. data/spec/support/shared_examples/memoized_helpers.rb +7 -0
  94. data/spec/support/shared_examples/prohibited_http_header_filter.rb +16 -0
  95. data/spec/support/silent_warnings.rb +1 -1
  96. data/tasks/code_quality.rake +6 -0
  97. metadata +99 -29
  98. data/lib/sitehub/forward_proxies.rb +0 -49
  99. data/lib/sitehub/logging/access_logger.rb +0 -78
  100. data/lib/sitehub/logging/error_logger.rb +0 -36
  101. data/lib/sitehub/logging/log_entry.rb +0 -15
  102. data/lib/sitehub/logging/log_stash.rb +0 -10
  103. data/lib/sitehub/logging/log_wrapper.rb +0 -23
  104. data/lib/sitehub/path_directive.rb +0 -32
  105. data/lib/sitehub/path_directives.rb +0 -22
  106. data/lib/sitehub/reverse_proxy.rb +0 -57
  107. data/lib/sitehub/string_sanitiser.rb +0 -7
  108. data/lib/sitehub/transaction_id.rb +0 -16
  109. data/spec/sitehub/error_handling_spec.rb +0 -20
  110. data/spec/sitehub/forward_proxies_spec.rb +0 -103
  111. data/spec/sitehub/logging/access_logger_spec.rb +0 -128
  112. data/spec/sitehub/logging/error_logger_spec.rb +0 -78
  113. data/spec/sitehub/logging/log_entry_spec.rb +0 -31
  114. data/spec/sitehub/logging/log_stash_spec.rb +0 -19
  115. data/spec/sitehub/logging/log_wrapper_spec.rb +0 -29
  116. data/spec/sitehub/path_directive_spec.rb +0 -47
  117. data/spec/sitehub/reverse_proxy_spec.rb +0 -111
  118. data/spec/sitehub/transaction_id_spec.rb +0 -28
  119. data/spec/support/async/response_handler.rb +0 -16
  120. data/spec/support/shared_contexts/async_context.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a6e0a6953fd3b5d361c2e65e2b0b015a22a36b8
4
- data.tar.gz: 76336ecd1253d8cf8e593e6bc67a1912b9fde469
3
+ metadata.gz: fb7cd90f333ade307a9dd901fb5922709263f78a
4
+ data.tar.gz: f843541b0caa8a76238aa299158c84a12616bfd8
5
5
  SHA512:
6
- metadata.gz: ecd3cd69815ab6d8755e222e0fbd17ee4b92f09472f67272da3b5f407be8b4a9954009d6b5563e7320ffda0db6b7b5aa8dce8e71e4d39e72f108fa5c522687d0
7
- data.tar.gz: e17c0f2deb78badac60445ac189103bb193687ed073202edcf1e12282aaff4e22e77c7bc74596133f3b8d069796bcefda52a01b0d1b19368c8ce966ec9095b07
6
+ metadata.gz: 0f0ea72647bbab0b92f166ade2d2f48eb6621c335bcc0c8ac711017dbb24540e40ced8327e7e67204f5a40439e318b840a27d76bdc30cb5eb73eb1b3a381be33
7
+ data.tar.gz: cafdd5cae62c9a8036adc64a7ab567ede50ef287f25983039374dd7bca7b9db3da7cffbd2d4d3fb8d9e8e0575d7962d462b2534f054d583823da361136777317
data/.codeclimate.yml ADDED
@@ -0,0 +1,31 @@
1
+ ---
2
+ engines:
3
+ bundler-audit:
4
+ enabled: true
5
+ duplication:
6
+ enabled: true
7
+ config:
8
+ languages:
9
+ - ruby
10
+ - javascript
11
+ - python
12
+ - php
13
+ fixme:
14
+ enabled: true
15
+ rubocop:
16
+ enabled: true
17
+ reek:
18
+ enabled: true
19
+ ratings:
20
+ paths:
21
+ - Gemfile.lock
22
+ - "**.inc"
23
+ - "**.js"
24
+ - "**.jsx"
25
+ - "**.module"
26
+ - "**.php"
27
+ - "**.py"
28
+ - "**.rb"
29
+ - "**.rake"
30
+ exclude_paths:
31
+ - spec/
data/.gitignore CHANGED
@@ -3,4 +3,5 @@
3
3
  test.rb
4
4
  coverage
5
5
  .ruby-gemset
6
- .ruby-version
6
+ .ruby-version
7
+ pkg
data/.reek ADDED
@@ -0,0 +1,41 @@
1
+ ---
2
+ IrresponsibleModule:
3
+ enabled: false
4
+
5
+ UtilityFunction:
6
+ exclude:
7
+ - NilProxy
8
+ - collect_middleware
9
+ - env_for
10
+ - "Rack::Response#cookie_data"
11
+ - 'SiteHub::CookieRewriting'
12
+ - format_as_rack_header_name
13
+
14
+ TooManyStatements:
15
+ enabled: true
16
+ exclude:
17
+ - "Builder#add_default_middleware"
18
+ - "ForwardProxy#initialize"
19
+ - "SiteHub::ForwardProxyBuilder#initialize"
20
+
21
+ FeatureEnvy:
22
+ exclude:
23
+ - "SiteHub::DownstreamClient#call"
24
+ - "SiteHub::LocationRewriters"
25
+ - 'Rack::Response#cookies'
26
+ - 'format_http_to_rack_headers'
27
+
28
+ TooManyMethods:
29
+ exclude:
30
+ - "SiteHub::Request"
31
+ LongParameterList:
32
+ exclude:
33
+ - env_for
34
+ - "SiteHub::ForwardProxy#initialize"
35
+
36
+ TooManyInstanceVariables:
37
+ exclude:
38
+ - ForwardProxyBuilder
39
+ - "SiteHub::Request"
40
+ - "SiteHub::ForwardProxy"
41
+
data/.simplecov ADDED
@@ -0,0 +1,7 @@
1
+ require "codeclimate-test-reporter"
2
+
3
+ SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter,CodeClimate::TestReporter::Formatter]
4
+
5
+ SimpleCov.start do
6
+ add_filter '/spec/'
7
+ end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sitehub (0.4.3)
4
+ sitehub (0.4.6)
5
5
  em-http-request
6
6
  em-synchrony
7
7
  faraday
@@ -14,44 +14,58 @@ PATH
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- addressable (2.3.8)
18
- ast (2.2.0)
17
+ addressable (2.4.0)
18
+ ast (2.3.0)
19
+ axiom-types (0.1.1)
20
+ descendants_tracker (~> 0.0.4)
21
+ ice_nine (~> 0.11.0)
22
+ thread_safe (~> 0.3, >= 0.3.1)
19
23
  builder (3.2.2)
20
- cookiejar (0.3.0)
24
+ codeclimate-engine-rb (0.3.1)
25
+ virtus (~> 1.0)
26
+ codeclimate-test-reporter (0.5.2)
27
+ simplecov (>= 0.7.1, < 1.0.0)
28
+ coercible (1.0.0)
29
+ descendants_tracker (~> 0.0.1)
30
+ cookiejar (0.3.3)
21
31
  crack (0.4.3)
22
32
  safe_yaml (~> 1.0.0)
23
33
  daemons (1.2.3)
34
+ descendants_tracker (0.0.4)
35
+ thread_safe (~> 0.3, >= 0.3.1)
24
36
  diff-lcs (1.2.5)
25
37
  docile (1.1.5)
26
- em-http-request (1.1.3)
38
+ em-http-request (1.1.4)
27
39
  addressable (>= 2.3.4)
28
- cookiejar (<= 0.3.0)
40
+ cookiejar (!= 0.3.1)
29
41
  em-socksify (>= 0.3)
30
42
  eventmachine (>= 1.0.3)
31
43
  http_parser.rb (>= 0.6.0)
32
44
  em-socksify (0.3.1)
33
45
  eventmachine (>= 1.0.0.beta.4)
34
- em-synchrony (1.0.4)
46
+ em-synchrony (1.0.5)
35
47
  eventmachine (>= 1.0.0.beta.1)
36
- eventmachine (1.0.8)
48
+ equalizer (0.0.11)
49
+ eventmachine (1.2.0.1)
37
50
  faraday (0.9.2)
38
51
  multipart-post (>= 1.2, < 3)
39
- geminabox (0.12.4)
52
+ geminabox (0.13.1)
40
53
  builder
41
54
  faraday
42
55
  httpclient (>= 2.2.7)
43
56
  nesty
44
57
  sinatra (>= 1.2.7)
45
- hashdiff (0.2.3)
58
+ hashdiff (0.3.0)
46
59
  http_parser.rb (0.6.0)
47
- httpclient (2.7.1)
60
+ httpclient (2.8.0)
61
+ ice_nine (0.11.2)
48
62
  json (1.8.3)
49
63
  macaddr (1.7.1)
50
64
  systemu (~> 2.6.2)
51
65
  memory_profiler (0.9.6)
52
66
  multipart-post (2.0.0)
53
67
  nesty (1.0.2)
54
- parser (2.3.1.0)
68
+ parser (2.3.1.2)
55
69
  ast (~> 2.2)
56
70
  powerpack (0.1.1)
57
71
  rack (1.6.4)
@@ -62,20 +76,24 @@ GEM
62
76
  rack-test (0.6.3)
63
77
  rack (>= 1.0)
64
78
  rainbow (2.1.0)
65
- rake (10.4.2)
66
- rspec (3.2.0)
67
- rspec-core (~> 3.2.0)
68
- rspec-expectations (~> 3.2.0)
69
- rspec-mocks (~> 3.2.0)
70
- rspec-core (3.2.3)
71
- rspec-support (~> 3.2.0)
72
- rspec-expectations (3.2.1)
79
+ rake (11.2.2)
80
+ reek (4.0.5)
81
+ codeclimate-engine-rb (~> 0.3.1)
82
+ parser (~> 2.3.1, >= 2.3.1.2)
83
+ rainbow (~> 2.0)
84
+ rspec (3.4.0)
85
+ rspec-core (~> 3.4.0)
86
+ rspec-expectations (~> 3.4.0)
87
+ rspec-mocks (~> 3.4.0)
88
+ rspec-core (3.4.4)
89
+ rspec-support (~> 3.4.0)
90
+ rspec-expectations (3.4.0)
73
91
  diff-lcs (>= 1.2.0, < 2.0)
74
- rspec-support (~> 3.2.0)
75
- rspec-mocks (3.2.1)
92
+ rspec-support (~> 3.4.0)
93
+ rspec-mocks (3.4.1)
76
94
  diff-lcs (>= 1.2.0, < 2.0)
77
- rspec-support (~> 3.2.0)
78
- rspec-support (3.2.2)
95
+ rspec-support (~> 3.4.0)
96
+ rspec-support (3.4.1)
79
97
  rubocop (0.40.0)
80
98
  parser (>= 2.3.1.0, < 3.0)
81
99
  powerpack (~> 0.1)
@@ -85,26 +103,33 @@ GEM
85
103
  ruby-prof (0.15.9)
86
104
  ruby-progressbar (1.8.1)
87
105
  safe_yaml (1.0.4)
88
- simplecov (0.11.1)
106
+ simplecov (0.11.2)
89
107
  docile (~> 1.1.0)
90
108
  json (~> 1.8)
91
109
  simplecov-html (~> 0.10.0)
92
110
  simplecov-html (0.10.0)
93
- sinatra (1.4.6)
94
- rack (~> 1.4)
111
+ sinatra (1.4.7)
112
+ rack (~> 1.5)
95
113
  rack-protection (~> 1.4)
96
114
  tilt (>= 1.3, < 3)
97
115
  systemu (2.6.5)
98
- thin (1.6.4)
116
+ thin (1.7.0)
99
117
  daemons (~> 1.0, >= 1.0.9)
100
118
  eventmachine (~> 1.0, >= 1.0.4)
101
- rack (~> 1.0)
102
- tilt (2.0.2)
119
+ rack (>= 1, < 3)
120
+ thread_safe (0.3.5)
121
+ tilt (2.0.5)
122
+ timecop (0.8.1)
103
123
  unicode-display_width (1.0.5)
104
124
  uuid (2.3.8)
105
125
  macaddr (~> 1.0)
106
- webmock (1.22.5)
107
- addressable (< 2.4.0)
126
+ virtus (1.0.5)
127
+ axiom-types (~> 0.1)
128
+ coercible (~> 1.0)
129
+ descendants_tracker (~> 0.0, >= 0.0.3)
130
+ equalizer (~> 0.0, >= 0.0.9)
131
+ webmock (2.1.0)
132
+ addressable (>= 2.3.6)
108
133
  crack (>= 0.3.2)
109
134
  hashdiff
110
135
 
@@ -113,15 +138,18 @@ PLATFORMS
113
138
 
114
139
  DEPENDENCIES
115
140
  bundler (~> 1.5)
141
+ codeclimate-test-reporter
116
142
  geminabox
117
143
  memory_profiler
118
144
  rack-test
119
145
  rake
120
- rspec (~> 3.2.0)
146
+ reek
147
+ rspec (~> 3.4.0)
121
148
  rubocop
122
149
  ruby-prof
123
150
  simplecov
124
151
  sitehub!
152
+ timecop
125
153
  webmock
126
154
 
127
155
  BUNDLED WITH
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # SiteHub
2
+ [![CircleCI](https://circleci.com/gh/lvl-up/sitehub.svg?style=shield&circle-token=da10bde2f25581f01839fb7078fc2a098a98ca13)](https://circleci.com/gh/lvl-up/sitehub)
3
+ [![Code Climate](https://codeclimate.com/github/lvl-up/sitehub/badges/gpa.svg)](https://codeclimate.com/github/lvl-up/sitehub)
4
+ [![Test Coverage](https://codeclimate.com/github/lvl-up/sitehub/badges/coverage.svg)](https://codeclimate.com/github/lvl-up/sitehub/coverage)
5
+
2
6
  SiteHub is a HTTP proxy written in Ruby with support for A|B testing baked in. SiteHub sits in front of your web application(s) routing all HTTP traffics between it and your users.
3
7
 
4
8
  Wouldn't it be cool to write something like:
data/Rakefile CHANGED
@@ -2,4 +2,4 @@ Dir["#{__dir__}/tasks/*.rake"].each do |tasks|
2
2
  import tasks
3
3
  end
4
4
 
5
- task default: [:clean, :spec, :coverage_check, 'rubocop:auto_correct', 'rubocop']
5
+ task default: [:clean, :spec, :coverage_check, 'rubocop:auto_correct', 'rubocop', 'reek']
data/circle.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  machine:
2
2
  ruby:
3
- version: '2.1'
3
+ version: '2.2'
4
4
  test:
5
5
  override:
6
6
  - bundle exec rake
@@ -1,20 +1,20 @@
1
- require 'sitehub/forward_proxies'
2
- require 'sitehub/transaction_id'
3
- require 'sitehub/middleware'
1
+ require 'sitehub/getter_setter_methods'
4
2
  require 'sitehub/forward_proxy_builder'
5
- require 'sitehub/reverse_proxy'
6
- require 'rack/ssl-enforcer'
7
- require 'sitehub/logging'
8
- require 'rack/fiber_pool'
3
+ require 'sitehub/middleware'
9
4
  require 'logger'
10
5
 
11
6
  class SiteHub
12
7
  class InvalidProxyDefinitionException < Exception
13
8
  end
9
+
14
10
  class Builder
15
11
  attr_reader :sitehub, :forward_proxies, :reverse_proxies
16
12
 
17
13
  include Middleware
14
+ extend GetterSetterMethods
15
+
16
+ getter_setters :access_logger, :error_logger
17
+ getter_setter :sitehub_cookie_name, RECORDED_ROUTES_COOKIE
18
18
 
19
19
  def force_ssl(except: [])
20
20
  @force_ssl = true
@@ -27,23 +27,6 @@ class SiteHub
27
27
  instance_eval(&block) if block
28
28
  end
29
29
 
30
- def access_logger(logger = nil)
31
- return @access_logger unless logger
32
- @access_logger = logger
33
- end
34
-
35
- def error_logger(logger = nil)
36
- return @error_logger unless logger
37
- @error_logger = logger
38
- end
39
-
40
- def sitehub_cookie_name(name = nil)
41
- @sitehub_cookie_name ||= RECORDED_ROUTES_COOKIE
42
-
43
- return @sitehub_cookie_name unless name
44
- @sitehub_cookie_name = name
45
- end
46
-
47
30
  def build
48
31
  forward_proxies.init
49
32
  add_default_middleware
@@ -52,27 +35,27 @@ class SiteHub
52
35
  end
53
36
 
54
37
  def add_default_middleware
55
- use ReverseProxy, reverse_proxies
56
- use TransactionId
57
- use Logging::AccessLogger, access_logger || ::Logger.new(STDOUT)
58
- use Logging::ErrorLogger, error_logger || ::Logger.new(STDERR)
38
+ use Middleware::ReverseProxy, reverse_proxies
39
+ use Middleware::TransactionId
40
+ use Middleware::ErrorHandling
41
+ use Middleware::Logging::AccessLogger, access_logger || ::Logger.new(STDOUT)
42
+ use Middleware::Logging::ErrorLogger, error_logger || ::Logger.new(STDERR)
59
43
  use Rack::FiberPool
60
44
  use Rack::SslEnforcer, except: @ssl_exclusions if @force_ssl
61
45
  end
62
46
 
63
47
  def proxy(opts = {}, &block)
64
- args = { sitehub_cookie_name: sitehub_cookie_name }
65
-
66
48
  if opts.is_a?(Hash)
67
- mapped_path = opts.keys.first
68
- url = opts.values.first
69
- args[:url] = url
70
- args[:mapped_path] = mapped_path
49
+ mapped_path, url = *opts.to_a.flatten
71
50
  else
72
- args[:mapped_path] = opts
51
+ mapped_path = opts
52
+ url = nil
73
53
  end
74
54
 
75
- forward_proxies << ForwardProxyBuilder.new(args, &block)
55
+ forward_proxies << ForwardProxyBuilder.new(sitehub_cookie_name: sitehub_cookie_name,
56
+ url: url,
57
+ mapped_path: mapped_path,
58
+ &block)
76
59
  end
77
60
 
78
61
  def reverse_proxy(hash)
@@ -8,6 +8,9 @@ class SiteHub
8
8
 
9
9
  FIXNUM_ERR_MSG = 'splits must be a Fixnum'.freeze
10
10
  SPLIT_ERR_MSG = 'total split percentages can not be greater than 100%'.freeze
11
+ INVALID_SPILTS_MSG = 'splits do not add up to 100% and no default has been specified'.freeze
12
+ MAX = 100
13
+ MIN = 0
11
14
 
12
15
  def initialize(hash = {})
13
16
  hash.each do |value, percentage|
@@ -17,37 +20,39 @@ class SiteHub
17
20
 
18
21
  def add(id, value, percentage)
19
22
  raise InvalidSplitException, FIXNUM_ERR_MSG unless percentage.is_a?(Fixnum)
20
- lower = values.last ? values.last.upper : 0
21
- upper = lower + percentage
23
+ upper_bound = lower_bound + percentage
22
24
 
23
- raise InvalidSplitException, SPLIT_ERR_MSG if upper > 100
24
- self[id] = Split.new(lower, upper, value)
25
+ raise InvalidSplitException, SPLIT_ERR_MSG if upper_bound > MAX
26
+ self[id] = Split.new(lower_bound, upper_bound, value)
25
27
  end
26
28
 
27
29
  def resolve(*args)
28
- random = rand(100)
30
+ random = rand(MAX)
29
31
  result = values.find { |split| random >= split.lower && random < split.upper }
30
32
  result ? result.value.resolve(*args) : nil
31
33
  end
32
34
 
33
- def transform
34
- values.each do |split|
35
- split.value = yield(split.value)
36
- end
35
+ def transform(&block)
36
+ values.each { |split| split.update_value(&block) }
37
37
  end
38
38
 
39
39
  def [](key)
40
- result = super(key)
41
- result && result.value
40
+ key?(key) ? super(key).value : nil
42
41
  end
43
42
 
44
43
  def valid?
45
44
  last = values.last
46
- return true if last && last.upper == 100
45
+ return true if last && last.upper == MAX
47
46
 
48
- warn('splits do not add up to 100% and no default has been specified')
47
+ warn(INVALID_SPILTS_MSG)
49
48
  false
50
49
  end
50
+
51
+ private
52
+
53
+ def lower_bound
54
+ values.empty? ? MIN : values.last.upper
55
+ end
51
56
  end
52
57
  end
53
58
  end