1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Use assignments consistent with our style guide

This is so that people do not get warnings about problems in existing
code when we turn on Hound style checks.

---

If git-blame brought you here you may want to read this, the
problem is with git-blame, not this change.

Try running these two lines just once:
```
git config --global alias.praise 'log -p -M --follow --stat --'
git config --global alias.praise-line 'log -p -M --pretty=format:"%h (%an %ai)" -L'
```

Now in future you can use

`git praise <path/to/your/file>`

or if you want to see the evolution of a specific line or range of lines

`git praise-line <start-line>:<end-line>:<path/to/your/file>`

Some examples you should try:
```
git praise lib/awesome_print/version.rb
git praise-line 8:8:lib/awesome_print/version.rb
```

Inspiration for these aliases:

http://blog.andrewray.me/a-better-git-blame/
This commit is contained in:
Gerard Caulfield 2016-11-09 17:04:02 +11:00
parent abff97e812
commit a65ba3ff38
No known key found for this signature in database
GPG key ID: 623B327128A9BEC3
10 changed files with 56 additions and 35 deletions

View file

@ -73,10 +73,10 @@ module AwesomePrint
# Add in associations # Add in associations
if @options[:mongo_mapper][:show_associations] if @options[:mongo_mapper][:show_associations]
object.associations.each do |name, assoc| object.associations.each do |name, assoc|
if @options[:mongo_mapper][:inline_embedded] and assoc.embeddable? data[name.to_s] = if @options[:mongo_mapper][:inline_embedded] and assoc.embeddable?
data[name.to_s] = object.send(name) object.send(name)
else else
data[name.to_s] = assoc assoc
end end
end end
end end

View file

@ -44,7 +44,7 @@ module AwesomePrint
def awesome_self(object, type) def awesome_self(object, type)
if @options[:raw] && object.instance_variables.any? if @options[:raw] && object.instance_variables.any?
awesome_object(object) awesome_object(object)
elsif hash = convert_to_hash(object) elsif (hash = convert_to_hash(object))
awesome_hash(hash) awesome_hash(hash)
else else
awesome_simple(object.inspect.to_s, type, @inspector) awesome_simple(object.inspect.to_s, type, @inspector)

View file

@ -52,10 +52,10 @@ module AwesomePrint
# Add the proper elements to the temp array and format the separator. # Add the proper elements to the temp array and format the separator.
temp = data[0, head] + [nil] + data[-tail, tail] temp = data[0, head] + [nil] + data[-tail, tail]
if is_hash temp[head] = if is_hash
temp[head] = "#{indent}#{data[head].strip} .. #{data[data.length - tail - 1].strip}" "#{indent}#{data[head].strip} .. #{data[data.length - tail - 1].strip}"
else else
temp[head] = "#{indent}[#{head.to_s.rjust(width)}] .. [#{data.length - tail - 1}]" "#{indent}[#{head.to_s.rjust(width)}] .. [#{data.length - tail - 1}]"
end end
temp temp
@ -90,7 +90,8 @@ module AwesomePrint
# #<UnboundMethod: Hello#world> # #<UnboundMethod: Hello#world>
# #
if method.to_s =~ /(Unbound)*Method: (.*)[#\.]/ if method.to_s =~ /(Unbound)*Method: (.*)[#\.]/
unbound, klass = $1 && '(unbound)', $2 unbound = $1 && '(unbound)'
klass = $2
if klass && klass =~ /(\(\w+:\s.*?\))/ # Is this ActiveRecord-style class? if klass && klass =~ /(\(\w+:\s.*?\))/ # Is this ActiveRecord-style class?
klass.sub!($1, '') # Yes, strip the fields leaving class name only. klass.sub!($1, '') # Yes, strip the fields leaving class name only.
end end

View file

@ -13,7 +13,8 @@ module AwesomePrint
end end
def format def format
if superclass = klass.superclass # <-- Assign and test if nil. superclass = klass.superclass
if superclass
colorize("#{klass.inspect} < #{superclass}", :class) colorize("#{klass.inspect} < #{superclass}", :class)
else else
colorize(klass.inspect, :class) colorize(klass.inspect, :class)

View file

@ -60,11 +60,14 @@ module AwesomePrint
end end
def plain_single_line def plain_single_line
plain, multiline = options[:plain], options[:multiline] plain = options[:plain]
options[:plain], options[:multiline] = true, false multiline = options[:multiline]
options[:plain] = true
options[:multiline] = false
yield yield
ensure ensure
options[:plain], options[:multiline] = plain, multiline options[:plain] = plain
options[:multiline] = multiline
end end
end end
end end

View file

@ -64,7 +64,8 @@ module AwesomePrint
end end
def left_aligned def left_aligned
current, options[:indent] = options[:indent], 0 current = options[:indent]
options[:indent] = 0
yield yield
ensure ensure
options[:indent] = current options[:indent] = current

View file

@ -60,7 +60,8 @@ module AwesomePrint
end end
def left_aligned def left_aligned
current, options[:indent] = options[:indent], 0 current = options[:indent]
options[:indent] = 0
yield yield
ensure ensure
options[:indent] = current options[:indent] = current

View file

@ -32,7 +32,8 @@ RSpec.describe 'AwesomePrint' do
it "colorizes processes with ENV['ANSICON'] by default" do it "colorizes processes with ENV['ANSICON'] by default" do
begin begin
stub_tty! stub_tty!
term, ENV['ANSICON'] = ENV['ANSICON'], '1' term = ENV['ANSICON']
ENV['ANSICON'] = '1'
expect(@arr.ai(multiline: false)).to eq(COLORIZED) expect(@arr.ai(multiline: false)).to eq(COLORIZED)
ensure ensure
ENV['ANSICON'] = term ENV['ANSICON'] = term
@ -42,7 +43,8 @@ RSpec.describe 'AwesomePrint' do
it 'does not colorize tty processes running in dumb terminals by default' do it 'does not colorize tty processes running in dumb terminals by default' do
begin begin
stub_tty! stub_tty!
term, ENV['TERM'] = ENV['TERM'], 'dumb' term = ENV['TERM']
ENV['TERM'] = 'dumb'
expect(@arr.ai(multiline: false)).to eq(PLAIN) expect(@arr.ai(multiline: false)).to eq(PLAIN)
ensure ensure
ENV['TERM'] = term ENV['TERM'] = term
@ -72,7 +74,8 @@ RSpec.describe 'AwesomePrint' do
it "colorizes processes with ENV['ANSICON'] set to 0" do it "colorizes processes with ENV['ANSICON'] set to 0" do
begin begin
stub_tty! stub_tty!
term, ENV['ANSICON'] = ENV['ANSICON'], '1' term = ENV['ANSICON']
ENV['ANSICON'] = '1'
expect(@arr.ai(multiline: false)).to eq(COLORIZED) expect(@arr.ai(multiline: false)).to eq(COLORIZED)
ensure ensure
ENV['ANSICON'] = term ENV['ANSICON'] = term
@ -82,7 +85,8 @@ RSpec.describe 'AwesomePrint' do
it 'colorizes dumb terminals' do it 'colorizes dumb terminals' do
begin begin
stub_tty! stub_tty!
term, ENV['TERM'] = ENV['TERM'], 'dumb' term = ENV['TERM']
ENV['TERM'] = 'dumb'
expect(@arr.ai(multiline: false)).to eq(COLORIZED) expect(@arr.ai(multiline: false)).to eq(COLORIZED)
ensure ensure
ENV['TERM'] = term ENV['TERM'] = term

View file

@ -32,8 +32,8 @@ RSpec.describe 'AwesomePrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_map
out.gsub!(/#\<Proc:.+?\>/, 'AWESOME_PRINT_PROC_STUB') out.gsub!(/#\<Proc:.+?\>/, 'AWESOME_PRINT_PROC_STUB')
out.gsub!(/BSON::ObjectId\('[\da-f]+?'\)/, "BSON::ObjectId('123456789')") out.gsub!(/BSON::ObjectId\('[\da-f]+?'\)/, "BSON::ObjectId('123456789')")
if MongoMapper::Version >= '0.13' str = if MongoMapper::Version >= '0.13'
str = <<-EOS.strip <<-EOS.strip
#<MongoUser:placeholder_id #<MongoUser:placeholder_id
@__mm_default_keys = [ @__mm_default_keys = [
[0] #<MongoMapper::Plugins::Keys::Key:placeholder_id [0] #<MongoMapper::Plugins::Keys::Key:placeholder_id
@ -110,7 +110,7 @@ RSpec.describe 'AwesomePrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_map
> >
EOS EOS
else else
str = <<-EOS.strip <<-EOS.strip
#<MongoUser:placeholder_id #<MongoUser:placeholder_id
@_new = true, @_new = true,
attr_accessor :first_name = "Al", attr_accessor :first_name = "Al",

View file

@ -13,7 +13,9 @@ RSpec.describe 'Objects' do
attr_accessor :dabra attr_accessor :dabra
def initialize def initialize
@abra, @ca, @dabra = 1, 2, 3 @abra = 1
@ca = 2
@dabra = 3
end end
end end
@ -33,7 +35,9 @@ EOS
it 'instance variables' do it 'instance variables' do
class Hello class Hello
def initialize def initialize
@abra, @ca, @dabra = 1, 2, 3 @abra = 1
@ca = 2
@dabra = 3
end end
end end
@ -57,8 +61,12 @@ EOS
attr_accessor :dabra attr_accessor :dabra
def initialize def initialize
@abra, @ca, @dabra = 1, 2, 3 @abra = 1
@scooby, @dooby, @doo = 3, 2, 1 @ca = 2
@dabra = 3
@scooby = 3
@dooby = 2
@doo = 1
end end
end end
@ -84,7 +92,8 @@ EOS
attr_writer :ca attr_writer :ca
def initialize def initialize
@abra, @ca = 1, 2 @abra = 1
@ca = 2
@dabra = 3 @dabra = 3
end end
end end
@ -108,7 +117,8 @@ EOS
attr_writer :ca attr_writer :ca
def initialize def initialize
@abra, @ca = 1, 2 @abra = 1
@ca = 2
@dabra = 3 @dabra = 3
end end
end end