1- #require 'awesome_print' # Removing because bad colors and can't configure
2- #AwesomePrint.pry!
3-
4-
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 )
1+ # =============================================================================
2+ # Setup
3+ # =============================================================================
4+
5+ # Disabe paging in pry, to avoid having to keep hitting j/space on big output
6+ # on small screens
7+ # On second thought I want this on because printing a huge object is not
8+ # cancellable
9+ # Pry.config.pager = false
10+
11+ # -----------------------------------------------------------------------------
12+ # Rails app spits out lots of startup garbage, separate this
13+ def notice_me ( msg )
14+ puts '*' * 100
15+ puts "❌ #{ msg } "
16+ puts
1017end
11- puts "Client ready at #{ url } "
1218
19+ # -----------------------------------------------------------------------------
20+ # Required for all the other functions: The 'colorize' gem, which lets you
21+ # colorize text output to the console. Since it's not in the Jarvis Gemfile,
22+ # we have to go find it manually. To find yours, do something like `bundle show # httparty`,
23+ # get the base gems/ path, and find colorize in there
1324begin
14- require 'colorize'
15- puts "#{ 'require' . light_red } #{ "'colorize'" . cyan } "
16- rescue StandardError
17- puts "Warning: colorize gem not found"
25+ colorize_init_file = "#{ Dir . home } /.gem/ruby/2.5.1/gems/colorize-0.8.1/lib/colorize.rb"
26+ require colorize_init_file
27+ puts "✅ #{ 'require' . light_red } #{ "'colorize'" . cyan } "
28+ rescue Exception => ex # Did you know LoadError inherits from Exception, not StandardError?
29+ 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 } "
1830end
1931
32+ # -----------------------------------------------------------------------------
33+ # Enables FactoryBot in a pry session
2034begin
2135 require 'factory_bot_rails'
22- puts "#{ 'require' . light_red } #{ "'factory_bot_rails'" . cyan } "
36+ puts "✅ #{ 'require' . light_red } #{ "'factory_bot_rails'" . cyan } "
37+ rescue Exception => ex
38+ notice_me "Warning: factory_bot_rails gem not found, #{ ex } "
39+ end
40+
41+ # -----------------------------------------------------------------------------
42+ # Required to create a covered_member patient, apparently?
43+ begin
44+ require './spec/support/anna_spec_helper'
45+ puts "✅ #{ 'require' . light_red } #{ "'./spec/support/anna_spec_helper'" . cyan } "
2346rescue StandardError
24- puts "Warning: factory_bot_rails gem not found"
47+ notice_me "Warning: ./spec/support/anna_spec_helper not found"
2548end
2649
27- # Gives domestic_phone_number for creating factories that use phone numbers
50+ # -----------------------------------------------------------------------------
51+ # Enables a lot more factories which explicilty need the domestic_phone_number
52+ # gem for creating factories that use phone numbers
2853begin
2954 require './spec/support/faker_phones.rb'
30- puts "#{ 'require' . light_red } #{ "'./spec/support/faker_phones.rb'" . cyan } "
55+ puts "✅ #{ 'require' . light_red } #{ "'./spec/support/faker_phones.rb'" . cyan } "
3156rescue StandardError
32- puts "Warning: ./spec/support/faker_phones.rb not found"
57+ notice_me "Warning: ./spec/support/faker_phones.rb not found"
3358end
3459
3560
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
61+ # -----------------------------------------------------------------------------
62+ # Load the route helpers in the terminal so you can generate page URLs
63+ # admin_stark_user_path / admin_stark_user_url
64+ begin
65+ include Rails . application . routes . url_helpers
66+ puts "✅ #{ 'include' . light_yellow } #{ 'Rails.application.routes.url_helpers' . cyan } "
67+ rescue LoadError
68+ puts "Warning: factory_bot_rails gem not found"
69+ end
4470
45- puts "#{ 'Starting a Pry console...' . cyan } "
71+ # =============================================================================
72+ # Helper functions (not meant to be run directly)
73+ # =============================================================================
4674
75+ # -----------------------------------------------------------------------------
76+ # Print a full stack trace with colorized output for easier
4777def colorized_stack_trace ( stack , base_dir )
4878 separator = File ::SEPARATOR
4979 longest = stack . max_by ( &:length ) . length
6898def filtered_stack_trace ( stack , filter )
6999 filtered = stack . grep ( filter )
70100 if filtered . empty?
71- puts "#{ 'The current stack trace doesn\'t contain any lines matching' . red } #{ filter . to_s . light_red } #{ '.' . red } "
101+ puts "#{ 'The current stack trace does not contain any lines matching' . red } #{ filter . to_s . light_red } #{ '.' . red } "
72102 puts 'Type `sa` to see a full colorized stack trace, or `caller` to see the vanilla ruby full stack trace.' . red
73103 return
74104 end
75105 colorized_stack_trace ( filtered , filter )
76106end
77107
108+ # =============================================================================
109+ # Pry commands (meant to be run directly)
110+ # =============================================================================
111+
112+ # -----------------------------------------------------------------------------
113+ # Print out the stack *only* including the current application's directory,
114+ # for example stack trace lines *only* matching /jarvis/ to remove noisy Gem
115+ # stack traces
78116Pry ::Commands . block_command "s" , "Application stack trace" do
79117 separator = File ::SEPARATOR
80118 pwd = Dir . pwd
@@ -86,25 +124,38 @@ Pry::Commands.block_command "sa", "Application stack trace" do
86124 filtered_stack_trace ( caller , /./ )
87125end
88126
89- def defandy ( input )
127+ # =============================================================================
128+ # Utiltiy functions (meant to be run directly)
129+ # =============================================================================
130+
131+ # -----------------------------------------------------------------------------
132+ # Copy some text to the clipboard
133+ def cpy ( input )
90134 _max_display_string_length = 50
91135 str = input . to_s
92136 IO . popen ( 'pbcopy' , 'w' ) { |f | f << str }
93- truncated = str . length > _max_display_string_length ? str [ 0 .._max_display_string_length ] + '... ' : str
94- puts "Copied \" #{ truncated } \" to system clipboard!"
137+ truncated = str . length > _max_display_string_length ? str [ 0 .._max_display_string_length ] + '… ' : str
138+ puts "✅ Copied \" #{ truncated } \" to system clipboard!" . green ;
95139end
96140
97- def h_o ( input )
141+ # -----------------------------------------------------------------------------
142+ # Write some text to an HTML file and open it for quick inspection. Opens with
143+ # browser by default
144+ def r_o ( input )
98145 f = Tempfile . new ( [ 'foo' , '.html' ] )
99146 f . write ( input )
100147 f . close
101148 `open #{ f . path } `
102149end
103150
151+ # -----------------------------------------------------------------------------
152+ # When debugging an rspec test, this will attempt to load the current page
153+ # body and display it to you in your web browser
104154def showme
105- h_o ( defined? ( page ) ? page . body : dom . to_s )
155+ r_o ( defined? ( page ) ? page . body : dom . to_s )
106156end
107157
108- # Disabe paging in pry
109- Pry . config . pager = false
110-
158+ # =============================================================================
159+ # ✨
160+ # =============================================================================
161+ puts "\n #{ '✨ Pry' . yellow } #{ 'console' . cyan } #{ 'initialized' . light_red } #{ 'succesfully! ✨' . green } "
0 commit comments