lib/hanami/routing/endpoint_resolver.rb in hanami-router-1.0.0.beta2 vs lib/hanami/routing/endpoint_resolver.rb in hanami-router-1.0.0.beta3

- old
+ new

@@ -56,10 +56,11 @@ # action name. (defaults to `ACTION_SEPARATOR`) # # @return [Hanami::Routing::EndpointResolver] self # # @since 0.1.0 + # @api private # # @example Specify custom endpoint class # require 'hanami/router' # # resolver = Hanami::Routing::EndpointResolver.new(endpoint: CustomEndpoint) @@ -115,10 +116,11 @@ # # @return [Endpoint] this may vary according to the :endpoint option # passed to #initialize # # @since 0.1.0 + # @api private # # @see #initialize # @see #find # # @example Resolve to a Proc @@ -171,23 +173,26 @@ # @param options [Hash] the path description # @option options [String,Proc,Class,Object#call] :to the endpoint # @option options [String] :namespace an optional namespace # # @since 0.1.0 + # @api private # # @return [Object] def find(options) options[:to] end protected + # @api private def default @endpoint_class.new( ->(env) { DEFAULT_RESPONSE } ) end + # @api private def constantize(string) klass = Utils::Class.load!(string, @namespace) if klass.respond_to?(:call) Endpoint.new(klass) else @@ -195,30 +200,34 @@ end rescue NameError LazyEndpoint.new(string, @namespace) end + # @api private def classify(string) Utils::String.new(string).underscore.classify end private + # @api private def resolve_callable(callable) if callable.respond_to?(:call) @endpoint_class.new(callable) elsif callable.is_a?(Class) && callable.instance_methods.include?(:call) @endpoint_class.new(callable.new) end end + # @api private def resolve_matchable(matchable) if matchable.respond_to?(:match) constantize( resolve_action(matchable) || classify(matchable) ) end end + # @api private def resolve_action(string) if string.match(action_separator) controller, action = string.split(action_separator).map {|token| classify(token) } @pattern % {controller: controller, action: action} end