mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Fix some Rubocop/Codeclimate issues
This commit is contained in:
parent
83b0ca63e0
commit
b25b16484e
3 changed files with 86 additions and 67 deletions
58
README.md
58
README.md
|
@ -33,35 +33,35 @@ ap object, options = {}
|
|||
Default options:
|
||||
|
||||
```ruby
|
||||
:indent => 4, # Indent using 4 spaces.
|
||||
:index => true, # Display array indices.
|
||||
:html => false, # Use ANSI color codes rather than HTML.
|
||||
:multiline => true, # Display in multiple lines.
|
||||
:plain => false, # Use colors.
|
||||
:raw => false, # Do not recursively format object instance variables.
|
||||
:sort_keys => false, # Do not sort hash keys.
|
||||
:limit => false, # Limit large output for arrays and hashes. Set to a boolean or integer.
|
||||
:new_hash_syntax => false, # Use the JSON like syntax { foo: 'bar' }, when the key is a symbol
|
||||
:color => {
|
||||
:args => :pale,
|
||||
:array => :white,
|
||||
:bigdecimal => :blue,
|
||||
:class => :yellow,
|
||||
:date => :greenish,
|
||||
:falseclass => :red,
|
||||
:fixnum => :blue,
|
||||
:float => :blue,
|
||||
:hash => :pale,
|
||||
:keyword => :cyan,
|
||||
:method => :purpleish,
|
||||
:nilclass => :red,
|
||||
:rational => :blue,
|
||||
:string => :yellowish,
|
||||
:struct => :pale,
|
||||
:symbol => :cyanish,
|
||||
:time => :greenish,
|
||||
:trueclass => :green,
|
||||
:variable => :cyanish
|
||||
indent: 4, # Number of spaces for indenting.
|
||||
index: true, # Display array indices.
|
||||
html: false, # Use ANSI color codes rather than HTML.
|
||||
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.
|
||||
limit: false, # Limit arrays & hashes. Accepts bool or int.
|
||||
new_hash_syntax: false, # Use Ruby 1.9 hash syntax in output.
|
||||
color: {
|
||||
args: :pale,
|
||||
array: :white,
|
||||
bigdecimal: :blue,
|
||||
class: :yellow,
|
||||
date: :greenish,
|
||||
falseclass: :red,
|
||||
fixnum: :blue,
|
||||
float: :blue,
|
||||
hash: :pale,
|
||||
keyword: :cyan,
|
||||
method: :purpleish,
|
||||
nilclass: :red,
|
||||
rational: :blue,
|
||||
string: :yellowish,
|
||||
struct: :pale,
|
||||
symbol: :cyanish,
|
||||
time: :greenish,
|
||||
trueclass: :green,
|
||||
variable: :cyanish
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -4,17 +4,17 @@ module AwesomePrint
|
|||
|
||||
# Class accessor to force colorized output (ex. forked subprocess where TERM
|
||||
# might be dumb).
|
||||
#------------------------------------------------------------------------------
|
||||
#---------------------------------------------------------------------------
|
||||
def force_colors!(value = true)
|
||||
@force_colors = value
|
||||
end
|
||||
|
||||
def console?
|
||||
!!(defined?(IRB) || defined?(Pry))
|
||||
boolean(defined?(IRB) || defined?(Pry))
|
||||
end
|
||||
|
||||
def rails_console?
|
||||
console? && !!(defined?(Rails::Console) || ENV["RAILS_ENV"])
|
||||
console? && boolean(defined?(Rails::Console) || ENV['RAILS_ENV'])
|
||||
end
|
||||
|
||||
def diet_rb
|
||||
|
@ -38,11 +38,20 @@ module AwesomePrint
|
|||
def irb!
|
||||
return unless defined?(IRB)
|
||||
|
||||
IRB.version.include?("DietRB") ? diet_rb : usual_rb
|
||||
IRB.version.include?('DietRB') ? diet_rb : usual_rb
|
||||
end
|
||||
|
||||
def pry!
|
||||
Pry.print = proc { |output, value| output.puts value.ai } if defined?(Pry)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Takes a value and returns true unless it is false or nil
|
||||
# This is an alternative to the less readable !!(value)
|
||||
# https://github.com/bbatsov/ruby-style-guide#no-bang-bang
|
||||
def boolean(value)
|
||||
value ? true : false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,35 +13,35 @@ module AwesomePrint
|
|||
|
||||
def initialize(options = {})
|
||||
@options = {
|
||||
:indent => 4, # Indent using 4 spaces.
|
||||
:index => true, # Display array indices.
|
||||
:html => false, # Use ANSI color codes rather than HTML.
|
||||
:multiline => true, # Display in multiple lines.
|
||||
:plain => false, # Use colors.
|
||||
:raw => false, # Do not recursively format object instance variables.
|
||||
:sort_keys => false, # Do not sort hash keys.
|
||||
:limit => false, # Limit large output for arrays and hashes. Set to a boolean or integer.
|
||||
:new_hash_syntax => false, # Use the JSON like syntax { foo: 'bar' }, when the key is a symbol
|
||||
:color => {
|
||||
:args => :pale,
|
||||
:array => :white,
|
||||
:bigdecimal => :blue,
|
||||
:class => :yellow,
|
||||
:date => :greenish,
|
||||
:falseclass => :red,
|
||||
:fixnum => :blue,
|
||||
:float => :blue,
|
||||
:hash => :pale,
|
||||
:keyword => :cyan,
|
||||
:method => :purpleish,
|
||||
:nilclass => :red,
|
||||
:rational => :blue,
|
||||
:string => :yellowish,
|
||||
:struct => :pale,
|
||||
:symbol => :cyanish,
|
||||
:time => :greenish,
|
||||
:trueclass => :green,
|
||||
:variable => :cyanish
|
||||
indent: 4, # Number of spaces for indenting.
|
||||
index: true, # Display array indices.
|
||||
html: false, # Use ANSI color codes rather than HTML.
|
||||
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.
|
||||
limit: false, # Limit arrays & hashes. Accepts bool or int.
|
||||
new_hash_syntax: false, # Use Ruby 1.9 hash syntax in output.
|
||||
color: {
|
||||
args: :pale,
|
||||
array: :white,
|
||||
bigdecimal: :blue,
|
||||
class: :yellow,
|
||||
date: :greenish,
|
||||
falseclass: :red,
|
||||
fixnum: :blue,
|
||||
float: :blue,
|
||||
hash: :pale,
|
||||
keyword: :cyan,
|
||||
method: :purpleish,
|
||||
nilclass: :red,
|
||||
rational: :blue,
|
||||
string: :yellowish,
|
||||
struct: :pale,
|
||||
symbol: :cyanish,
|
||||
time: :greenish,
|
||||
trueclass: :green,
|
||||
variable: :cyanish
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,15 @@ module AwesomePrint
|
|||
#---------------------------------------------------------------------------
|
||||
def colorize?
|
||||
AwesomePrint.force_colors ||= false
|
||||
AwesomePrint.force_colors || (STDOUT.tty? && ((ENV['TERM'] && ENV['TERM'] != 'dumb') || ENV['ANSICON']))
|
||||
AwesomePrint.force_colors || (
|
||||
STDOUT.tty? && (
|
||||
(
|
||||
ENV['TERM'] &&
|
||||
ENV['TERM'] != 'dumb'
|
||||
) ||
|
||||
ENV['ANSICON']
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -106,8 +114,9 @@ module AwesomePrint
|
|||
@formatter.format(object, printable(object))
|
||||
end
|
||||
|
||||
# Turn class name into symbol, ex: Hello::World => :hello_world. Classes that
|
||||
# inherit from Array, Hash, File, Dir, and Struct are treated as the base class.
|
||||
# Turn class name into symbol, ex: Hello::World => :hello_world. Classes
|
||||
# that inherit from Array, Hash, File, Dir, and Struct are treated as the
|
||||
# base class.
|
||||
#---------------------------------------------------------------------------
|
||||
def printable(object)
|
||||
case object
|
||||
|
@ -120,7 +129,8 @@ module AwesomePrint
|
|||
end
|
||||
end
|
||||
|
||||
# Update @options by first merging the :color hash and then the remaining keys.
|
||||
# Update @options by first merging the :color hash and then the remaining
|
||||
# keys.
|
||||
#---------------------------------------------------------------------------
|
||||
def merge_options!(options = {})
|
||||
@options[:color].merge!(options.delete(:color) || {})
|
||||
|
|
Loading…
Reference in a new issue