Class: Hanami::Routes::RoutesProc Private

Inherits:
Proc
  • Object
show all
Defined in:
lib/hanami/routes.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Wrapper class for the (otherwise opaque) proc returned from routes, adding an ‘#empty?` method that returns true if no routes were defined.

This is useful when needing to determine behaviour based on the presence of user-defined routes, such as determining whether to show the Hanami welcome page in Slice#load_router.

Since:

  • 2.1.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proc, empty: false) ⇒ RoutesProc

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RoutesProc.

Since:

  • 2.1.0



80
81
82
83
# File 'lib/hanami/routes.rb', line 80

def initialize(proc, empty: false)
  @empty = empty
  super(proc)
end

Class Method Details

.emptyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



74
75
76
# File 'lib/hanami/routes.rb', line 74

def self.empty
  new(proc {}, empty: true)
end

Instance Method Details

#empty?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 2.1.0



87
88
89
# File 'lib/hanami/routes.rb', line 87

def empty?
  !!@empty
end