Skip to content

Commit 06930da

Browse files
committed
Merge pull request #1205 from marshall-lee/memoize_endpoint_helpers
Memoize endpoint helpers.
2 parents 99749c4 + 3779ff1 commit 06930da

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Metrics/BlockNesting:
2222
# Offense count: 5
2323
# Configuration parameters: CountComments.
2424
Metrics/ClassLength:
25-
Max: 253
25+
Max: 257
2626

2727
# Offense count: 23
2828
Metrics/CyclomaticComplexity:

lib/grape/endpoint.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def compile_path(prepared_path, anchor = true, requirements = {})
189189

190190
def call(env)
191191
build_app
192+
build_helpers
192193
dup.call!(env)
193194
end
194195

@@ -307,12 +308,17 @@ def build_stack
307308
b.to_app
308309
end
309310

310-
def helpers
311-
mod = Module.new
312-
(namespace_stackable(:helpers) || []).each do |mod_to_include|
313-
mod.send :include, mod_to_include
311+
def build_helpers
312+
helpers = namespace_stackable(:helpers) || []
313+
Module.new do
314+
helpers.each do |mod_to_include|
315+
include mod_to_include
316+
end
314317
end
315-
mod
318+
end
319+
320+
def helpers
321+
@helpers ||= build_helpers
316322
end
317323

318324
def run_filters(filters, type = :other)

0 commit comments

Comments
 (0)