Included Modules

Innate::Node

The nervous system of {Innate}, so you can relax.

Node may be included into any class to make it a valid responder to requests.

The major difference between this and the old Ramaze controller is that every Node acts as a standalone application with its own dispatcher.

What’s also an important difference is the fact that {Node} is a module, so we don’t have to spend a lot of time designing the perfect subclassing scheme.

This makes dispatching more fun, avoids a lot of processing that is done by Rack anyway and lets you tailor your application down to the last action exactly the way you want without worrying about side-effects to other {Node}s.

Upon inclusion, it will also include {Innate::Trinity} and {Innate::Helper} to provide you with {Innate::Request}, {Innate::Response}, {Innate::Session} instances, and all the standard helper methods as well as the ability to simply add other helpers.

Please note that method_missing will not be considered when building an {Action}. There might be future demand for this, but for now you can simply use `def index(*args); end` to make a catch-all action.

Constants

NODE_LIST

Attributes

method_arities[R]
layout_templates[R]
view_templates[R]

Public Class Methods

generate_mapping(object_name = self.name) click to toggle source
    # File lib/innate/node.rb, line 90
90:     def self.generate_mapping(object_name = self.name)
91:       return '/' if NODE_LIST.size == 1
92:       parts = object_name.split('::').map{|part|
93:         part.gsub(/^[A-Z]+/){|sub| sub.downcase }.gsub(/[A-Z]+[^A-Z]/, '_\&')
94:       }
95:       '/' << parts.join('/').downcase
96:     end
included(into) click to toggle source

Upon inclusion we make ourselves comfortable.

    # File lib/innate/node.rb, line 63
63:     def self.included(into)
64:       into.__send__(:include, Helper)
65:       into.extend(Trinity, self)
66: 
67:       NODE_LIST << into
68: 
69:       return if into.provide_set?
70:       into.provide(:html, :engine => :Etanni)
71:       into.trait(:provide_set => false)
72:     end
setup() click to toggle source

node mapping procedure

when Node is included into an object, it’s added to NODE_LIST when object::map(location) is sent, it maps the object into DynaMap when Innate.start is issued, it calls Node::setup Node::setup iterates NODE_LIST and maps all objects not in DynaMap by using Node::generate_mapping(object.name) as location

when object::map(nil) is sent, the object will be skipped in Node::setup

    # File lib/innate/node.rb, line 84
84:     def self.setup
85:       NODE_LIST.each{|node|
86:         node.map(generate_mapping(node.name)) unless node.trait[:skip_node_map]
87:       }
88:     end

Public Instance Methods

action_found(action) click to toggle source

Executed once an {Action} has been found.

Reset the {Innate::Response} instance, catch :respond and :redirect. {Action#call} has to return a String.

@param [Action] action

@return [Innate::Response]

@api external @see Action#call Innate::Response @author manveru

     # File lib/innate/node.rb, line 298
298:     def action_found(action)
299:       response = catch(:respond){ catch(:redirect){ action.call }}
300: 
301:       unless response.respond_to?(:finish)
302:         self.response.write(response)
303:         response = self.response
304:       end
305: 
306:       response['Content-Type'] ||= action.options[:content_type]
307:       response
308:     end
action_missing(path) click to toggle source

The default handler in case no action was found, kind of method_missing. Must modify the response in order to have any lasting effect.

Reasoning:

  • We are doing this is in order to avoid tons of special error handling code that would impact runtime and make the overall API more complicated.

  • This cannot be a normal action is that methods defined in {Innate::Node} will never be considered for actions.

To use a normal action with template do following:

@example

  class Hi
    include Innate::Node
    map '/'

    def self.action_missing(path)
      return if path == '/not_found'
      # No normal action, runs on bare metal
      try_resolve('/not_found')
    end

    def not_found
      # Normal action
      "Sorry, I do not exist"
    end
  end

@param [String] path

@api external @see Innate::Response Node#try_resolve @author manveru

     # File lib/innate/node.rb, line 345
345:     def action_missing(path)
346:       response = Current.response
347:       response.status = 404
348:       response['Content-Type'] = 'text/plain'
349:       response.write("No action found at: %p" % path)
350: 
351:       response
352:     end
alias_view(to, from, node = nil) click to toggle source

Aliasing one view from another. The aliases are inherited, and the optional third node parameter indicates the Node to take the view from.

The argument order is identical with `alias` and `alias_method`, which quite honestly confuses me, but at least we stay consistent.

@example

  class Foo
    include Innate::Node

    # Use the 'foo' view when calling 'bar'
    alias_view 'bar', 'foo'

    # Use the 'foo' view from FooBar node when calling 'bar'
    alias_view 'bar', 'foo', FooBar
  end

Note that the parameters have been simplified in comparision with Ramaze::Controller::template where the second parameter may be a Controller or the name of the template. We take that now as an optional third parameter.

@param [#] to view that should be replaced @param [#] from view to use or Node. @param [#, Node] node optionally obtain view from this Node

@api external @see Node::find_aliased_view @author manveru

     # File lib/innate/node.rb, line 611
611:     def alias_view(to, from, node = nil)
612:       trait[:alias_view] || trait(:alias_view => {})
613:       trait[:alias_view][to.to_s] = node ? [from.to_s, node] : from.to_s
614:     end
binding() click to toggle source

For compatibility with new Kernel#binding behaviour in 1.9

@return [Binding] binding of the instance being rendered. @see Action#binding @author manveru

     # File lib/innate/node.rb, line 892
892:     def binding; super end
call(env) click to toggle source

This makes the Node a valid application for Rack. env is the environment hash passed from the Rack::Handler

We rely on correct PATH_INFO.

As defined by the Rack spec, PATH_INFO may be empty if it wants the root of the application, so we insert ’/’ to make our dispatcher simple.

Innate will not rescue any errors for you or do any error handling, this should be done by an underlying middleware.

We do however log errors at some vital points in order to provide you with feedback in your logs.

A lot of functionality in here relies on the fact that call is executed within Current#call which populates the variables used by Trinity. So if you use the Node directly as a middleware make sure that you # Innate::Current as a middleware before it.

@param [Hash] env

@return [Array]

@api external @see Response#reset Node#try_resolve Session#flush @author manveru

     # File lib/innate/node.rb, line 263
263:     def call(env)
264:       path = env['PATH_INFO']
265:       path << '/' if path.empty?
266: 
267:       response.reset
268:       try_resolve(path).finish
269:     end
fill_action(action, given_name) click to toggle source

Now we’re talking {Action}, we try to find a matching template and method, if we can’t find either we go to the next pattern, otherwise we answer with an {Action} with everything we know so far about the demands of the client.

@param [String] given_name the name extracted from REQUEST_PATH @param [String] wish

@return [Action, nil]

@api internal @see Node#find_method Node#find_view Node#find_layout Node#patterns_for

     Action#wish Action#merge!

@author manveru

     # File lib/innate/node.rb, line 419
419:     def fill_action(action, given_name)
420:       needs_method = action.options[:needs_method]
421:       wish = action.wish
422: 
423:       patterns_for(given_name) do |name, params|
424:         method = find_method(name, params)
425: 
426:         next unless method if needs_method
427:         next unless method if params.any?
428:         next unless (view = find_view(name, wish)) || method
429: 
430:         params.map!{|param| Rack::Utils.unescape(param) }
431: 
432:         action.merge!(:method => method, :view => view, :params => params,
433:                       :layout => find_layout(name, wish))
434:       end
435:     end
find_aliased_view(action_name, wish) click to toggle source

Resolve one level of aliasing for the given action_name and wish.

@param [String] action_name @param [String] wish

@return [nil, String] the absolute path to the aliased template or nil

@api internal @see Node::alias_view Node::find_view @author manveru

     # File lib/innate/node.rb, line 626
626:     def find_aliased_view(action_name, wish)
627:       aliased_name, aliased_node = ancestral_trait[:alias_view][action_name]
628:       return unless aliased_name
629: 
630:       aliased_node ||= self
631:       aliased_node.update_view_mappings
632:       aliased_node.find_view(aliased_name, wish)
633:     end
find_layout(name, wish) click to toggle source

Try to find a suitable value for the layout. This may be a template or the name of a method.

If a layout could be found, an Array with two elements is returned, the first indicating the kind of layout (:layout|:view|:method), the second the found value, which may be a String or Symbol.

@param [String] name @param [String] wish

@return [Array, nil]

@api external @see Node#to_layout Node#find_method Node#find_view @author manveru

@todo allow layouts combined of method and view... hairy :)

     # File lib/innate/node.rb, line 454
454:     def find_layout(name, wish)
455:       return unless layout = ancestral_trait[:layout]
456:       return unless layout = layout.call(name, wish) if layout.respond_to?(:call)
457: 
458:       if found = to_layout(layout, wish)
459:         [:layout, found]
460:       elsif found = find_view(layout, wish)
461:         [:view, found]
462:       elsif found = find_method(layout, [])
463:         [:method, found]
464:       end
465:     end
find_method(name, params) click to toggle source

We check arity if possible, but will happily dispatch to any method that has default parameters. If you don’t want your method to be responsible for messing up a request you should think twice about the arguments you specify due to limitations in Ruby.

So if you want your method to take only one parameter which may have a default value following will work fine:

  def index(foo = "bar", *rest)

But following will respond to /arg1/arg2 and then fail due to ArgumentError:

  def index(foo = "bar")

Here a glance at how parameters are expressed in arity:

  def index(a)                  # => 1
  def index(a = :a)             # => -1
  def index(a, *r)              # => -2
  def index(a = :a, *r)         # => -1

  def index(a, b)               # => 2
  def index(a, b, *r)           # => -3
  def index(a, b = :b)          # => -2
  def index(a, b = :b, *r)      # => -2

  def index(a = :a, b = :b)     # => -1
  def index(a = :a, b = :b, *r) # => -1

@param [String, Symbol] name @param [Array] params

@return [String, Symbol]

@api external @see Node#fill_action Node#find_layout @author manveru

@todo Once 1.9 is mainstream we can use Method#parameters to do accurate

      prediction
     # File lib/innate/node.rb, line 508
508:     def find_method(name, params)
509:       return unless arity = method_arities[name.to_s]
510:       name if arity == params.size || arity < 0
511:     end
find_provide(path) click to toggle source

Resolve possible provides for the given path from {Innate::Node#provides}.

@param [String] path

@return [Array] with name, wish, engine

@api internal @see Node::provide Node::provides @author manveru

     # File lib/innate/node.rb, line 391
391:     def find_provide(path)
392:       pr = provides
393: 
394:       name, wish, engine = path, 'html', pr['html_handler']
395: 
396:       pr.find do |key, value|
397:         key = key[/(.*)_handler$/, 1]
398:         next unless path =~ /^(.+)\.#{key}$/
399:         name, wish, engine = $1, key, value
400:       end
401: 
402:       return name, wish, engine
403:     end
find_view(action_name, wish) click to toggle source

Try to find the best template for the given basename and wish and respect aliased views.

@param [#] action_name @param [#] wish

@return [String, nil] depending whether a template could be found

@api external @see Node#to_template Node#find_aliased_view @author manveru

     # File lib/innate/node.rb, line 555
555:     def find_view(action_name, wish)
556:       aliased = find_aliased_view(action_name, wish)
557:       return aliased if aliased
558: 
559:       to_view(action_name, wish)
560:     end
layout(layout_name = nil, &block) click to toggle source

Define a layout to use on this Node.

A Node can only have one layout, although the template being chosen can depend on {Innate::Node#provides}.

@example

  layout :foo

@example

  layout do |name, wish|
    name == 'foo' ? 'dark' : 'bright'
  end

@example

  layout :foo do |name, wish|
    wish == 'html'
  end

@param [String, #] name basename without extension of the layout to use @param [Proc, #] block called on every dispatch if no name given

@return [Proc, String] The assigned name or block

@api external @see Node#find_layout Node#layout_paths Node#to_layout Node#app_layout @author manveru

     # File lib/innate/node.rb, line 677
677:     def layout(layout_name = nil, &block)
678:       if layout_name and block
679:         # default name, but still check with block
680:         trait(:layout => lambda{|name, wish| layout_name.to_s if block.call(name, wish) })
681:       elsif layout_name
682:         # name of a method or template
683:         trait(:layout => layout_name.to_s)
684:       elsif block
685:         # call block every request with name and wish, returned value is name
686:         # of layout template or method
687:         trait(:layout => block)
688:       else
689:         # remove layout for this node
690:         trait(:layout => nil)
691:       end
692: 
693:       return ancestral_trait[:layout]
694:     end
layout_mappings() click to toggle source

Combine Innate.options.layouts with either the `ancestral_trait[:layouts]` or the {Node#mapping} if the trait yields an empty Array.

@return [Array, Array>]

@api external @see {Node#map_layouts} @author manveru

     # File lib/innate/node.rb, line 961
961:     def layout_mappings
962:       paths = [*ancestral_trait[:layouts]]
963:       paths = ['/'] if paths.empty?
964: 
965:       [[*options.layouts].flatten, [*paths].flatten]
966:     end
map(location) click to toggle source

Shortcut to map or remap this Node.

@example Usage for explicit mapping:

  class FooBar
    include Innate::Node
    map '/foo_bar'
  end

  Innate.to(FooBar) # => '/foo_bar'

@example Usage for automatic mapping:

  class FooBar
    include Innate::Node
    map mapping
  end

  Innate.to(FooBar) # => '/foo_bar'

@param [#] location

@api external @see Innate::SingletonMethods::map @author manveru

     # File lib/innate/node.rb, line 143
143:     def map(location)
144:       trait :skip_node_map => true
145:       Innate.map(location, self)
146:     end
map_layouts(*locations) click to toggle source

Set the paths for lookup below the Innate.options.layouts paths.

@param [String, Array] locations

  Any number of strings indicating the paths where layout templates may
  be located, relative to Innate.options.roots/Innate.options.layouts

@return [Node] self

@api external @see {Node#layout_mappings} @author manveru

     # File lib/innate/node.rb, line 948
948:     def map_layouts(*locations)
949:       trait :layouts => locations.flatten.uniq
950:       self
951:     end
map_views(*locations) click to toggle source

Set the paths for lookup below the Innate.options.views paths.

@param [String, Array] locations

  Any number of strings indicating the paths where view templates may be
  located, relative to Innate.options.roots/Innate.options.views

@return [Node] self

@api external @see {Node#view_mappings} @author manveru

     # File lib/innate/node.rb, line 917
917:     def map_views(*locations)
918:       trait :views => locations.flatten.uniq
919:       self
920:     end
mapping() click to toggle source

Tries to find the relative url that this {Node} is mapped to. If it cannot find one it will instead generate one based on the snake_cased name of itself.

@example Usage:

  class FooBar
    include Innate::Node
  end
  FooBar.mapping # => '/foo_bar'

@return [String] the relative path to the node

@api external @see Innate::SingletonMethods#to @author manveru

     # File lib/innate/node.rb, line 114
114:     def mapping
115:       Innate.to(self)
116:     end
needs_method?() click to toggle source

Whether an {Action} can be built without a method.

The default is to allow actions that use only a view template, but you might want to turn this on, for example if you have partials in your view directories.

@example turning needs_method? on

  class Foo
    Innate.node('/')
  end

  Foo.needs_method? # => true
  Foo.trait :needs_method => false
  Foo.needs_method? # => false

@return [true, false] (false)

@api external @see {Node#fill_action} @author manveru

     # File lib/innate/node.rb, line 993
993:     def needs_method?
994:       ancestral_trait[:needs_method]
995:     end
options() click to toggle source
     # File lib/innate/node.rb, line 968
968:     def options
969:       Innate.options
970:     end
patterns_for(path) click to toggle source

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.

@example yielding possible combinations of action names and params

  class Foo; include Innate::Node; map '/'; end

  Foo.patterns_for('/'){|action, params| p action => params }
  # => {"index"=>[]}

  Foo.patterns_for('/foo/bar'){|action, params| p action => params }
  # => {"foo__bar"=>[]}
  # => {"foo"=>["bar"]}
  # => {"index"=>["foo", "bar"]}

  Foo.patterns_for('/foo/bar/baz'){|action, params| p action => params }
  # => {"foo__bar__baz"=>[]}
  # => {"foo__bar"=>["baz"]}
  # => {"foo"=>["bar", "baz"]}
  # => {"index"=>["foo", "bar", "baz"]}

@param [String, #] path usually the PATH_INFO

@return [Action] it actually returns the first non-nil/false result of yield

@api internal @see Node#fill_action @author manveru

     # File lib/innate/node.rb, line 734
734:     def patterns_for(path)
735:       default_action_name = ancestral_trait[:default_action_name]
736:       separate_default_action = ancestral_trait[:separate_default_action]
737: 
738:       atoms = path.split('/')
739:       atoms.delete('')
740:       result = nil
741:       atoms.size.downto(0) do |len|
742:         action_name = atoms[0...len].join('__')
743: 
744:         next if separate_default_action && action_name == default_action_name
745: 
746:         params = atoms[len..1]
747: 
748:         action_name = default_action_name if action_name.empty? &&
749:           (separate_default_action || params != [default_action_name])
750: 
751:         return result if result = yield(action_name, params)
752:       end
753: 
754:       return nil
755:     end
possible_exts_for(wish) click to toggle source

Answer with an array of possible extensions in order of significance for the given wish.

@param [#] wish the extension (no leading ’.’)

@return [Array] list of exts valid for this wish

@api internal @see Node#to_template View::exts_of Node#provides @author manveru

     # File lib/innate/node.rb, line 879
879:     def possible_exts_for(wish)
880:       pr = provides
881:       return unless engine = pr["#{wish}_handler"]
882:       View.exts_of(engine).map{|e_ext|
883:         [[*wish].map{|w_ext| /#{w_ext}\.#{e_ext}$/ }, /#{e_ext}$/]
884:       }.flatten
885:     end
possible_paths_for(mappings) click to toggle source

Answer with an array of possible paths in order of significance for template lookup of the given mappings.

@param [#] An array two Arrays of inner and outer directories.

@return [Array] @see update_view_mappings update_layout_mappings update_template_mappings @author manveru

     # File lib/innate/node.rb, line 862
862:     def possible_paths_for(mappings)
863:       root_mappings.map{|root|
864:         mappings.first.map{|inner|
865:           mappings.last.map{|outer|
866:             ::File.join(root, inner, outer, '/') }}}.flatten
867:     end
provide(format, param = {}, &block) click to toggle source

Specify which way contents are provided and processed.

Use this to set a templating engine, custom Content-Type, or pass a block to take over the processing of the {Action} and template yourself.

Provides set via this method will be inherited into subclasses.

The format is extracted from the PATH_INFO, it simply represents the last extension name in the path.

The provide also has influence on the chosen templates for the {Action}.

@example providing RSS with ERB templating

  provide :rss, :engine => :ERB

Given a request to `/list.rss` the template lookup first tries to find `list.rss.erb`, if that fails it falls back to `list.erb`. If neither of these are available it will try to use the return value of the method in the {Action} as template.

A request to `/list.yaml` would match the format ‘yaml’

@example providing a yaml version of actions

  class Articles
    include Innate::Node
    map '/article'

    provide(:yaml, :type => 'text/yaml'){|action, value| value.to_yaml }

    def list
      @articles = Article.list
    end
  end

@example providing plain text inspect version

  class Articles
    include Innate::Node
    map '/article'

    provide(:txt, :type => 'text/plain'){|action, value| value.inspect }

    def list
      @articles = Article.list
    end
  end

@param [Proc] block

  upon calling the action, [action, value] will be passed to it and its
  return value becomes the response body.

@option param :engine [Symbol String]

  Name of an engine for View::get

@option param :type [String]

  default Content-Type if none was set in Response

@raise [ArgumentError] if neither a block nor an engine was given

@api external @see View::get Node#provides @author manveru

@todo

  The comment of this method may be too short for the effects it has on
  the rest of Innate, if you feel something is missing please let me
  know.
     # File lib/innate/node.rb, line 217
217:     def provide(format, param = {}, &block)
218:       if param.respond_to?(:to_hash)
219:         param = param.to_hash
220:         handler = block || View.get(param[:engine])
221:         content_type = param[:type]
222:       else
223:         handler = View.get(param)
224:       end
225: 
226:       raise(ArgumentError, "Need an engine or block") unless handler
227: 
228:       trait("#{format}_handler"      => handler, :provide_set => true)
229:       trait("#{format}_content_type" => content_type) if content_type
230:     end
provide_set?() click to toggle source

This will return true if the only provides set are by {Innate::Node.included}.

The reasoning behind this is to determine whether the user has touched the provides at all, in which case we will not override the provides in subclasses.

@return [true, false] (false)

@api internal @see {Node::included} @author manveru

      # File lib/innate/node.rb, line 1009
1009:     def provide_set?
1010:       ancestral_trait[:provide_set]
1011:     end
provides() click to toggle source
     # File lib/innate/node.rb, line 232
232:     def provides
233:       ancestral_trait.reject{|key, value| key !~ /_handler$/ }
234:     end
resolve(path, options = {}) click to toggle source

Let’s get down to business, first check if we got any wishes regarding the representation from the client, otherwise we will assume he wants html.

@param [String] path @param [Hash] options

@return [nil, Action]

@api external @see Node::find_provide Node::update_method_arities Node::find_action @author manveru

     # File lib/innate/node.rb, line 366
366:     def resolve(path, options = {})
367:       name, wish, engine = find_provide(path)
368:       node = (respond_to?(:ancestors) && respond_to?(:new)) ? self : self.class
369:       action = Action.create(:node => node, :wish => wish, :engine => engine, :path => path, :options => options)
370:       action.options.key?(:needs_method) || action.options[:needs_method] = node.needs_method?
371: 
372:       if content_type = node.ancestral_trait["#{wish}_content_type"]
373:         action.options = {:content_type => content_type}
374:       end
375: 
376:       node.update_method_arities
377:       node.update_template_mappings
378:       node.fill_action(action, name)
379:     end
root_mappings() click to toggle source

make sure this is an Array and a new instance so modification on the wrapping array doesn’t affect the original option. [*arr].object_id == arr.object_id if arr is an Array

@return [Array] list of root directories

@api external @author manveru

     # File lib/innate/node.rb, line 902
902:     def root_mappings
903:       [*options.roots].flatten
904:     end
to_layout(action_name, wish) click to toggle source

Find the best matching action_name for the layout, if any.

This is mostly an abstract method that you might find handy if you want to do vastly different layout lookup.

@param [String] action_name @param [String] wish

@return [nil, String] the absolute path to the template or nil

@api external @see {Node#to_template} {Node#root_mappings} {Node#layout_mappings} @author manveru

     # File lib/innate/node.rb, line 648
648:     def to_layout(action_name, wish)
649:       return unless files = layout_templates[wish.to_s]
650:       files[action_name.to_s]
651:     end
to_template(path, wish) click to toggle source

Try to find a template at the given path for wish.

Since Innate supports multiple paths to templates the path has to be an Array that may be nested one level.

@example Usage to find available templates

  # This assumes following files:
  # view/foo.erb
  # view/bar.erb
  # view/bar.rss.erb
  # view/bar.yaml.erb

  class FooBar
    Innate.node('/')
  end

  FooBar.to_template(['.', 'view', '/', 'foo'], 'html')
  # => "./view/foo.erb"
  FooBar.to_template(['.', 'view', '/', 'foo'], 'yaml')
  # => "./view/foo.erb"
  FooBar.to_template(['.', 'view', '/', 'foo'], 'rss')
  # => "./view/foo.erb"

  FooBar.to_template(['.', 'view', '/', 'bar'], 'html')
  # => "./view/bar.erb"
  FooBar.to_template(['.', 'view', '/', 'bar'], 'yaml')
  # => "./view/bar.yaml.erb"
  FooBar.to_template(['.', 'view', '/', 'bar'], 'rss')
  # => "./view/bar.rss.erb"

@param [Array>, Array] path

  array containing strings and nested (1 level) arrays containing strings

@param [String] wish

@return [nil, String] relative path to the first template found

@api external @see Node#find_view Node#to_layout Node#find_aliased_view @author manveru

     # File lib/innate/node.rb, line 797
797:     def to_template(path, wish)
798:       to_view(path, wish) || to_layout(path, wish)
799:     end
to_view(action_name, wish) click to toggle source

Try to find the best template for the given basename and wish.

This method is mostly here for symetry with {Innate::Node#to_layout} and to allow you overriding the template lookup easily.

@param [#] action_name @param [#] wish

@return [String, nil] depending whether a template could be found

@api external @see {Node#find_view} {Node#to_template} {Node#root_mappings}

     {Node#view_mappings} {Node#to_template}

@author manveru

     # File lib/innate/node.rb, line 576
576:     def to_view(action_name, wish)
577:       return unless files = view_templates[wish.to_s]
578:       files[action_name.to_s]
579:     end
try_resolve(path) click to toggle source

Let’s try to find some valid action for given path. Otherwise we dispatch to {Innate::Node#action_missing}.

@param [String] path from env[‘PATH_INFO’]

@return [Response]

@api external @see Node#resolve Node#action_found Node#action_missing @author manveru

     # File lib/innate/node.rb, line 281
281:     def try_resolve(path)
282:       action = resolve(path)
283:       action ? action_found(action) : action_missing(path)
284:     end
update_layout_mappings() click to toggle source
     # File lib/innate/node.rb, line 815
815:     def update_layout_mappings
816:       if ancestral_trait[:fast_mappings]
817:         return @layout_templates if instance_variable_defined?(:@layout_templates)
818:       end
819: 
820:       paths = possible_paths_for(layout_mappings)
821:       @layout_templates = update_mapping_shared(paths)
822:     end
update_mapping_shared(paths) click to toggle source
     # File lib/innate/node.rb, line 824
824:     def update_mapping_shared(paths)
825:       mapping = {}
826:       paths.reject!{|path| !File.directory?(path) }
827: 
828:       provides.each do |wish_key, engine|
829:         wish = wish_key[/(.*)_handler/, 1]
830:         exts = possible_exts_for(wish)
831: 
832:         paths.reverse_each do |path|
833:           Find.find(path) do |file|
834:             exts.each do |ext|
835:               next unless file =~ ext
836: 
837:               case file.sub(path, '').gsub('/', '__')
838:               when /^(.*)\.(.*)\.(.*)$/
839:                 action_name, wish_ext, engine_ext = $1, $2, $3
840:               when /^(.*)\.(.*)$/
841:                 action_name, wish_ext, engine_ext = $1, wish, $2
842:               end
843: 
844:               mapping[wish_ext] ||= {}
845:               mapping[wish_ext][action_name] = file
846:             end
847:           end
848:         end
849:       end
850: 
851:       return mapping
852:     end
update_method_arities() click to toggle source

Answer with a hash, keys are method names, values are method arities.

Note that this will be executed once for every request, once we have settled things down a bit more we can switch to update based on Reloader hooks and update once on startup. However, that may cause problems with dynamically created methods, so let’s play it safe for now.

@example

  Hi.update_method_arities
  # => {'index' => 0, 'foo' => -1, 'bar' => 2}

@api internal @see Node#resolve @return [Hash] mapping the name of the methods to their arity

     # File lib/innate/node.rb, line 529
529:     def update_method_arities
530:       @method_arities = {}
531: 
532:       exposed = ancestors & Helper::EXPOSE.to_a
533:       higher = ancestors.select{|ancestor| ancestor < Innate::Node }
534: 
535:       (higher + exposed).reverse_each do |ancestor|
536:         ancestor.public_instance_methods(false).each do |im|
537:           @method_arities[im.to_s] = ancestor.instance_method(im).arity
538:         end
539:       end
540: 
541:       @method_arities
542:     end
update_template_mappings() click to toggle source
     # File lib/innate/node.rb, line 801
801:     def update_template_mappings
802:       update_view_mappings
803:       update_layout_mappings
804:     end
update_view_mappings() click to toggle source
     # File lib/innate/node.rb, line 806
806:     def update_view_mappings
807:       if ancestral_trait[:fast_mappings]
808:         return @view_templates if instance_variable_defined?(:@view_templates)
809:       end
810: 
811:       paths = possible_paths_for(view_mappings)
812:       @view_templates = update_mapping_shared(paths)
813:     end
view_mappings() click to toggle source

Combine Innate.options.views with either the `ancestral_trait[:views]` or the {Node#mapping} if the trait yields an empty Array.

@return [Array, Array>]

@api external @see {Node#map_views} @author manveru

     # File lib/innate/node.rb, line 930
930:     def view_mappings
931:       paths = [*ancestral_trait[:views]]
932:       paths = [mapping] if paths.empty?
933: 
934:       [[*options.views].flatten, [*paths].flatten]
935:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.