Class: MethodMissingRouter::Route

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regex, target, options) ⇒ Route

Returns a new instance of Route.



71
72
73
74
75
# File 'lib/method_missing_router.rb', line 71

def initialize(regex, target, options)
  @regex = regex
  @target = target
  @options = options
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



69
70
71
# File 'lib/method_missing_router.rb', line 69

def target
  @target
end

Instance Method Details

#applies_to?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/method_missing_router.rb', line 77

def applies_to?(method_name)
  @regex =~ method_name
end

#message_for(method_name) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/method_missing_router.rb', line 81

def message_for(method_name)
  captures = @regex.match(method_name).captures
  if @options[:pass_matches]
    return captures
  elsif @options[:pass_match]
    return captures.first 
  else
    return method_name.to_s
  end
end