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

Make option name more meaningful

I just noticed a code review which suggested against the name
we are currently using and gave some good reasoning:

"Naming things "new" is always a problem (since time passes and
it's no longer new). Maybe colonize_symbol_keys? ("colonize"
sounds kind of gross though...)
https://git.io/vKIiX

The ruby19_syntax name was suggested later in the conversation.

As we have not yet released with the previous option name, it's
now or never for this change.
This commit is contained in:
Gerard Caulfield 2016-07-06 18:35:19 +10:00
parent 9ad80f0309
commit cf18904915
No known key found for this signature in database
GPG key ID: 623B327128A9BEC3
4 changed files with 25 additions and 25 deletions

View file

@ -33,15 +33,15 @@ ap object, options = {}
Default options: Default options:
```ruby ```ruby
indent: 4, # Number of spaces for indenting. indent: 4, # Number of spaces for indenting.
index: true, # Display array indices. index: true, # Display array indices.
html: false, # Use ANSI color codes rather than HTML. html: false, # Use ANSI color codes rather than HTML.
multiline: true, # Display in multiple lines. multiline: true, # Display in multiple lines.
plain: false, # Use colors. plain: false, # Use colors.
raw: false, # Do not recursively format instance variables. raw: false, # Do not recursively format instance variables.
sort_keys: false, # Do not sort hash keys. sort_keys: false, # Do not sort hash keys.
limit: false, # Limit arrays & hashes. Accepts bool or int. limit: false, # Limit arrays & hashes. Accepts bool or int.
new_hash_syntax: false, # Use Ruby 1.9 hash syntax in output. ruby19_syntax: false, # Use Ruby 1.9 hash syntax in output.
color: { color: {
args: :pale, args: :pale,
array: :white, array: :white,

View file

@ -28,10 +28,10 @@ module AwesomePrint
data = data.map do |key, value| data = data.map do |key, value|
indented do indented do
if options[:new_hash_syntax] && symbol?(key) if options[:ruby19_syntax] && symbol?(key)
new_hash_syntax(key, value, width) ruby19_syntax(key, value, width)
else else
old_hash_syntax(key, value, width) pre_ruby19_syntax(key, value, width)
end end
end end
end end
@ -50,12 +50,12 @@ module AwesomePrint
k.first == ':' k.first == ':'
end end
def new_hash_syntax(k, v, width) def ruby19_syntax(k, v, width)
k[0] = '' k[0] = ''
align(k, width - 1) << colorize(": ", :hash) << inspector.awesome(v) align(k, width - 1) << colorize(": ", :hash) << inspector.awesome(v)
end end
def old_hash_syntax(k, v, width) def pre_ruby19_syntax(k, v, width)
align(k, width) << colorize(" => ", :hash) << inspector.awesome(v) align(k, width) << colorize(" => ", :hash) << inspector.awesome(v)
end end

View file

@ -13,15 +13,15 @@ module AwesomePrint
def initialize(options = {}) def initialize(options = {})
@options = { @options = {
indent: 4, # Number of spaces for indenting. indent: 4, # Number of spaces for indenting.
index: true, # Display array indices. index: true, # Display array indices.
html: false, # Use ANSI color codes rather than HTML. html: false, # Use ANSI color codes rather than HTML.
multiline: true, # Display in multiple lines. multiline: true, # Display in multiple lines.
plain: false, # Use colors. plain: false, # Use colors.
raw: false, # Do not recursively format instance variables. raw: false, # Do not recursively format instance variables.
sort_keys: false, # Do not sort hash keys. sort_keys: false, # Do not sort hash keys.
limit: false, # Limit arrays & hashes. Accepts bool or int. limit: false, # Limit arrays & hashes. Accepts bool or int.
new_hash_syntax: false, # Use Ruby 1.9 hash syntax in output. ruby19_syntax: false, # Use Ruby 1.9 hash syntax in output.
color: { color: {
args: :pale, args: :pale,
array: :white, array: :white,

View file

@ -276,7 +276,7 @@ EOS
end end
it "new hash syntax" do it "new hash syntax" do
expect(@hash.ai(:plain => true, :new_hash_syntax => true)).to eq <<-EOS.strip expect(@hash.ai(:plain => true, :ruby19_syntax => true)).to eq <<-EOS.strip
{ {
1 => { 1 => {
sym: { sym: {
@ -328,7 +328,7 @@ EOS
end end
it "colored with new hash syntax" do it "colored with new hash syntax" do
expect(@hash.ai(:new_hash_syntax => true)).to eq <<-EOS.strip expect(@hash.ai(:ruby19_syntax => true)).to eq <<-EOS.strip
{ {
1\e[0;37m => \e[0m{ 1\e[0;37m => \e[0m{
sym\e[0;37m: \e[0m{ sym\e[0;37m: \e[0m{