Class: Pakyow::Routing::Route
- Inherits:
-
Object
- Object
- Pakyow::Routing::Route
- Defined in:
- lib/pakyow/routing/route.rb
Overview
A Controller endpoint.
Defined Under Namespace
Classes: EndpointBuilder
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
- #pipeline ⇒ Object private
Instance Method Summary collapse
- #build_path(path_to_self, **params) ⇒ Object
- #call(context) ⇒ Object
-
#initialize(path_or_matcher, name:, method:, &block) ⇒ Route
constructor
A new instance of Route.
- #match(path_to_match) ⇒ Object
Constructor Details
#initialize(path_or_matcher, name:, method:, &block) ⇒ Route
Returns a new instance of Route.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pakyow/routing/route.rb', line 18 def initialize(path_or_matcher, name:, method:, &block) @name, @method, @block = name, method, block if path_or_matcher.is_a?(String) @path = path_or_matcher.to_s @matcher = create_matcher_from_path(@path) else @path = "" @matcher = path_or_matcher end end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
13 14 15 |
# File 'lib/pakyow/routing/route.rb', line 13 def block @block end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
13 14 15 |
# File 'lib/pakyow/routing/route.rb', line 13 def method @method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/pakyow/routing/route.rb', line 13 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/pakyow/routing/route.rb', line 13 def path @path end |
#pipeline ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/pakyow/routing/route.rb', line 16 def pipeline @pipeline end |
Instance Method Details
#build_path(path_to_self, **params) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pakyow/routing/route.rb', line 38 def build_path(path_to_self, **params) working_path = String.normalize_path(File.join(path_to_self.to_s, @path)) params.each do |key, value| working_path.sub!(":#{key}", value.to_s) end working_path.sub!("/#", "#") working_path end |
#call(context) ⇒ Object
34 35 36 |
# File 'lib/pakyow/routing/route.rb', line 34 def call(context) context.instance_exec(&@block) if @block end |
#match(path_to_match) ⇒ Object
30 31 32 |
# File 'lib/pakyow/routing/route.rb', line 30 def match(path_to_match) @matcher.match(path_to_match) end |