Module: Innate::SingletonMethods
- Included in:
- Ramaze
- Defined in:
- /home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/dynamap.rb,
/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/node.rb,
/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/route.rb,
/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/state.rb
Overview
script_name, path_info = env['SCRIPT_NAME'], env['PATH_INFO'] answer = app.call(env) env.merge!('SCRIPT_NAME' => script_name, 'PATH_INFO' => path_info) answer
Instance Method Summary (collapse)
-
- (Object) at(location)
Answer with object at +location+.
-
- (Object) defer
-
- (Object) map(location, object = nil, &block)
Maps the given +object+ or +block+ to +location+, +object+ must respond to #call in order to be of any use.
-
- (Class, Module) node(location, node = nil)
Convenience method to include the Node module into +node+ and map to a +location+.
-
- (Class, Module) node_from_backtrace(backtrace)
Cheap hack that works reasonably well to avoid passing self all the time to Innate::node We simply search the file that Innate::node was called in for the first class definition above the line that Innate::node was called and look up the constant.
-
- (Object) Rewrite(key, value = nil, &block)
-
- (Object) Route(key, value = nil, &block)
-
- (Object) sync(&block)
Use this method to achieve thread-safety for sensitive operations.
-
- (Object) to(object)
Returns one of the paths the given +object+ is mapped to.
Instance Method Details
- (Object) at(location)
Answer with object at +location+.
78 79 80 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/dynamap.rb', line 78 def at(location) DynaMap.at(location) end |
- (Object) defer
18 19 20 21 22 23 24 25 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/state.rb', line 18 def defer outer = ::Thread.current ::Thread.new{ inner = ::Thread.current outer.keys.each{|k| inner[k] = outer[k] } yield } end |
- (Object) map(location, object = nil, &block)
Maps the given +object+ or +block+ to +location+, +object+ must respond to
call in order to be of any use.
64 65 66 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/dynamap.rb', line 64 def map(location, object = nil, &block) DynaMap.map(location, object || block) end |
- (Class, Module) node(location, node = nil)
Convenience method to include the Node module into +node+ and map to a +location+.
1076 1077 1078 1079 1080 1081 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/node.rb', line 1076 def node(location, node = nil) node ||= node_from_backtrace(caller) node.__send__(:include, Node) node.map(location) node end |
- (Class, Module) node_from_backtrace(backtrace)
Cheap hack that works reasonably well to avoid passing self all the time to Innate::node We simply search the file that Innate::node was called in for the first class definition above the line that Innate::node was called and look up the constant. If there are any problems with this (filenames containing ':' or metaprogramming) just pass the node parameter explicitly to Innate::node
1098 1099 1100 1101 1102 1103 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/node.rb', line 1098 def node_from_backtrace(backtrace) filename, lineno = backtrace[0].split(':', 2) regexp = /^\s*class\s+(\S+)/ File.readlines(filename)[0..lineno.to_i].reverse.find{|ln| ln =~ regexp } const_get($1) end |
- (Object) Rewrite(key, value = nil, &block)
110 111 112 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/route.rb', line 110 def Rewrite(key, value = nil, &block) Rewrite[key] = value || block end |
- (Object) Route(key, value = nil, &block)
106 107 108 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/route.rb', line 106 def Route(key, value = nil, &block) Route[key] = value || block end |
- (Object) sync(&block)
Use this method to achieve thread-safety for sensitive operations.
This should be of most use when manipulating files to prevent other threads from doing the same, no other code will be scheduled during execution of this method.
14 15 16 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/state.rb', line 14 def sync(&block) SEMAPHORE.synchronize(&block) end |
- (Object) to(object)
Returns one of the paths the given +object+ is mapped to.
92 93 94 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/dynamap.rb', line 92 def to(object) DynaMap.to(object) end |