mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Merge pull request #295 from aars/option-sort-instance-variables
sort_vars option
This commit is contained in:
commit
3e2a31fe4d
4 changed files with 39 additions and 1 deletions
|
@ -40,6 +40,7 @@ multiline: true, # Display in multiple lines.
|
|||
plain: false, # Use colors.
|
||||
raw: false, # Do not recursively format instance variables.
|
||||
sort_keys: false, # Do not sort hash keys.
|
||||
sort_vars: true, # Sort instance variables.
|
||||
limit: false, # Limit arrays & hashes. Accepts bool or int.
|
||||
ruby19_syntax: false, # Use Ruby 1.9 hash syntax in output.
|
||||
color: {
|
||||
|
|
|
@ -28,7 +28,7 @@ module AwesomePrint
|
|||
end
|
||||
end
|
||||
|
||||
data = vars.sort.map do |declaration, var|
|
||||
data = (options[:sort_vars] ? vars.sort : vars).map do |declaration, var|
|
||||
key = left_aligned do
|
||||
align(declaration, declaration.size)
|
||||
end
|
||||
|
|
|
@ -20,6 +20,7 @@ module AwesomePrint
|
|||
plain: false, # Use colors.
|
||||
raw: false, # Do not recursively format instance variables.
|
||||
sort_keys: false, # Do not sort hash keys.
|
||||
sort_vars: true, # Sort instance variables.
|
||||
limit: false, # Limit arrays & hashes. Accepts bool or int.
|
||||
ruby19_syntax: false, # Use Ruby 1.9 hash syntax in output.
|
||||
color: {
|
||||
|
|
|
@ -127,6 +127,42 @@ EOS
|
|||
out = hello.ai(multiline: false, plain: true, raw: true)
|
||||
str = <<-EOS.strip
|
||||
#<Hello:placeholder_id @dabra = 3, attr_reader :abra = 1, attr_writer :ca = 2>
|
||||
EOS
|
||||
expect(out).to be_similar_to(str)
|
||||
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
||||
end
|
||||
|
||||
it 'without the sort_vars option does not sort instance variables' do
|
||||
class Hello
|
||||
attr_reader :abra
|
||||
attr_writer :ca
|
||||
attr_accessor :dabra
|
||||
|
||||
def initialize
|
||||
@abra = 1
|
||||
@ca = 2
|
||||
@dabra = 3
|
||||
@scooby = 3
|
||||
@dooby = 2
|
||||
@doo = 1
|
||||
end
|
||||
|
||||
def instance_variables
|
||||
[:@scooby, :@dooby, :@doo, :@abra, :@ca, :@dabra]
|
||||
end
|
||||
end
|
||||
|
||||
hello = Hello.new
|
||||
out = hello.ai(plain: true, raw: true, sort_vars: false)
|
||||
str = <<-EOS.strip
|
||||
#<Hello:placeholder_id
|
||||
@scooby = 3,
|
||||
@dooby = 2,
|
||||
@doo = 1,
|
||||
attr_reader :abra = 1,
|
||||
attr_writer :ca = 2,
|
||||
attr_accessor :dabra = 3
|
||||
>
|
||||
EOS
|
||||
expect(out).to be_similar_to(str)
|
||||
expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect)
|
||||
|
|
Loading…
Reference in a new issue