Sha256: 990ac7b7dfbb0db643f5c4a3799a611fe58a11208a0a8c79206fa6acb9916055

Contents?: true

Size: 1.33 KB

Versions: 47

Compression:

Stored size: 1.33 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 Block => nil
  def override(&proc)
    @route.override = 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

47 entries across 47 versions & 1 rubygems

Version Path
ree_lib-1.0.124 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.123 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.122 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.121 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.120 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.119 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.118 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.117 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.116 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.115 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.114 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.113 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.112 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.111 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.110 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.109 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.108 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.107 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.106 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb
ree_lib-1.0.105 lib/ree_lib/packages/ree_routes/package/ree_routes/route_builder.rb