Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
engines:
version: 2
plugins:
duplication:
enabled: true
config:
Expand All @@ -9,8 +10,5 @@ engines:
enabled: true
rubocop:
enabled: true
ratings:
paths:
- "**.rb"
exclude_paths:
exclude_patterns:
- spec/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Gemfile.lock
/tmp
/.bundle
/gemfiles/.bundle
/gemfiles/vendor/bundle

## PROJECT::RVM
.rvmrc
Expand Down
19 changes: 13 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
language: ruby
cache: bundler
os: linux
dist: xenial

rvm:
- 2.3
- 2.4
- 2.5
- 2.6
- 2.7
- ruby-head


before_install:
- gem install bundler

gemfile:
# ignore 4.2 for now as the cost to run these tests is too high
# - gemfiles/rails_4.2.gemfile
- gemfiles/rails_5.0.gemfile
- gemfiles/rails_5.1.gemfile
- gemfiles/rails_5.2.gemfile
- gemfiles/mongoid_4.0.gemfile
- gemfiles/rails_6.0.gemfile
- gemfiles/rails_6.1.gemfile
- gemfiles/mongoid_5.0.gemfile
- gemfiles/mongoid_6.0.gemfile
- gemfiles/mongoid_7.0.gemfile
- gemfiles/mongoid_7.1.gemfile

matrix:
jobs:
allow_failures:
- rvm: 2.7
- rvm: ruby-head
include:
- rvm: 2.6
env: RUBYOPT="--enable-frozen-string-literal"
Expand Down
17 changes: 15 additions & 2 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,31 @@ appraise 'rails-5.2' do
gem 'rails', '>= 5.2.0', '< 5.3'
end

appraise 'mongoid-4.0' do
gem 'mongoid', '~> 4.0.0'
appraise 'rails-6.0' do
gem 'rails', '>= 6.0.0', '< 6.1'
end

appraise 'rails-6.1' do
gem 'rails', '>= 6.1.0', '< 6.2'
end

appraise 'mongoid-5.0' do
gem 'mongoid', '~> 5.0.0'
gem 'bigdecimal', '~> 1.3.5'
end

appraise 'mongoid-6.0' do
gem 'mongoid', '~> 6.0.0'
end

appraise 'mongoid-7.0' do
gem 'mongoid', '~> 7.0.0'
end

appraise 'mongoid-7.1' do
gem 'mongoid', '~> 7.1.0'
end

# appraise 'mongo_mapper' do
# gem 'mongo_mapper'
# end
Expand Down
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
## master (unreleased)


## 1.9.2
- Tests work with Ruby 2.6.6, 2.7.2 and 3.0.0
- Update awsome_print.gemspec nokogiri dependency to resolve CVEs [@gvwirth]

## 1.9.1
- Updated code so it can be released to rubygems.
- Updated nokogiri to resolve vulnerability scan

## 1.9.0
- Update method signature after change in IRB [@febeling]
- Fixes block and proc definition to work with Ruby 3.0.0 [@csalvato] - [#392]
- Removed check for Ruby 2.4 and earlier [@bryanh]
- Rails 5.0 builds are failing, because the sqlite3 version being installed is wrong version [#366]
- Fixes spec suite to properly work via travis, gets a clean build [@imajes, others]
- Adds support for ActiveModel::Errors [@dshinzie] - [#301]
- removes use of `strip_heredoc` from specs as it's a rails dep [@kstephens] - [#303]
Expand All @@ -8,7 +23,7 @@
- stat("$HOME/.aprc") once [@kstephens] - [#304]
- ActiveRecord: #joins now show the columns #select'ed [@adrianomitre] - [#211]
- Handles NoMethodError for IRB implicit `ai` [@jtnegrotto] - [#212]
- Replaced Fixnum reference with Integer
- Replaced Fixnum reference with Integer
- Colorize ORM class names [@ixti]

## 1.7.0
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Special thanks goes to awesome team of contributors, namely:
* Barry Allard -- https://github.com/steakknife
* Benoit Daloze -- http://github.com/eregon
* Brandon Zylstra -- https://github.com/brandondrew
* Bryan Hanks, PMP -- https://github.com/bryanh
* Dan Lynn -- https://github.com/danlynn
* Daniel Johnson -- https://github.com/adhd360
* Daniel Bretoi -- http://github.com/danielb2
Expand Down
50 changes: 42 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ Awesome Print is a Ruby library that pretty prints Ruby objects in full color
exposing their internal structure with proper indentation. Rails ActiveRecord
objects and usage within Rails templates are supported via included mixins.

__NOTE__: awesome_print v1.2.0 is the last release supporting Ruby versions
prior to v1.9.3 and Rails versions prior to v3.0. The upcoming awesome_print
v2.0 will *require* Ruby v1.9.3 or later and Rails v3.0 or later.
__NOTE__: awesome_print v1.9.0 may not work on Ruby versions 2.4 or older or Rails versions 4.2 or older.
The upcoming awesome_print v2.0 will *require* Ruby v1.9.3 or later and Rails v3.0 or later.

### Installation ###
# Installing as Ruby gem
Expand Down Expand Up @@ -84,6 +83,8 @@ irb> "awesome print".ai

### Examples ###

#### Array

```ruby
$ cat > 1.rb
require "awesome_print"
Expand All @@ -104,7 +105,10 @@ $ ruby 1.rb
:distance => 4.2e+43
}
]
```
#### Hash

```ruby
$ cat > 2.rb
require "awesome_print"
data = { :now => Time.now, :class => Time.now.class, :distance => 42e42 }
Expand All @@ -116,7 +120,11 @@ $ ruby 2.rb
:now => Fri Apr 02 19:55:53 -0700 2010,
:distance => 4.2e+43
}
```

#### Nested array

```ruby
$ cat > 3.rb
require "awesome_print"
data = [ false, 42, %w(forty two) ]
Expand All @@ -126,6 +134,11 @@ ap data, :multiline => false
$ ruby 3.rb
[ false, 42, [ "forty", "two" ], [...] ]

```

#### Class methods

```ruby
$ cat > 4.rb
require "awesome_print"
class Hello
Expand All @@ -139,6 +152,11 @@ $ ruby 4.rb
[0] world(x, y, *z, &blk) Hello
]

```

#### Object methods

```ruby
$ cat > 5.rb
require "awesome_print"
ap (''.methods - Object.methods).grep(/!/)
Expand Down Expand Up @@ -167,14 +185,25 @@ $ ruby 5.rb
[19] upcase!() String
]

```

#### Compare output to value

```ruby
$ cat > 6.rb
require "awesome_print"
ap 42 == ap(42)
^D
$ ruby 6.rb
42
true
$ cat 7.rb

```

#### Array with default output limit

```ruby
$ cat > 7.rb
require "awesome_print"
some_array = (1..1000).to_a
ap some_array, :limit => true
Expand All @@ -189,8 +218,12 @@ $ ruby 7.rb
[998] 999,
[999] 1000
]
```

$ cat 8.rb
#### Array with specific output limit

```ruby
$ cat > 8.rb
require "awesome_print"
some_array = (1..1000).to_a
ap some_array, :limit => 5
Expand All @@ -205,7 +238,7 @@ $ ruby 8.rb
]
```

### Example (Rails console) ###
#### Rails console
```ruby
$ rails console
rails> require "awesome_print"
Expand Down Expand Up @@ -275,7 +308,8 @@ AwesomePrint.irb!

### PRY integration ###
If you miss awesome_print's way of formatting output, here's how you can use it in place
of the formatting which comes with pry. Add the following code to your ~/.pryrc:
of the formatting which comes with pry. Add the following code to your `~/.pryrc`
or your project's `./.pryrc`:

```ruby
require "awesome_print"
Expand Down Expand Up @@ -307,7 +341,7 @@ With other web frameworks (ex: in Sinatra templates) you can explicitly request
formatting:

<%= ap @accounts.first, :html => true %>

### String Convenience Methods ###
Use methods such as `.red` to set string color:

Expand Down
2 changes: 1 addition & 1 deletion awesome_print.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'appraisal'
s.add_development_dependency 'fakefs', '>= 0.2.1'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'nokogiri', '>= 1.6.5'
s.add_development_dependency 'nokogiri', '>= 1.11.0'
# s.add_development_dependency 'simplecov'
# s.add_development_dependency 'codeclimate-test-reporter'
end
1 change: 1 addition & 0 deletions gemfiles/mongoid_5.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
source "https://rubygems.org"

gem "mongoid", "~> 5.0.0"
gem "bigdecimal", "~> 1.3.5"

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

source "https://rubygems.org"

gem "mongoid", "~> 4.0.0"
gem "mongoid", "~> 7.0.0"

gemspec path: "../"
3 changes: 1 addition & 2 deletions gemfiles/rails_4.2.gemfile → gemfiles/mongoid_7.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

source "https://rubygems.org"

gem "rails", "~> 4.2.0"
gem "mime-types", "2.6.2", platforms: :ruby_19
gem "mongoid", "~> 7.1.0"

gemspec path: "../"
7 changes: 7 additions & 0 deletions gemfiles/rails_6.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", ">= 6.0.0", "< 6.1"

gemspec path: "../"
7 changes: 7 additions & 0 deletions gemfiles/rails_6.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", ">= 6.1.0", "< 6.2"

gemspec path: "../"
2 changes: 1 addition & 1 deletion lib/awesome_print/custom_defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def inspect_object(object)

def usual_rb
IRB::Irb.class_eval do
def output_value
def output_value(*args)
ap @context.last_value
rescue NoMethodError
puts "(Object doesn't support #ai)"
Expand Down
34 changes: 23 additions & 11 deletions lib/awesome_print/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,33 @@ def awesome_dir(d)

# Utility methods.
#------------------------------------------------------------------------------

# A class (ex. `Net::HTTP.Get`) might have `attr_reader :method` accessor
# which causes `object.method(:to_hash)` throw `ArgumentError (wrong number
# of arguments (given 1, expected 0))`. The following tries to avoid that.
def has_method_accessor?(object)
!object.method(:method)
rescue ArgumentError
true
end

def convert_to_hash(object)
if !object.respond_to?(:to_hash)
return nil
end
return nil if has_method_accessor?(object)
return nil if !object.respond_to?(:to_hash) || object.method(:to_hash).arity != 0

if object.method(:to_hash).arity != 0
return nil
end
# ActionController::Parameters will raise if they are not yet permitted
# and we try to convert to hash.
# https://api.rubyonrails.org/classes/ActionController/Parameters.html
return nil if object.respond_to?(:permitted?) && !object.permitted?

hash = object.to_hash
if !hash.respond_to?(:keys) || !hash.respond_to?('[]')
return nil
end
begin
hash = object.to_hash
return nil if !hash.respond_to?(:keys) || !hash.respond_to?(:[])

return hash
hash
rescue
return { class: object.class.name, contents: object.inspect }
end
end
end
end
6 changes: 3 additions & 3 deletions lib/awesome_print/formatters/base_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def method_tuple(method)
# #<Method: User(id: integer, username: string)(ActiveRecord::Base).current>
# #<UnboundMethod: Hello#world>
#
if method.to_s =~ /(Unbound)*Method: (.*)[#\.]/
if method.to_s =~ /(Unbound)*Method: (.*?)[#\.]/
unbound = $1 && '(unbound)'
klass = $2
if klass && klass =~ /(\(\w+:\s.*?\))/ # Is this ActiveRecord-style class?
Expand All @@ -109,8 +109,8 @@ def indentation
inspector.current_indentation
end

def indented
inspector.increase_indentation(&Proc.new)
def indented(&block)
inspector.increase_indentation(&block)
end

def indent
Expand Down
Loading