lib/atd.rb in atd-0.3.1 vs lib/atd.rb in atd-0.3.2
- old
+ new
@@ -22,13 +22,12 @@
class Route
attr_accessor :args, :method, :block, :path, :output, :app, :actions
# The first two arguments must me the path and the output.
def initialize(*args, &block)
- args -= [nil]
- args.reject! { |arg| arg.is_a?(File) ? false : arg.empty? } # File doesn't respond to empty
- @method = (args.last.is_a?(Hash) && !args.last[:methods].nil? ? args.last[:methods] : [:get, :post, :put, :patch, :delete])
+ @method = [:get, :post, :put, :patch, :delete]
+ @method = [] if args.last.is_a?(Hash) && !(args.last[:respond_to].nil? || args.last[:ignore].nil?)
@app = :DefaultApp
parse_args(*args, &block)
end
# This works differently from a standard setter because is makes sure that a {Route} can belong to only one {App}.
@@ -67,11 +66,10 @@
[:get, :post, :put, :delete, :patch].each do |method|
define_method(method) do |*args, &block|
@method = [method] if @method.length == 5
@method += [method]
- @method += args.last[:respond_to] if args.last.is_a?(Hash) && !args.last[:respond_to].nil?
@method.uniq!
parse_args(*args, &block)
end
end
@@ -93,18 +91,22 @@
private
# This should also manage @message at some point
def parse_args(*args, &block)
+ args.compact!
+ args.flatten!
+ args.reject! { |arg| arg.is_a?(File) ? false : arg.empty? } # File doesn't respond to empty
@block = block
- @path = args.shift if @path.nil?
- @output = args.shift if @output.nil?
- @args = Array(@args).concat(args) - [nil] unless args.nil?
+ @path ||= args.shift
+ @output ||= args.shift
+ @args = Array(@args).concat(args) unless args.nil?
if @output =~ /^\w*#\w*$/ # Check if @path is a controller#action combo
controller, action = @output.split("#")
@action = Object.const_get(controller.to_sym).method(action.to_sym)
@output = @action.call
end
+ @method += Array(args.last[:respond_to]) if args.last.is_a?(Hash) && !args.last[:respond_to].nil?
@method -= Array(args.last[:ignore]) if args.last.is_a?(Hash) && !args.last[:ignore].nil?
self
end
end