From dddf48207b0dcac1d3d0d67916f9821243ab3f8c Mon Sep 17 00:00:00 2001 From: namusyaka Date: Tue, 20 Sep 2016 14:44:16 +0900 Subject: [PATCH 1/5] fix a little bit whitespace --- lib/sinatra/base.rb | 8 ++++---- lib/sinatra/show_exceptions.rb | 4 ++-- sinatra-contrib/lib/sinatra/config_file.rb | 2 +- sinatra-contrib/lib/sinatra/content_for.rb | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index e7f7ebd6..2fc5dbab 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -705,7 +705,7 @@ module Sinatra render :less, template, options, locals end - def stylus(template, options={}, locals={}) + def stylus(template, options = {}, locals = {}) options.merge! :layout => false, :default_content_type => :css render :styl, template, options, locals end @@ -1081,7 +1081,7 @@ module Sinatra # Creates a Hash with indifferent access. def indifferent_hash - Hash.new {|hash,key| hash[key.to_s] if Symbol === key } + Hash.new { |hash, key| hash[key.to_s] if Symbol === key } end # Run the block with 'throw :halt' support and apply result to the response. @@ -1909,9 +1909,9 @@ module Sinatra # top-level. Subclassing Sinatra::Base is highly recommended for # modular applications. class Application < Base - set :logging, Proc.new { ! test? } + set :logging, Proc.new { !test? } set :method_override, true - set :run, Proc.new { ! test? } + set :run, Proc.new { !test? } set :session_secret, Proc.new { super() unless development? } set :app_file, nil diff --git a/lib/sinatra/show_exceptions.rb b/lib/sinatra/show_exceptions.rb index ab26997e..c0ed224f 100644 --- a/lib/sinatra/show_exceptions.rb +++ b/lib/sinatra/show_exceptions.rb @@ -15,7 +15,7 @@ module Sinatra def @@eats_errors.puts(*) end def initialize(app) - @app = app + @app = app end def call(env) @@ -51,7 +51,7 @@ module Sinatra def prefers_plain_text?(env) !(Request.new(env).preferred_type("text/plain","text/html") == "text/html") && - [/curl/].index{|item| item =~ env["HTTP_USER_AGENT"]} + [/curl/].index { |item| item =~ env["HTTP_USER_AGENT"] } end def frame_class(frame) diff --git a/sinatra-contrib/lib/sinatra/config_file.rb b/sinatra-contrib/lib/sinatra/config_file.rb index 0ad8e88c..0bddd6fc 100644 --- a/sinatra-contrib/lib/sinatra/config_file.rb +++ b/sinatra-contrib/lib/sinatra/config_file.rb @@ -161,7 +161,7 @@ module Sinatra end if hash.respond_to? :to_hash - indifferent_hash = Hash.new {|hash,key| hash[key.to_s] if Symbol === key } + indifferent_hash = Hash.new { |hash, key| hash[key.to_s] if Symbol === key } indifferent_hash.merge hash.to_hash else hash diff --git a/sinatra-contrib/lib/sinatra/content_for.rb b/sinatra-contrib/lib/sinatra/content_for.rb index 0d444d15..c61d8191 100644 --- a/sinatra-contrib/lib/sinatra/content_for.rb +++ b/sinatra-contrib/lib/sinatra/content_for.rb @@ -179,7 +179,7 @@ module Sinatra private def content_blocks - @content_blocks ||= Hash.new {|h,k| h[k] = [] } + @content_blocks ||= Hash.new { |h, k| h[k] = [] } end end From 6543ce63c4b4924ce86b1fa2757540f29cb8372d Mon Sep 17 00:00:00 2001 From: namusyaka Date: Wed, 21 Sep 2016 00:03:50 +0900 Subject: [PATCH 2/5] prefer %r over slash when containing escaped slash --- lib/sinatra/show_exceptions.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sinatra/show_exceptions.rb b/lib/sinatra/show_exceptions.rb index c0ed224f..ea7489b2 100644 --- a/lib/sinatra/show_exceptions.rb +++ b/lib/sinatra/show_exceptions.rb @@ -55,10 +55,10 @@ module Sinatra end def frame_class(frame) - if frame.filename =~ /lib\/sinatra.*\.rb/ + if frame.filename =~ %r{lib/sinatra.*\.rb} "framework" elsif (defined?(Gem) && frame.filename.include?(Gem.dir)) || - frame.filename =~ /\/bin\/(\w+)$/ + frame.filename =~ %r{/bin/(\w+)\z} "system" else "app" From 3d7b8fd5778009a235b12007ecbadf822aa2563a Mon Sep 17 00:00:00 2001 From: namusyaka Date: Wed, 21 Sep 2016 00:06:04 +0900 Subject: [PATCH 3/5] prefer to_proc syntax --- lib/sinatra/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 2fc5dbab..50c76f01 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -1916,7 +1916,7 @@ module Sinatra set :app_file, nil def self.register(*extensions, &block) #:nodoc: - added_methods = extensions.map {|m| m.public_instance_methods }.flatten + added_methods = extensions.map(&:public_instance_methods).flatten Delegator.delegate(*added_methods) super(*extensions, &block) end From 7608f7128f462d259d2d1ab317db343a6497cb25 Mon Sep 17 00:00:00 2001 From: namusyaka Date: Wed, 21 Sep 2016 00:18:03 +0900 Subject: [PATCH 4/5] fix indentation --- lib/sinatra/base.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 50c76f01..d37abd27 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -469,8 +469,8 @@ module Sinatra def cache_control(*values) if values.last.kind_of?(Hash) hash = values.pop - hash.reject! { |k,v| v == false } - hash.reject! { |k,v| values << k if v == true } + hash.reject! { |k, v| v == false } + hash.reject! { |k, v| values << k if v == true } else hash = {} end @@ -807,7 +807,7 @@ module Sinatra def render(engine, data, options = {}, locals = {}, &block) # merge app-level options - engine_options = settings.respond_to?(engine) ? settings.send(engine) : {} + engine_options = settings.respond_to?(engine) ? settings.send(engine) : {} options.merge!(engine_options) { |key, v1, v2| v1 } # extract generic options @@ -1207,7 +1207,7 @@ module Sinatra @extensions = [] if superclass.respond_to?(:templates) - @templates = Hash.new { |hash,key| superclass.templates[key] } + @templates = Hash.new { |hash, key| superclass.templates[key] } else @templates = {} end @@ -1639,8 +1639,8 @@ module Sinatra unbound_method = generate_method(method_name, &block) conditions, @conditions = @conditions, [] wrapper = block.arity != 0 ? - proc { |a,p| unbound_method.bind(a).call(*p) } : - proc { |a,p| unbound_method.bind(a).call } + proc { |a, p| unbound_method.bind(a).call(*p) } : + proc { |a, p| unbound_method.bind(a).call } [ pattern, conditions, wrapper ] end From 23c243d4babeeb362e2bea7650db88c18cbbc776 Mon Sep 17 00:00:00 2001 From: namusyaka Date: Thu, 29 Sep 2016 18:00:10 +0900 Subject: [PATCH 5/5] use Enumerable#flat_map if possible --- lib/sinatra/base.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index d37abd27..74260d50 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -1283,7 +1283,7 @@ module Sinatra # handled. def error(*codes, &block) args = compile! "ERROR", /.*/, block - codes = codes.map { |c| Array(c) }.flatten + codes = codes.flat_map(&method(:Array)) codes << Exception if codes.empty? codes << Sinatra::NotFound if codes.include?(404) codes.each { |c| (@errors[c] ||= []) << args } @@ -1916,7 +1916,7 @@ module Sinatra set :app_file, nil def self.register(*extensions, &block) #:nodoc: - added_methods = extensions.map(&:public_instance_methods).flatten + added_methods = extensions.flat_map(&:public_instance_methods) Delegator.delegate(*added_methods) super(*extensions, &block) end