Module: AsyncRender::Utils
- Included in:
- AsyncHelper, MemoizedHelper, Warmup
- Defined in:
- lib/async_render/utils.rb
Instance Method Summary collapse
- #build_memoized_render_key(partial, locals) ⇒ Object
- #generate_token(partial) ⇒ Object
- #normalize_locals(locals, locals_kw) ⇒ Object
Instance Method Details
#build_memoized_render_key(partial, locals) ⇒ Object
10 11 12 13 |
# File 'lib/async_render/utils.rb', line 10 def build_memoized_render_key(partial, locals) return partial if locals.nil? || locals.empty? [ partial, locals.to_a.sort_by { |(k, _)| k.to_s } ] end |
#generate_token(partial) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/async_render/utils.rb', line 3 def generate_token(partial) # Fast random token generation using Random.bytes partial_id = partial.downcase.gsub(/[^a-z0-9\/]/, "").slice(0, 100) random_hex = Random.bytes(5).unpack1("H*") "#{partial_id}/#{random_hex}" end |
#normalize_locals(locals, locals_kw) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/async_render/utils.rb', line 15 def normalize_locals(locals, locals_kw) if locals.nil? locals_kw elsif locals_kw.empty? locals else locals.merge(locals_kw) end end |