class Peictt::Http::MATCH

Constants

DEFAULT_METHODS

Attributes

action[R]
controller[R]
regexp[R]
verb[R]

Public Class Methods

new(regexp, options = {}) click to toggle source
# File lib/peictt/http/match.rb, line 8
def initialize(regexp, options = {})
  @regexp = (regexp if regexp.is_a? Regexp) || regexp_error
  controller_error unless options.key? :controller
  set_controller options[:controller]
  @action = options[:action] || action_error
  get_verbs options[:methods]
end

Private Instance Methods

action_error() click to toggle source
# File lib/peictt/http/match.rb, line 52
def action_error
  raise ArgumentError.new("action for match not provided")
end
controller_error() click to toggle source
# File lib/peictt/http/match.rb, line 48
def controller_error
  raise ArgumentError.new("controller for match not provided")
end
controller_from_camel_case(controller) click to toggle source
# File lib/peictt/http/match.rb, line 26
def controller_from_camel_case(controller)
  if /^[A-Z][a-z]+Controller/ =~ controller
    @controller = Object.const_get controller
  end
end
controller_from_string(controller) click to toggle source
# File lib/peictt/http/match.rb, line 32
def controller_from_string(controller)
  if /^[a-z_]+$/ =~ controller
    temp = controller.to_camel_case
    @controller = Object.const_get "#{temp}Controller"
  end
end
get_verbs(methods) click to toggle source
# File lib/peictt/http/match.rb, line 39
def get_verbs(methods)
  no_method_error methods
  @verb = (methods unless methods.empty?) || DEFAULT_METHODS
end
no_method_error(methods) click to toggle source
# File lib/peictt/http/match.rb, line 56
def no_method_error(methods)
  unless methods.is_a? Array
    raise ArgumentError.new("methods for match must be array")
  end
end
regexp_error() click to toggle source
# File lib/peictt/http/match.rb, line 44
def regexp_error
  raise ArgumentError.new("Provide regexp for match First argument")
end
set_controller(controller) click to toggle source
# File lib/peictt/http/match.rb, line 18
def set_controller(controller)
  if controller.is_a? String
    controller_from_camel_case(controller)
    controller_from_string(controller) unless @controller
  end
  @controller = controller unless @controller
end