Class: Kumonos::Routes::Route
- Inherits:
-
Struct
- Object
- Struct
- Kumonos::Routes::Route
- Defined in:
- lib/kumonos/routes.rb
Constant Summary collapse
- ALLOWED_METHODS =
%w[GET HEAD POST PUT DELETE].freeze
Instance Attribute Summary collapse
-
#cluster ⇒ Object
Returns the value of attribute cluster.
-
#host_header ⇒ Object
Returns the value of attribute host_header.
-
#method ⇒ Object
Returns the value of attribute method.
-
#path ⇒ Object
Returns the value of attribute path.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#retry_policy ⇒ Object
Returns the value of attribute retry_policy.
-
#timeout_ms ⇒ Object
Returns the value of attribute timeout_ms.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#cluster ⇒ Object
Returns the value of attribute cluster
40 41 42 |
# File 'lib/kumonos/routes.rb', line 40 def cluster @cluster end |
#host_header ⇒ Object
Returns the value of attribute host_header
40 41 42 |
# File 'lib/kumonos/routes.rb', line 40 def host_header @host_header end |
#method ⇒ Object
Returns the value of attribute method
40 41 42 |
# File 'lib/kumonos/routes.rb', line 40 def method @method end |
#path ⇒ Object
Returns the value of attribute path
40 41 42 |
# File 'lib/kumonos/routes.rb', line 40 def path @path end |
#prefix ⇒ Object
Returns the value of attribute prefix
40 41 42 |
# File 'lib/kumonos/routes.rb', line 40 def prefix @prefix end |
#retry_policy ⇒ Object
Returns the value of attribute retry_policy
40 41 42 |
# File 'lib/kumonos/routes.rb', line 40 def retry_policy @retry_policy end |
#timeout_ms ⇒ Object
Returns the value of attribute timeout_ms
40 41 42 |
# File 'lib/kumonos/routes.rb', line 40 def timeout_ms @timeout_ms end |
Class Method Details
.build(h, cluster, host_header) ⇒ Object
42 43 44 45 |
# File 'lib/kumonos/routes.rb', line 42 def build(h, cluster, host_header) new(h['prefix'], h['path'], h['method'], cluster, h.fetch('timeout_ms'), RetryPolicy.build(h.fetch('retry_policy')), host_header) end |
Instance Method Details
#to_h ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/kumonos/routes.rb', line 48 def to_h h = super h.delete(:retry_policy) h.delete(:host_header) h.delete(:method) if prefix h.delete(:path) h[:prefix] = prefix elsif path h.delete(:prefix) h[:path] = path else raise '`path` or `prefix` is required' end if host_header h[:host_rewrite] = host_header else h[:auto_host_rewrite] = true end h end |
#to_h_with_retry ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/kumonos/routes.rb', line 73 def to_h_with_retry h = to_h h[:retry_policy] = retry_policy.to_h if method m = method.upcase unless ALLOWED_METHODS.include?(m) raise "method must be one of #{ALLOWED_METHODS.join(',')}: given `#{m}`" end h[:headers] = [{ name: ':method', value: m, regex: false }] else h[:headers] = [{ name: ':method', value: '(GET|HEAD)', regex: true }] end h end |