Module: Jets::Router::Util

Included in:
MethodCreator, MethodCreator::Code, Route, Scope
Defined in:
lib/jets/router/util.rb

Instance Method Summary collapse

Instance Method Details

#get_controller_action(options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jets/router/util.rb', line 14

def get_controller_action(options)
  if options.key?(:controller) && options.key?(:action)
    [options[:controller], options[:action]]
  elsif options.key?(:controller) && options.key?(:to)
    action = options[:to].split('#').last
    [options[:controller], action]
  elsif options.key?(:on)
    handle_on!(options)
  else
    options[:to].split('#') # controller, action
  end
end

#handle_on!(options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/jets/router/util.rb', line 27

def handle_on!(options)
  controller = @scope.options[:prefix].to_s
  to = "#{controller}##{options[:path]}"
  options[:to] = to

  as = @options[:on] == :member ? controller.singularize : controller
  as = "#{@options[:path]}_#{as}"
  options[:as] = as
  to.split('#')
end

#join(*items) ⇒ Object

used in MethodCreator logic



4
5
6
7
# File 'lib/jets/router/util.rb', line 4

def join(*items)
  list = items.compact.join('_')
  underscore(list)
end

#underscore(str) ⇒ Object



9
10
11
12
# File 'lib/jets/router/util.rb', line 9

def underscore(str)
  return unless str
  str.to_s.gsub(/[^a-zA-Z0-9]/,'_')
end