Module: MagicLinks::Templates

Defined in:
lib/magic_links/templates.rb

Class Method Summary collapse

Class Method Details

.add(name:, pattern:, action_scope:, strength:, expiry: nil) ⇒ Object



4
5
6
7
8
9
# File 'lib/magic_links/templates.rb', line 4

def add(name:, pattern:, action_scope:, strength:, expiry: nil)
  templates[name] = Template.new(pattern: pattern,
                                 action_scope: action_scope,
                                 strength: strength,
                                 expiry: expiry)
end

.find(name) ⇒ Object



11
12
13
# File 'lib/magic_links/templates.rb', line 11

def find(name)
  templates[name]
end

.match?(path) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/magic_links/templates.rb', line 15

def match?(path)
  templates.values.any? do |template|
    template.match? path
  end
end

.token_for(path) ⇒ Object



21
22
23
# File 'lib/magic_links/templates.rb', line 21

def token_for(path)
  templates.values.find { |template| template.match?(path) }&.token_for(path)
end