Class: Yuriita::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/yuriita/route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, matcher, to) ⇒ Route

Returns a new instance of Route.



5
6
7
8
9
# File 'lib/yuriita/route.rb', line 5

def initialize(collection, matcher, to)
  @collection = collection
  @matcher = matcher
  @to = to
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



3
4
5
# File 'lib/yuriita/route.rb', line 3

def collection
  @collection
end

Instance Method Details

#actionObject



29
30
31
# File 'lib/yuriita/route.rb', line 29

def action
  to
end

#match?(input) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/yuriita/route.rb', line 11

def match?(input)
  case matcher
  when String
    # TODO better matching
    # This won't work for string matching becuase to_s will use quotes
    # Could we parse it and compare the queries? This would maybe let us
    # catch parse exceptions
    #
    # If we do parse the matcher we could warn if it resulted in more than
    # two inputs.
    input.to_s == matcher
  when Proc
    matcher.call(input)
  else
    matcher.match?(input)
  end
end