lib/web_system/dev/request_command.rb in lizarb-1.0.3 vs lib/web_system/dev/request_command.rb in lizarb-1.0.4

- old
+ new

@@ -1,18 +1,11 @@ class WebSystem::RequestCommand < Liza::Command VALID_ACTIONS = %w[find get post] - def self.call(args) - log "Called #{self}.#{__method__} with args #{args}" - new.call(args) - end - - # instance methods - def call(args) - log "Called #{self}.#{__method__} with args #{args}" + log "args = #{args.inspect}" @command = args.shift @args = args return help unless VALID_ACTIONS.include? @command @@ -21,12 +14,10 @@ @error = error handle end def perform - log "Called #{self}.#{__method__}" - case @command when "find" find when "get" get_request @@ -34,23 +25,20 @@ post_request end end def handle - log "Called #{self}.#{__method__}" log render "error.txt" end def help - log "Called #{self}.#{__method__}" log render "help.txt" end # actions def find - log "Called #{self}.#{__method__}" path = @args.first @env = {} @env["REQUEST_PATH"] = path @@ -60,11 +48,10 @@ puts render "find.txt" end def get_request - log "Called #{self}.#{__method__}" path = @args.first @env = {} @env["REQUEST_METHOD"] = "GET" @env["REQUEST_PATH"] = path @@ -73,11 +60,10 @@ log "STATUS #{@status} with #{@headers.count} headers and a #{@body.first.size} byte body" puts render "response.http" end def post_request - log "Called #{self}.#{__method__}" path = @args.first @env = {} @env["REQUEST_METHOD"] = "POST" @env["REQUEST_PATH"] = path @@ -94,34 +80,34 @@ end end __END__ -# success.txt.erb +# view success.txt.erb RESULT: class <%= @result.class %> value <%= @result %> -# error.txt.erb +# view error.txt.erb ERROR: class <%= @error.class %> message <%= @error.message %> backtrace <%= @error.backtrace.select { |s| @stop = true if s.include?("/exe/lizarb:"); !defined? @stop }.join "\n " %> -# help.txt.erb +# view help.txt.erb USAGE: liza request find /path/to/action.format liza request get /path/to/action.format liza request post /path/to/action.format -# find.txt.erb +# view find.txt.erb ENV: <% @env.each do |k, v| %> env["<%= k %>"] = <%= v.inspect -%> <% end %> @@ -131,10 +117,10 @@ # <%= @request_class.source_location.join ":" %> class <%= @request_class %> < <%= @request_class.superclass %> # ... end -# response.http.erb +# view response.http.erb <%= @status %> <% @headers.each do |k, v| -%> <%= k %>: <%= v %> <% end -%>