Class: Itsi::Server::Config::Location
- Inherits:
-
Middleware
- Object
- Middleware
- Itsi::Server::Config::Location
- Defined in:
- lib/itsi/server/config/middleware/location.rb
Instance Attribute Summary collapse
-
#accepts ⇒ Object
Returns the value of attribute accepts.
-
#block ⇒ Object
Returns the value of attribute block.
-
#content_types ⇒ Object
Returns the value of attribute content_types.
-
#extensions ⇒ Object
Returns the value of attribute extensions.
-
#hosts ⇒ Object
Returns the value of attribute hosts.
-
#location ⇒ Object
Returns the value of attribute location.
-
#ports ⇒ Object
Returns the value of attribute ports.
-
#protocols ⇒ Object
Returns the value of attribute protocols.
-
#routes ⇒ Object
Returns the value of attribute routes.
Instance Method Summary collapse
- #build! ⇒ Object
- #http_methods ⇒ Object
-
#initialize(location, *routes, methods: [], protocols: [], schemes: [], hosts: [], ports: [], extensions: [], content_types: [], accepts: [], &block) ⇒ Location
constructor
A new instance of Location.
- #intersect(a, b) ⇒ Object
Methods included from ConfigHelpers
included, load_and_register, #normalize_keys!
Constructor Details
#initialize(location, *routes, methods: [], protocols: [], schemes: [], hosts: [], ports: [], extensions: [], content_types: [], accepts: [], &block) ⇒ Location
Returns a new instance of Location.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/itsi/server/config/middleware/location.rb', line 32 def initialize(location, *routes, methods: [], protocols: [], schemes: [], hosts: [], ports: [], extensions: [], content_types: [], accepts: [], &block ) @location = location params = self.schema.new({ routes: routes, methods: methods, protocols: protocols, schemes: schemes, hosts: hosts, ports: ports, extensions: extensions, content_types: content_types, accepts: accepts, block: block }).to_h @routes = params[:routes].empty? ? ["*"] : params[:routes] @methods = params[:methods].map { |s| s.is_a?(Regexp) ? s : s.to_s } @protocols = (params[:protocols] | params[:schemes]).map { |s| s.is_a?(Regexp) ? s : s.to_s } @hosts = params[:hosts].map { |s| s.is_a?(Regexp) ? s : s.to_s } @ports = params[:ports].map { |s| s.is_a?(Regexp) ? s : s.to_s } @extensions = params[:extensions].map { |s| s.is_a?(Regexp) ? s : s.to_s } @content_types = params[:content_types].map { |s| s.is_a?(Regexp) ? s : s.to_s } @accepts = params[:accepts].map { |s| s.is_a?(Regexp) ? s : s.to_s } @block = block end |
Instance Attribute Details
#accepts ⇒ Object
Returns the value of attribute accepts.
29 30 31 |
# File 'lib/itsi/server/config/middleware/location.rb', line 29 def accepts @accepts end |
#block ⇒ Object
Returns the value of attribute block.
29 30 31 |
# File 'lib/itsi/server/config/middleware/location.rb', line 29 def block @block end |
#content_types ⇒ Object
Returns the value of attribute content_types.
29 30 31 |
# File 'lib/itsi/server/config/middleware/location.rb', line 29 def content_types @content_types end |
#extensions ⇒ Object
Returns the value of attribute extensions.
29 30 31 |
# File 'lib/itsi/server/config/middleware/location.rb', line 29 def extensions @extensions end |
#hosts ⇒ Object
Returns the value of attribute hosts.
29 30 31 |
# File 'lib/itsi/server/config/middleware/location.rb', line 29 def hosts @hosts end |
#location ⇒ Object
Returns the value of attribute location.
29 30 31 |
# File 'lib/itsi/server/config/middleware/location.rb', line 29 def location @location end |
#ports ⇒ Object
Returns the value of attribute ports.
29 30 31 |
# File 'lib/itsi/server/config/middleware/location.rb', line 29 def ports @ports end |
#protocols ⇒ Object
Returns the value of attribute protocols.
29 30 31 |
# File 'lib/itsi/server/config/middleware/location.rb', line 29 def protocols @protocols end |
#routes ⇒ Object
Returns the value of attribute routes.
29 30 31 |
# File 'lib/itsi/server/config/middleware/location.rb', line 29 def routes @routes end |
Instance Method Details
#build! ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/itsi/server/config/middleware/location.rb', line 79 def build! build_child = lambda { child = DSL.new( location, routes: routes, methods: intersect(http_methods, location.http_methods), protocols: intersect(protocols, location.protocols), hosts: intersect(hosts, location.hosts), ports: intersect(ports, location.ports), extensions: intersect(extensions, location.extensions), content_types: intersect(content_types, location.content_types), accepts: intersect(accepts, location.accepts), controller: location.controller, &block ) child.[:nested_locations].each(&:call) location.children << child } location.[:nested_locations] << build_child end |
#http_methods ⇒ Object
69 70 71 |
# File 'lib/itsi/server/config/middleware/location.rb', line 69 def http_methods @methods end |
#intersect(a, b) ⇒ Object
73 74 75 76 77 |
# File 'lib/itsi/server/config/middleware/location.rb', line 73 def intersect(a, b) return b if a.empty? return a if b.empty? a & b end |