Skip to content

Commit 1f135e6

Browse files
committed
Updates to .pryrc
1 parent 8158b08 commit 1f135e6

1 file changed

Lines changed: 74 additions & 35 deletions

File tree

.pryrc

Lines changed: 74 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,67 @@
1-
#require 'awesome_print' # Removing because bad colors and can't configure
2-
#AwesomePrint.pry!
1+
# =============================================================================
2+
# Setup
3+
# =============================================================================
34

5+
# Disabe paging in pry, to avoid having to keep hitting j/space on big output
6+
# on small screens
7+
Pry.config.pager = false
48

5-
url = 'https://vonk.fire.ly'
6-
if defined? GrFhir
7-
client = GrFhir::Client.build(url)
8-
else
9-
client = Gr::Fhir::Client.build(url)
9+
# -----------------------------------------------------------------------------
10+
# Rails app spits out lots of startup garbage, separate this
11+
def notice_me(msg)
12+
puts '*' * 100
13+
puts "❌ #{msg}"
14+
puts
1015
end
11-
puts "Client ready at #{url}"
1216

17+
# -----------------------------------------------------------------------------
18+
# Required for all the other functions: The 'colorize' gem, which lets you
19+
# colorize text output to the console. Since it's not in the Jarvis Gemfile,
20+
# we have to go find it manually. To find yours, do something like `bundle show # httparty`,
21+
# get the base gems/ path, and find colorize in there
1322
begin
14-
require 'colorize'
15-
puts "#{'require'.light_red} #{"'colorize'".cyan}"
16-
rescue StandardError
17-
puts "Warning: colorize gem not found"
23+
colorize_init_file = "#{Dir.home}/.gem/ruby/2.5.1/gems/colorize-0.8.1/lib/colorize.rb"
24+
require colorize_init_file
25+
puts "✅ #{'require'.light_red} #{"'colorize'".cyan}"
26+
rescue Exception => ex # Did you know LoadError inherits from Exception, not StandardError?
27+
notice_me "Warning: colorize gem not found, make sure you:\n - Installed colorize locally (gem install colorize)\n - This path exists: #{colorize_init_file}\n#{ex.message}"
1828
end
1929

30+
# -----------------------------------------------------------------------------
31+
# Enables FactoryBot in a pry session
2032
begin
2133
require 'factory_bot_rails'
22-
puts "#{'require'.light_red} #{"'factory_bot_rails'".cyan}"
23-
rescue StandardError
24-
puts "Warning: factory_bot_rails gem not found"
34+
rescue Exception => ex
35+
puts "✅ #{'require'.light_red} #{"'factory_bot_rails'".cyan}"
36+
notice_me "Warning: factory_bot_rails gem not found, #{ex}"
2537
end
2638

27-
# Gives domestic_phone_number for creating factories that use phone numbers
39+
# -----------------------------------------------------------------------------
40+
# Enables a lot more factories which explicilty need the domestic_phone_number
41+
# gem for creating factories that use phone numbers
2842
begin
2943
require './spec/support/faker_phones.rb'
30-
puts "#{'require'.light_red} #{"'./spec/support/faker_phones.rb'".cyan}"
44+
puts "#{'require'.light_red} #{"'./spec/support/faker_phones.rb'".cyan}"
3145
rescue StandardError
32-
puts "Warning: ./spec/support/faker_phones.rb not found"
46+
notice_me "Warning: ./spec/support/faker_phones.rb not found"
3347
end
3448

49+
# -----------------------------------------------------------------------------
50+
# Load the route helpers in the terminal so you can generate page URLs
51+
# admin_stark_user_path / admin_stark_user_url
52+
begin
53+
include Rails.application.routes.url_helpers
54+
puts "✅ #{'include'.light_yellow} #{'Rails.application.routes.url_helpers'.cyan}"
55+
rescue LoadError
56+
puts "Warning: factory_bot_rails gem not found"
57+
end
3558

36-
# rails 5.1 break?
37-
#begin
38-
#Rails.application.routes.url_helpers
39-
#include Rails.application.routes.url_helpers
40-
#puts "#{'include'.light_yellow} #{'Rails.application.routes.url_helpers'.cyan}"
41-
#rescue LoadError
42-
#puts "Warning: factory_bot_rails gem not found"
43-
#end
44-
45-
puts "#{'Starting a Pry console...'.cyan}"
59+
# =============================================================================
60+
# Helper functions (not meant to be run directly)
61+
# =============================================================================
4662

63+
# -----------------------------------------------------------------------------
64+
# Print a full stack trace with colorized output for easier
4765
def colorized_stack_trace( stack, base_dir )
4866
separator = File::SEPARATOR
4967
longest = stack.max_by(&:length).length
@@ -68,13 +86,21 @@ end
6886
def filtered_stack_trace( stack, filter )
6987
filtered = stack.grep( filter )
7088
if filtered.empty?
71-
puts "#{'The current stack trace doesn\'t contain any lines matching'.red} #{filter.to_s.light_red}#{'.'.red}"
89+
puts "#{'The current stack trace does not contain any lines matching'.red} #{filter.to_s.light_red}#{'.'.red}"
7290
puts 'Type `sa` to see a full colorized stack trace, or `caller` to see the vanilla ruby full stack trace.'.red
7391
return
7492
end
7593
colorized_stack_trace( filtered, filter )
7694
end
7795

96+
# =============================================================================
97+
# Pry commands (meant to be run directly)
98+
# =============================================================================
99+
100+
# -----------------------------------------------------------------------------
101+
# Print out the stack *only* including the current application's directory,
102+
# for example stack trace lines *only* matching /jarvis/ to remove noisy Gem
103+
# stack traces
78104
Pry::Commands.block_command "s", "Application stack trace" do
79105
separator = File::SEPARATOR
80106
pwd = Dir.pwd
@@ -86,25 +112,38 @@ Pry::Commands.block_command "sa", "Application stack trace" do
86112
filtered_stack_trace( caller, /./ )
87113
end
88114

89-
def defandy(input)
115+
# =============================================================================
116+
# Utiltiy functions (meant to be run directly)
117+
# =============================================================================
118+
119+
# -----------------------------------------------------------------------------
120+
# Copy some text to the clipboard
121+
def copy(input)
90122
_max_display_string_length = 50
91123
str = input.to_s
92124
IO.popen('pbcopy', 'w') { |f| f << str }
93125
truncated = str.length > _max_display_string_length ? str[0.._max_display_string_length] + '...' : str
94126
puts "Copied \"#{truncated}\" to system clipboard!"
95127
end
96128

97-
def h_o(input)
129+
# -----------------------------------------------------------------------------
130+
# Write some text to an HTML file and open it for quick inspection. Opens with
131+
# browser by default
132+
def r_o(input)
98133
f = Tempfile.new(['foo', '.html'])
99134
f.write(input)
100135
f.close
101136
`open #{f.path}`
102137
end
103138

139+
# -----------------------------------------------------------------------------
140+
# When debugging an rspec test, this will attempt to load the current page
141+
# body and display it to you in your web browser
104142
def showme
105-
h_o( defined?(page) ? page.body : dom.to_s )
143+
r_o( defined?(page) ? page.body : dom.to_s )
106144
end
107145

108-
# Disabe paging in pry
109-
Pry.config.pager = false
110-
146+
# =============================================================================
147+
# ✨
148+
# =============================================================================
149+
puts "\n#{'✨ Pry'.yellow} #{'console'.cyan} #{'initialized'.light_red} #{'succesfully! ✨'.green}"

0 commit comments

Comments
 (0)