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.57 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.56 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.55 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.54 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.53 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.52 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.51 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.50 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.49 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.48 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.47 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.46 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.45 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.44 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.43 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.42 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.41 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.40 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb