lib/rack/queries/app.rb in rack-queries-0.1.3 vs lib/rack/queries/app.rb in rack-queries-0.2.0

- old
+ new

@@ -9,22 +9,22 @@ # then we can do something smart about it, but for now it's fine. # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength def call(env) return not_found unless env[REQUEST_METHOD] - case env[PATH_INFO] - when '/queries' - json(queries: Cache.queries) - when %r{\A/queries/([a-z0-9_\-:]+)\z}i + case Utils.unescape(env[PATH_INFO]) + when %r{\A/queries/(.+)/opts/(.+)\z}i + values = Cache.opts_for($1, $2) + values ? json(values: values) : not_found + when %r{\A/queries/(.+)\z}i query = Cache.query_for($1) return not_found unless query params = Request.new(env).params json(results: query.new.run(params)) - when %r{\A/queries/([a-z0-9_\-:]+)/opts/([a-z0-9_]+)\z}i - values = Cache.opts_for($1, $2) - values ? json(values: values) : not_found + when '/queries' + json(queries: Cache.queries) else not_found end end # rubocop:enable AbcSize, CyclomaticComplexity, MethodLength @@ -90,21 +90,22 @@ end private def app - @app ||= - begin - configurations = middlewares + @app ||= build_app + end - Builder.new do - configurations.each do |middleware, block| - use(*middleware, &block) - end - use Static - run Controller.new - end + def build_app + configurations = middlewares + + Builder.new do + configurations.each do |middleware, block| + use(*middleware, &block) end + use Static + run Controller.new + end end end end end end