Module: Spider::Dispatcher::ClassMethods

Defined in:
lib/spiderfw/controller/dispatcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_dispatcherObject

Returns the value of attribute default_dispatcher.



224
225
226
# File 'lib/spiderfw/controller/dispatcher.rb', line 224

def default_dispatcher
  @default_dispatcher
end

#default_routeObject

Returns the value of attribute default_route.



224
225
226
# File 'lib/spiderfw/controller/dispatcher.rb', line 224

def default_route
  @default_route
end

#nil_routeObject

Returns the value of attribute nil_route.



224
225
226
# File 'lib/spiderfw/controller/dispatcher.rb', line 224

def nil_route
  @nil_route
end

Instance Method Details

#add_chain_item(method, proc, params) ⇒ Object



248
249
250
251
252
# File 'lib/spiderfw/controller/dispatcher.rb', line 248

def add_chain_item(method, proc, params)
    @dispatch_chains ||= {}
    @dispatch_chains[method] ||= []
    @dispatch_chains[method] << [proc, params]
end

#add_route(routes, path, dest = nil, options = nil) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/spiderfw/controller/dispatcher.rb', line 226

def add_route(routes, path, dest=nil, options=nil)
    if path.is_a?(Hash)
        path.each {|p,d| add_route(p, d)}
    elsif path.nil?
        @nil_route = [dest, options || {}]
    else
        routes << [path, dest, options || {}]
        if path.is_a?(String) && dest.respond_to?(:default_dispatcher=)
            dest.default_dispatcher = self
            dest.default_route = path
        end
    end
end

#check_action(action, check) ⇒ Object



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/spiderfw/controller/dispatcher.rb', line 263

def check_action(action, check)
    checks = check.is_a?(Array) ? check : [check]
    action = action.to_s
    action = default_action if action == ''
    action = action[0..-1] if action[-1].chr == '/'
    checks.each do |check|
        if check.is_a?(String)
            return true if (action == check || (action[-1].chr == '/' && action[0..-2] == check))
        elsif check.is_a?(Regexp)
            return true if action =~ check
        elsif check.is_a?(Proc)
            return true if check.call(action)
        elsif (check.is_a?(Symbol))
            first, rest = action.split('/', 2)
            return true if first && first.to_sym == check
        end
    end
    return false
end

#dispatch_chain(method) ⇒ Object



254
255
256
257
# File 'lib/spiderfw/controller/dispatcher.rb', line 254

def dispatch_chain(method)
    return [] unless @dispatch_chains && @dispatch_chains[method]
    @dispatch_chains[method]
end

#dispatch_methodsObject



259
260
261
# File 'lib/spiderfw/controller/dispatcher.rb', line 259

def dispatch_methods
    @dispatch_methods
end

#route(path, dest = nil, options = nil) ⇒ Object



240
241
242
# File 'lib/spiderfw/controller/dispatcher.rb', line 240

def route(path, dest=nil, options=nil)
    add_route(routes, path, dest, options)
end

#routesObject



244
245
246
# File 'lib/spiderfw/controller/dispatcher.rb', line 244

def routes
    @routes ||= []
end