-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpryrc
162 lines (161 loc) · 4.43 KB
/
pryrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Pry.config.editor = 'vim'
# Pry.config.commands.alias_command "q", "exit-all"
#
# Pry.commands.alias_command 'c', 'continue'
# Pry.commands.alias_command 's', 'step'
# Pry.commands.alias_command 'n', 'next'
# Pry.commands.alias_command 'f', 'finish'
# # Toys methods
# # See https://gist.github.com/807492
# class Array
# def self.toy(n=10, &block)
# block_given? ? Array.new(n,&block) : Array.new(n) {|i| i+1}
# end
# end
#
# class Hash
# def self.toy(n=10)
# Hash[Array.toy(n).zip(Array.toy(n){|c| (97+c).chr})]
# end
# end
#
# if defined?(Rails) && Rails.env
# require 'logger'
#
# if defined?(ActiveRecord)
# ActiveRecord::Base.logger = Logger.new(STDOUT)
# ActiveRecord::Base.clear_active_connections!
# end
#
# end
#
#
#
# # Load 'awesome_print'
# begin
# require 'awesome_print'
# require 'awesome_print/ext/active_record'
# require 'awesome_print/ext/active_support'
# AwesomePrint.pry!
# rescue LoadError => err
# end
#
# # Load 'hirb'
# # begin
# # require 'hirb'
# #
# # Pry.config.print = proc do |output, value|
# # Hirb::View.view_or_page_output(value) || Pry::DEFAULT_PRINT.call(output, value)
# # end
# #
# # Hirb.enable
# # rescue LoadError => err
# # end
#
# # Launch Pry with access to the entire Rails stack
# rails = File.join(Dir.getwd, 'config', 'environment.rb')
#
# if File.exist?(rails) && ENV['SKIP_RAILS'].nil?
# require rails
#
# if Rails.version[0..0] == "2"
# require 'console_app'
# require 'console_with_helpers'
# elsif Rails.version[0..0].in?(['3', '4'])
# require 'rails/console/app'
# require 'rails/console/helpers'
# else
# warn "[WARN] cannot load Rails console commands (Not on Rails2, Rails3 or Rails4?)"
# end
#
# # Rails' pry prompt
# env = ENV['RAILS_ENV'] || Rails.env
# rails_root = File.basename(Dir.pwd)
#
# rails_env_prompt = case env
# when 'development'
# '[DEV]'
# when 'production'
# '[PROD]'
# else
# "[#{env.upcase}]"
# end
#
# prompt = '%s %s %s:%s'
# Pry.config.prompt = [ proc { |obj, nest_level, *| "#{prompt}> " % [rails_root, rails_env_prompt, obj, nest_level] },
# proc { |obj, nest_level, *| "#{prompt}* " % [rails_root, rails_env_prompt, obj, nest_level] } ]
#
# # [] acts as find()
# ActiveRecord::Base.instance_eval { alias :[] :find } if defined?(ActiveRecord)
#
# # Add Rails console helpers (like `reload!`) to pry
# if defined?(Rails::ConsoleMethods)
# extend Rails::ConsoleMethods
# end
#
# # r! to reload Rails console
# def r!
# reload!
# end
#
# # automatically call `reload` every time a new command is typed
# # Pry.hooks.add_hook(:before_eval, :reload_everything) { reload!(false) }
#
# # sql for arbitrary SQL commands through the AR
# def sql(query)
# ActiveRecord::Base.connection.execute(query)
# end
#
# # set logging to screen
# if ENV.include?('RAILS_ENV')
# # Rails 2.x
# if !Object.const_defined?('RAILS_DEFAULT_LOGGER')
# require 'logger'
# Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
# end
# else
# # Rails 3
# if Rails.logger and defined?(ActiveRecord)
# Rails.logger = Logger.new(STDOUT)
# ActiveRecord::Base.logger = Rails.logger
# end
# end
#
# # .details method for pretty printing ActiveRecord's objects attributes
# class Object
# def details
# if self.respond_to?(:attributes) and self.attributes.any?
# max = self.attributes.keys.sort_by { |k| k.size }.pop.size + 5
# puts
# self.attributes.keys.sort.each do |k|
# puts sprintf("%-#{max}.#{max}s%s", k, self.try(k))
# end
# puts
# end
# end
# alias :detailed :details
# end
#
# # returns a collection of the methods that Rails added to the given class
# # http://lucapette.com/irb/rails-core-ext-and-irb/
# class Class
# def core_ext
# self.instance_methods.map {|m| [m, self.instance_method(m).source_location] }.select {|m| m[1] && m[1][0] =~/activesupport/}.map {|m| m[0]}.sort
# end
# end
#
# # local methods helper
# # http://rakeroutes.com/blog/customize-your-irb/
# class Object
# def local_methods
# case self.class
# when Class
# self.public_methods.sort - Object.public_methods
# when Module
# self.public_methods.sort - Module.public_methods
# else
# self.public_methods.sort - Object.new.public_methods
# end
# end
# end
# end