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
42 43 44 |
# File 'lib/kumonos/routes.rb', line 42 def cluster @cluster end |
#host_header ⇒ Object
Returns the value of attribute host_header
42 43 44 |
# File 'lib/kumonos/routes.rb', line 42 def host_header @host_header end |
#method ⇒ Object
Returns the value of attribute method
42 43 44 |
# File 'lib/kumonos/routes.rb', line 42 def method @method end |
#path ⇒ Object
Returns the value of attribute path
42 43 44 |
# File 'lib/kumonos/routes.rb', line 42 def path @path end |
#prefix ⇒ Object
Returns the value of attribute prefix
42 43 44 |
# File 'lib/kumonos/routes.rb', line 42 def prefix @prefix end |
#retry_policy ⇒ Object
Returns the value of attribute retry_policy
42 43 44 |
# File 'lib/kumonos/routes.rb', line 42 def retry_policy @retry_policy end |
#timeout_ms ⇒ Object
Returns the value of attribute timeout_ms
42 43 44 |
# File 'lib/kumonos/routes.rb', line 42 def timeout_ms @timeout_ms end |
Class Method Details
.build(h, cluster, host_header) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/kumonos/routes.rb', line 44 def build(h, cluster, host_header) retry_policy = if h.key?('retry_policy') RetryPolicy.build(h.fetch('retry_policy')) else nil end new(h['prefix'], h['path'], h['method'], cluster, h.fetch('timeout_ms'), retry_policy, host_header) end |
Instance Method Details
#to_h ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/kumonos/routes.rb', line 57 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
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/kumonos/routes.rb', line 82 def to_h_with_retry h = to_h h[:retry_policy] = retry_policy.to_h if retry_policy if method m = method.upcase raise "method must be one of #{ALLOWED_METHODS.join(',')}: given `#{m}`" unless ALLOWED_METHODS.include?(m) h[:headers] = [{ name: ':method', value: m, regex: false }] else h[:headers] = [{ name: ':method', value: '(GET|HEAD)', regex: true }] end h end |