Module: Spider::Dispatcher::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#add_chain_item(method, proc, params) ⇒ Object



217
218
219
220
221
# File 'lib/spiderfw/controller/dispatcher.rb', line 217

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



201
202
203
204
205
206
207
# File 'lib/spiderfw/controller/dispatcher.rb', line 201

def add_route(routes, path, dest=nil, options=nil)
    if ( path.is_a? Hash )
        path.each {|p,d| add_route(p, d)}
    else
        routes << [path, dest, options || {}]
    end
end

#check_action(action, check) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/spiderfw/controller/dispatcher.rb', line 232

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



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

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

#dispatch_methodsObject



228
229
230
# File 'lib/spiderfw/controller/dispatcher.rb', line 228

def dispatch_methods
    @dispatch_methods
end

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



209
210
211
# File 'lib/spiderfw/controller/dispatcher.rb', line 209

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

#routesObject



213
214
215
# File 'lib/spiderfw/controller/dispatcher.rb', line 213

def routes
    @routes ||= []
end