Rubocop tweaks

This commit is contained in:
Thomas Reynolds 2015-04-26 11:13:29 -07:00
parent 4be3fcfd31
commit c87e2e026e
9 changed files with 22 additions and 26 deletions

View file

@ -31,7 +31,7 @@ HashSyntax:
EnforcedStyle: ruby19 EnforcedStyle: ruby19
SpaceAroundEqualsInParameterDefault: SpaceAroundEqualsInParameterDefault:
EnforcedStyle: no_space EnforcedStyle: no_space
Blocks: BlockDelimiters:
Enabled: false Enabled: false
PerlBackrefs: PerlBackrefs:
Enabled: false Enabled: false

View file

@ -75,7 +75,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
# Render through the Rack interface so middleware and mounted apps get a shot # Render through the Rack interface so middleware and mounted apps get a shot
response = @rack_client.get(URI.escape(resource.destination_path), response = @rack_client.get(URI.escape(resource.destination_path),
'bypass_inline_url_rewriter_asset_hash' => 'true' 'bypass_inline_url_rewriter_asset_hash' => 'true'
) )
raise "#{resource.path} should be in the sitemap!" unless response.status == 200 raise "#{resource.path} should be in the sitemap!" unless response.status == 200

View file

@ -152,8 +152,8 @@ class Middleman::Extensions::Lorem < ::Middleman::Extension
color = options[:color] color = options[:color]
if options[:random_color] if options[:random_color]
background_color = hex.shuffle[0...6].join background_color = hex.sample(6).join
color = hex.shuffle[0...6].join color = hex.sample(6).join
end end
src << "/#{background_color.sub(/^#/, '')}" if background_color src << "/#{background_color.sub(/^#/, '')}" if background_color

View file

@ -89,6 +89,7 @@ module Middleman
File.fnmatch(value, validator) File.fnmatch(value, validator)
else else
# If some unknown thing, don't ignore # If some unknown thing, don't ignore
false
end end
end end
end end

View file

@ -74,7 +74,7 @@ module Middleman
locals: md.delete(:locals) || {}, locals: md.delete(:locals) || {},
page: md.delete(:data) || {}, page: md.delete(:data) || {},
options: md options: md
) )
end end
end end
end end

View file

@ -63,7 +63,7 @@ module Middleman
url = ::Middleman::Util.url_for(@store.app, @request_path, url = ::Middleman::Util.url_for(@store.app, @request_path,
relative: false, relative: false,
find_resource: true find_resource: true
) )
if output if output
output.call(path, url) output.call(path, url)

View file

@ -14,6 +14,8 @@ module Middleman
extend Forwardable extend Forwardable
include Contracts include Contracts
Matcher = Or[Regexp, RespondTo[:call]]
# A reference to the current app. # A reference to the current app.
Contract IsA['Middleman::Application'] Contract IsA['Middleman::Application']
attr_reader :app attr_reader :app
@ -246,28 +248,24 @@ module Middleman
# Backwards compatible change handler. # Backwards compatible change handler.
# #
# @param [nil,Regexp] matcher A Regexp to match the change path against # @param [nil,Regexp] matcher A Regexp to match the change path against
# Contract Maybe[Regexp] => Any Contract Maybe[Matcher] => Any
def changed(matcher=nil, &block) def changed(matcher=nil, &block)
on_change :source do |updated, _removed| on_change :source do |updated, _removed|
updated.select { |f| updated
matcher.nil? ? true : matches?(matcher, f) .select { |f| matcher.nil? ? true : matches?(matcher, f) }
}.each do |f| .each { |f| block.call(f[:relative_path]) }
block.call(f[:relative_path])
end
end end
end end
# Backwards compatible delete handler. # Backwards compatible delete handler.
# #
# @param [nil,Regexp] matcher A Regexp to match the change path against # @param [nil,Regexp] matcher A Regexp to match the change path against
# Contract Maybe[Regexp] => Any Contract Maybe[Matcher] => Any
def deleted(matcher=nil, &block) def deleted(matcher=nil, &block)
on_change :source do |_updated, removed| on_change :source do |_updated, removed|
removed.select { |f| removed
matcher.nil? ? true : matches?(matcher, f) .select { |f| matcher.nil? ? true : matches?(matcher, f) }
}.each do |f| .each { |f| block.call(f[:relative_path]) }
block.call(f[:relative_path])
end
end end
end end
@ -287,7 +285,7 @@ module Middleman
# @param [Regexp, #call] validator The match validator. # @param [Regexp, #call] validator The match validator.
# @param [Middleman::SourceFile] file The file to check. # @param [Middleman::SourceFile] file The file to check.
# @return [Boolean] # @return [Boolean]
Contract Or[Regexp, RespondTo[:call]], SourceFile => Bool Contract Matcher, SourceFile => Bool
def matches?(validator, file) def matches?(validator, file)
path = file[:relative_path] path = file[:relative_path]
if validator.is_a? Regexp if validator.is_a? Regexp

View file

@ -252,7 +252,7 @@ module Middleman
Contract Pathname => Pathname Contract Pathname => Pathname
def strip_extensions(p) def strip_extensions(p)
p = p.sub_ext('') while ::Tilt[p.to_s] || p.extname === '.html' p = p.sub_ext('') while ::Tilt[p.to_s] || p.extname == '.html'
Pathname(p.to_s + '.*') Pathname(p.to_s + '.*')
end end
@ -262,9 +262,9 @@ module Middleman
# @return [Boolean] # @return [Boolean]
Contract IsA['Middleman::SourceFile'] => Bool Contract IsA['Middleman::SourceFile'] => Bool
def valid?(file) def valid?(file)
globally_valid = @validator.call(file) && !globally_ignored?(file) return false unless @validator.call(file) && !globally_ignored?(file)
globally_valid && if @only.empty? if @only.empty?
!@ignored.call(file) !@ignored.call(file)
else else
@only.any? { |reg| reg.match(file[:relative_path].to_s) } @only.any? { |reg| reg.match(file[:relative_path].to_s) }

View file

@ -87,13 +87,11 @@ module Middleman
end end
end end
def method_missing(key, *args) def method_missing(key, *_args)
if key?(key.to_sym) if key?(key.to_sym)
self[key.to_sym] self[key.to_sym]
elsif key?(key.to_s) elsif key?(key.to_s)
self[key.to_s] self[key.to_s]
else
super
end end
end end
end end
@ -131,7 +129,6 @@ module Middleman
end end
end end
# Normalize a path to not include a leading slash # Normalize a path to not include a leading slash
# @param [String] path # @param [String] path
# @return [String] # @return [String]