lib/plezi/handlers/controller_magic.rb in plezi-0.7.5 vs lib/plezi/handlers/controller_magic.rb in plezi-0.7.6

- old
+ new

@@ -104,31 +104,31 @@ raise 'Cannot use "send_data" after headers were sent' if response.headers_sent? # write data to response object response << data # set headers - content_disposition = "attachment" + content_disposition = 'attachment' options[:type] ||= MimeTypeHelper::MIME_DICTIONARY[::File.extname(options[:filename])] if options[:filename] if options[:type] - response["content-type"] = options[:type] + response['content-type'] = options[:type] options.delete :type end if options[:inline] - content_disposition = "inline" + content_disposition = 'inline' options.delete :inline end if options[:attachment] options.delete :attachment end if options[:filename] content_disposition << "; filename=#{options[:filename]}" options.delete :filename end - response["content-length"] = data.bytesize rescue true - response["content-disposition"] = content_disposition + response['content-length'] = data.bytesize rescue true + response['content-disposition'] = content_disposition response.finish true end # renders a template file (.slim/.erb/.haml) or an html file (.html) to text @@ -187,21 +187,21 @@ # (which is the last method called before the protocol is switched from HTTP to WebSockets). def requested_method # respond to websocket special case return :pre_connect if request['upgrade'] && request['upgrade'].to_s.downcase == 'websocket' && request['connection'].to_s.downcase == 'upgrade' # respond to save 'new' special case - return :save if request.request_method.match(/POST|PUT/) && params[:id].nil? || params[:id] == 'new' + return :save if request.request_method.match(/POST|PUT|PATCH/) && params[:id].nil? || params[:id] == 'new' # set DELETE method if simulated request.request_method = 'DELETE' if params[:_method].to_s.downcase == 'delete' # respond to special :id routing return params[:id].to_s.to_sym if params[:id] && self.class.available_public_methods.include?(params[:id].to_s.to_sym) #review general cases case request.request_method when 'GET', 'HEAD' return :index unless params[:id] return :show - when 'POST', 'PUT' + when 'POST', 'PUT', 'PATCH' return :update when 'DELETE' return :delete end false @@ -268,23 +268,23 @@ public # lists the available methods that will be exposed to HTTP requests def available_public_methods # set class global to improve performance while checking for supported methods - Plezi.cached?(self.superclass.name + "_p&rt") ? Plezi.get_cached(self.superclass.name + "_p&rt") : Plezi.cache_data(self.superclass.name + "_p&rt", available_routing_methods - [:before, :after, :save, :show, :update, :delete, :initialize, :on_message, :pre_connect, :on_connect, :on_disconnect]) + Plezi.cached?(self.superclass.name + '_p&rt') ? Plezi.get_cached(self.superclass.name + "_p&rt") : Plezi.cache_data(self.superclass.name + "_p&rt", (available_routing_methods - [:before, :after, :save, :show, :update, :delete, :initialize, :on_message, :pre_connect, :on_connect, :on_disconnect]).to_set ) end # lists the available methods that will be exposed to the HTTP router def available_routing_methods # set class global to improve performance while checking for supported methods - Plezi.cached?(self.superclass.name + "_r&rt") ? Plezi.get_cached(self.superclass.name + "_r&rt") : Plezi.cache_data(self.superclass.name + "_r&rt", (((public_instance_methods - Object.public_instance_methods) - Plezi::ControllerMagic::InstanceMethods.instance_methods).delete_if {|m| m.to_s[0] == '_'}) ) + Plezi.cached?(self.superclass.name + '_r&rt') ? Plezi.get_cached(self.superclass.name + "_r&rt") : Plezi.cache_data(self.superclass.name + "_r&rt", (((public_instance_methods - Object.public_instance_methods) - Plezi::ControllerMagic::InstanceMethods.instance_methods).delete_if {|m| m.to_s[0] == '_'}).to_set ) end # resets this controller's router, to allow for dynamic changes def reset_routing_cache - Plezi.clear_cached(self.superclass.name + "_p&rt") - Plezi.clear_cached(self.superclass.name + "_r&rt") + Plezi.clear_cached(self.superclass.name + '_p&rt') + Plezi.clear_cached(self.superclass.name + '_r&rt') available_routing_methods available_public_methods end # a callback that resets the class router whenever a method (a potential route) is added @@ -327,14 +327,14 @@ # end # end # raise "Redis connction failed for: #{ENV['PL_REDIS_URL']}" unless @@redis # @@redis return false unless defined?(Redis) && ENV['PL_REDIS_URL'] - return Plezi.get_cached(self.superclass.name + "_b") if Plezi.cached?(self.superclass.name + "_b") + return Plezi.get_cached(self.superclass.name + '_b') if Plezi.cached?(self.superclass.name + '_b') @@redis_uri ||= URI.parse(ENV['PL_REDIS_URL']) - Plezi.cache_data self.superclass.name + "_b", Redis.new(host: @@redis_uri.host, port: @@redis_uri.port, password: @@redis_uri.password) - raise "Redis connction failed for: #{ENV['PL_REDIS_URL']}" unless Plezi.cached?(self.superclass.name + "_b") + Plezi.cache_data self.superclass.name + '_b', Redis.new(host: @@redis_uri.host, port: @@redis_uri.port, password: @@redis_uri.password) + raise "Redis connction failed for: #{ENV['PL_REDIS_URL']}" unless Plezi.cached?(self.superclass.name + '_b') t = Thread.new do begin Redis.new(host: @@redis_uri.host, port: @@redis_uri.port, password: @@redis_uri.password).subscribe(redis_channel_name) do |on| on.message do |channel, msg| args = JSON.parse(msg) @@ -345,11 +345,11 @@ rescue Exception => e Plezi.error e retry end end - Plezi.cache_data self.superclass.name + "_t", t - Plezi.get_cached(self.superclass.name + "_b") + Plezi.cache_data self.superclass.name + '_t', t + Plezi.get_cached(self.superclass.name + '_b') end # returns a Redis channel name for this controller. def redis_channel_name self.superclass.name.to_s