Sha256: ffbbb66f20f04a2a8e3ac38d137dc9e87bbcfa1355b603977c6102191fb2ce01

Contents?: true

Size: 1.25 KB

Versions: 38

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

require_relative "route"

class ReeRoutes::RouteBuilder
  Redirect = Struct.new(:path, :code)

  def initialize
    @route = ReeRoutes::Route.new
    @route.respond_to = :json
  end

  contract Symbol => Symbol
  def warden_scope(scope)
    @route.warden_scope = scope
  end

  contract Symbol => Symbol
  def respond_to(v)
    @route.respond_to = v
  end

  contract None => ReeRoutes::Route
  def get_route
    @route
  end

  contract Block => nil
  def before(&proc)
    @route.before = proc
    nil
  end

  contract String => String
  def summary(str)
    @route.summary = str
  end

  contract Symbol, Symbol => nil
  def serializer(name, from:)
    object = Ree.container.packages_facade.get_object(from, name)
    @route.serializer = object
    nil
  end

  contract SplatOf[String] => nil
  def sections(*names)
    @route.sections = names
    nil
  end

  contract Symbol, Symbol => nil
  def action(name, from:)
    object = Ree.container.packages_facade.get_object(from, name)
    @route.action = object
    nil
  end

  contract String, Kwargs[code: Integer] => nil
  def redirect(path, code: 301)
    raise ArgumentError if ![301, 302, 303, 307, 308].include?(code)
    @route.redirect = Redirect.new(path, code)
    nil
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
ree_lib-1.0.77 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.76 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.75 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.74 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.73 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.72 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.71 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.70 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.69 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.68 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.67 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.66 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.65 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.64 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.63 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.62 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.61 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.60 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.59 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.58 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb