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:
parent
abff97e812
commit
a65ba3ff38
10 changed files with 56 additions and 35 deletions
|
@ -73,11 +73,11 @@ 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
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -52,11 +52,11 @@ 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
|
||||||
end
|
end
|
||||||
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
@ -108,9 +108,9 @@ RSpec.describe 'AwesomePrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_map
|
||||||
"last_name" => nil
|
"last_name" => nil
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
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",
|
||||||
|
@ -122,8 +122,8 @@ RSpec.describe 'AwesomePrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_map
|
||||||
attr_reader :first_name_before_type_cast = "Al",
|
attr_reader :first_name_before_type_cast = "Al",
|
||||||
attr_reader :last_name_before_type_cast = "Capone"
|
attr_reader :last_name_before_type_cast = "Capone"
|
||||||
>
|
>
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
expect(out).to be_similar_to(str)
|
expect(out).to be_similar_to(str)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue