mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Add specific class for custom defaults
This commit is contained in:
parent
46ba51bd19
commit
f6a6927e11
2 changed files with 47 additions and 42 deletions
47
lib/awesome_print/custom_defaults.rb
Normal file
47
lib/awesome_print/custom_defaults.rb
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
module AwesomePrint
|
||||||
|
|
||||||
|
class << self
|
||||||
|
attr_accessor :defaults, :force_colors
|
||||||
|
|
||||||
|
# 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))
|
||||||
|
end
|
||||||
|
|
||||||
|
def rails_console?
|
||||||
|
console? && !!(defined?(Rails::Console) || ENV["RAILS_ENV"])
|
||||||
|
end
|
||||||
|
|
||||||
|
def diet_rb
|
||||||
|
IRB.formatter = Class.new(IRB::Formatter) do
|
||||||
|
def inspect_object(object)
|
||||||
|
object.ai
|
||||||
|
end
|
||||||
|
end.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def usual_rb
|
||||||
|
IRB::Irb.class_eval do
|
||||||
|
def output_value
|
||||||
|
ap @context.last_value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def irb!
|
||||||
|
return unless defined?(IRB)
|
||||||
|
|
||||||
|
IRB.version.include?("DietRB") ? diet_rb : usual_rb
|
||||||
|
end
|
||||||
|
|
||||||
|
def pry!
|
||||||
|
Pry.print = proc { |output, value| output.puts value.ai } if defined?(Pry)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -6,48 +6,6 @@
|
||||||
require_relative 'indentator'
|
require_relative 'indentator'
|
||||||
|
|
||||||
module AwesomePrint
|
module AwesomePrint
|
||||||
class << self # Class accessors for custom defaults.
|
|
||||||
attr_accessor :defaults, :force_colors
|
|
||||||
|
|
||||||
# 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))
|
|
||||||
end
|
|
||||||
|
|
||||||
def rails_console?
|
|
||||||
console? && !!(defined?(Rails::Console) || ENV['RAILS_ENV'])
|
|
||||||
end
|
|
||||||
|
|
||||||
def irb!
|
|
||||||
return unless defined?(IRB)
|
|
||||||
unless IRB.version.include?('DietRB')
|
|
||||||
IRB::Irb.class_eval do
|
|
||||||
def output_value
|
|
||||||
ap @context.last_value
|
|
||||||
rescue NoMethodError
|
|
||||||
puts "(Object doesn't support #ai)"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else # MacRuby
|
|
||||||
IRB.formatter = Class.new(IRB::Formatter) do
|
|
||||||
def inspect_object(object)
|
|
||||||
object.ai
|
|
||||||
end
|
|
||||||
end.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def pry!
|
|
||||||
Pry.print = proc { |output, value| output.puts value.ai } if defined?(Pry)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Inspector
|
class Inspector
|
||||||
attr_accessor :options, :indentator
|
attr_accessor :options, :indentator
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue