Skip to content

Commit

Permalink
Merge pull request Homebrew#1123 from reitermarkus/rubocop
Browse files Browse the repository at this point in the history
RuboCop: Style/AccessorMethodName
  • Loading branch information
MikeMcQuaid authored Sep 24, 2016
2 parents 1e6e2d7 + 6c6a4c9 commit 232078d
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 45 deletions.
10 changes: 0 additions & 10 deletions Library/.rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,6 @@ Metrics/ModuleLength:
Metrics/ParameterLists:
Max: 6

# Offense count: 8
Style/AccessorMethodName:
Exclude:
- 'Homebrew/download_strategy.rb'
- 'Homebrew/extend/ENV/std.rb'
- 'Homebrew/formula.rb'
- 'Homebrew/formula_lock.rb'
- 'Homebrew/formulary.rb'
- 'Homebrew/migrator.rb'

# Offense count: 1
Style/CaseEquality:
Exclude:
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/bump-formula-pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
module Homebrew
def inreplace_pairs(path, replacement_pairs)
if ARGV.dry_run?
contents = path.open("r") { |f| Formulary.set_encoding(f).read }
contents = path.open("r") { |f| Formulary.ensure_utf8_encoding(f).read }
contents.extend(StringInreplaceExtension)
replacement_pairs.each do |old, new|
unless ARGV.flag?("--quiet")
Expand All @@ -48,7 +48,7 @@ def inreplace_pairs(path, replacement_pairs)
s.gsub!(old, new)
end
end
path.open("r") { |f| Formulary.set_encoding(f).read }
path.open("r") { |f| Formulary.ensure_utf8_encoding(f).read }
end
end

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def repo_url
Utils.popen_read("svn", "info", cached_location.to_s).strip[/^URL: (.+)$/, 1]
end

def get_externals
def externals
Utils.popen_read("svn", "propget", "svn:externals", @url).chomp.each_line do |line|
name, url = line.split(/\s+/)
yield name, url
Expand Down Expand Up @@ -600,7 +600,7 @@ def clone_repo
main_revision = @ref[:trunk]
fetch_repo cached_location, @url, main_revision, true

get_externals do |external_name, external_url|
externals do |external_name, external_url|
fetch_repo cached_location+external_name, external_url, @ref[external_name], true
end
else
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/ARGV.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def resolved_formulae
if f.any_version_installed?
tab = Tab.for_formula(f)
resolved_spec = spec(nil) || tab.spec
f.set_active_spec(resolved_spec) if f.send(resolved_spec)
f.active_spec = resolved_spec if f.send(resolved_spec)
f.build = tab
if f.head? && tab.tabfile
k = Keg.new(tab.tabfile.parent)
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/extend/ENV/std.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def setup_build_environment(formula = nil)
end

# Os is the default Apple uses for all its stuff so let's trust them
set_cflags "-Os #{SAFE_CFLAGS_FLAGS}"
define_cflags "-Os #{SAFE_CFLAGS_FLAGS}"

append "LDFLAGS", "-Wl,-headerpad_max_install_names"

Expand Down Expand Up @@ -136,12 +136,12 @@ def clang
end

def minimal_optimization
set_cflags "-Os #{SAFE_CFLAGS_FLAGS}"
define_cflags "-Os #{SAFE_CFLAGS_FLAGS}"
end
alias generic_minimal_optimization minimal_optimization

def no_optimization
set_cflags SAFE_CFLAGS_FLAGS
define_cflags SAFE_CFLAGS_FLAGS
end
alias generic_no_optimization no_optimization

Expand Down Expand Up @@ -206,7 +206,7 @@ def replace_in_cflags(before, after)
end

# Convenience method to set all C compiler flags in one shot.
def set_cflags(val)
def define_cflags(val)
CC_FLAG_VARS.each { |key| self[key] = val }
end

Expand Down
18 changes: 9 additions & 9 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ def initialize(name, path, spec, alias_path: nil)
Tap.fetch($1, $2)
end

@full_name = get_full_name(name)
@full_alias_name = get_full_name(@alias_name)
@full_name = full_name_with_optional_tap(name)
@full_alias_name = full_name_with_optional_tap(@alias_name)

set_spec :stable
set_spec :devel
set_spec :head
spec_eval :stable
spec_eval :devel
spec_eval :head

@active_spec = determine_active_spec(spec)
@active_spec_sym = if head?
Expand All @@ -201,7 +201,7 @@ def initialize(name, path, spec, alias_path: nil)
end

# @private
def set_active_spec(spec_sym)
def active_spec=(spec_sym)
spec = send(spec_sym)
raise FormulaSpecificationError, "#{spec_sym} spec is not available for #{full_name}" unless spec
@active_spec = spec
Expand All @@ -214,15 +214,15 @@ def set_active_spec(spec_sym)

# Allow full name logic to be re-used between names, aliases,
# and installed aliases.
def get_full_name(name)
def full_name_with_optional_tap(name)
if name.nil? || @tap.nil? || @tap.core_tap?
name
else
"#{@tap}/#{name}"
end
end

def set_spec(name)
def spec_eval(name)
spec = self.class.send(name)
return unless spec.url
spec.owner = self
Expand Down Expand Up @@ -264,7 +264,7 @@ def installed_alias_name
end

def full_installed_alias_name
get_full_name(installed_alias_name)
full_name_with_optional_tap(installed_alias_name)
end

# The path that was specified to find this formula.
Expand Down
15 changes: 6 additions & 9 deletions Library/Homebrew/formula_lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def initialize(name)
end

def lock
HOMEBREW_LOCK_DIR.mkpath
@lockfile = get_or_create_lockfile
@path.parent.mkpath
create_lockfile
return if @lockfile.flock(File::LOCK_EX | File::LOCK_NB)
raise OperationInProgressError, @name
end
Expand All @@ -29,12 +29,9 @@ def with_lock

private

def get_or_create_lockfile
if @lockfile.nil? || @lockfile.closed?
@lockfile = @path.open(File::RDWR | File::CREAT)
@lockfile.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
end

@lockfile
def create_lockfile
return unless @lockfile.nil? || @lockfile.closed?
@lockfile = @path.open(File::RDWR | File::CREAT)
@lockfile.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
end
end
6 changes: 3 additions & 3 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ def self.load_formula(name, path, contents, namespace)
end

def self.load_formula_from_path(name, path)
contents = path.open("r") { |f| set_encoding(f).read }
contents = path.open("r") { |f| ensure_utf8_encoding(f).read }
namespace = "FormulaNamespace#{Digest::MD5.hexdigest(path.to_s)}"
klass = load_formula(name, path, contents, namespace)
FORMULAE[path] = klass
end

if IO.method_defined?(:set_encoding)
def self.set_encoding(io)
def self.ensure_utf8_encoding(io)
io.set_encoding(Encoding::UTF_8)
end
else
def self.set_encoding(io)
def self.ensure_utf8_encoding(io)
io
end
end
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def initialize(formula)

@new_cellar = HOMEBREW_CELLAR/formula.name

if @old_linked_keg = get_linked_old_linked_keg
if @old_linked_keg = linked_old_linked_keg
@old_linked_keg_record = old_linked_keg.linked_keg_record if old_linked_keg.linked?
@old_opt_record = old_linked_keg.opt_record if old_linked_keg.optlinked?
@new_linked_keg_record = HOMEBREW_CELLAR/"#{newname}/#{File.basename(old_linked_keg)}"
Expand Down Expand Up @@ -137,7 +137,7 @@ def from_same_taps?
end
end

def get_linked_old_linked_keg
def linked_old_linked_keg
kegs = old_cellar.subdirs.map { |d| Keg.new(d) }
kegs.detect(&:linked?) || kegs.detect(&:optlinked?)
end
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/test/test_formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def test_formula_spec_integration
assert_version_equal "HEAD", f.head.version
end

def test_formula_set_active_spec
def test_formula_active_spec=
f = formula do
url "foo"
version "1.0"
Expand All @@ -481,11 +481,11 @@ def test_formula_set_active_spec
assert_equal :stable, f.active_spec_sym
assert_equal f.stable, f.send(:active_spec)
assert_equal "1.0_1", f.pkg_version.to_s
f.set_active_spec(:devel)
f.active_spec = :devel
assert_equal :devel, f.active_spec_sym
assert_equal f.devel, f.send(:active_spec)
assert_equal "1.0beta_1", f.pkg_version.to_s
assert_raises(FormulaSpecificationError) { f.set_active_spec(:head) }
assert_raises(FormulaSpecificationError) { f.active_spec = :head }
end

def test_path
Expand Down

0 comments on commit 232078d

Please sign in to comment.