Method: Innate::Node#patterns_for
- Defined in:
- lib/innate/node.rb
#patterns_for(path) ⇒ Action
The innate beauty in Nitro, Ramaze, and Innate.
Will yield the name of the action and parameter for the action method in order of significance.
def foo__bar # responds to /foo/bar
def foo(bar) # also responds to /foo/bar
But foo__bar takes precedence because it’s more explicit.
The last fallback will always be the index action with all of the path turned into parameters.
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 |
# File 'lib/innate/node.rb', line 739 def patterns_for(path) default_action_name = ancestral_trait[:default_action_name] separate_default_action = ancestral_trait[:separate_default_action] atoms = path.split('/') atoms.delete('') result = nil atoms.size.downto(0) do |len| action_name = atoms[0...len].join('__') next if separate_default_action && action_name == default_action_name params = atoms[len..-1] action_name = default_action_name if action_name.empty? && (separate_default_action || params != [default_action_name]) return result if result = yield(action_name, params) end return nil end |