Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/not.rb,
lib/with.rb,
lib/is_an.rb,
lib/pastie.rb,
lib/language_greps.rb,
lib/language_greps.rb,
lib/command_history.rb,
lib/interactive_editor.rb,
lib/irb_verbosity_control.rb,
lib/rails_verbosity_control.rb
Overview
Rails verbosity: weblog.jamisbuck.org/2007/1/8/watching-activerecord-do-it-s-thing Marcel said they toyed with making this the console default on core
Defined Under Namespace
Classes: Not
Instance Method Summary collapse
- #edit(editor) ⇒ Object
- #emacs ⇒ Object
- #grep_classes(search_term) ⇒ Object
- #grep_methods(search_term) ⇒ Object
- #history(how_many = 50) ⇒ Object (also: #h)
-
#history_do(lines = (Readline::HISTORY.size - 2)) ⇒ Object
(also: #h!)
-2 because -1 is ourself.
-
#history_to_vi ⇒ Object
(also: #hvi)
TODO: history_write should go to a file, or the clipboard, or a file which opens in an application.
- #history_write(filename, lines) ⇒ Object
- #log ⇒ Object
- #mate ⇒ Object
- #pastie ⇒ Object (also: #pst)
- #quiet ⇒ Object (also: #q)
- #verbose ⇒ Object (also: #v)
- #vi ⇒ Object
- #with(object, &block) ⇒ Object
Instance Method Details
#edit(editor) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/interactive_editor.rb', line 22 def edit(editor) unless IRB.conf[:interactive_editors] && IRB.conf[:interactive_editors][editor] IRB.conf[:interactive_editors] ||= {} IRB.conf[:interactive_editors][editor] = InteractiveEditor.new(editor) end IRB.conf[:interactive_editors][editor].edit end |
#emacs ⇒ Object
38 39 40 |
# File 'lib/interactive_editor.rb', line 38 def emacs edit(:emacs) end |
#grep_classes(search_term) ⇒ Object
15 16 17 18 19 |
# File 'lib/language_greps.rb', line 15 def grep_classes(search_term) classes = [] ObjectSpace.each_object {|object| classes << object.name if object.is_a? Class and not object.name.blank?} classes.find_all {|klass| klass.downcase.include? search_term.downcase} end |
#grep_methods(search_term) ⇒ Object
24 25 26 |
# File 'lib/language_greps.rb', line 24 def grep_methods(search_term) methods.find_all {|method| method.downcase.include? search_term.downcase} end |
#history(how_many = 50) ⇒ Object Also known as: h
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/command_history.rb', line 27 def history(how_many = 50) history_size = Readline::HISTORY.size # no lines, get out of here puts "No history" and return if history_size == 0 start_index = 0 # not enough lines, only show what we have if history_size <= how_many how_many = history_size - 1 end_index = how_many else end_index = history_size - 1 # -1 to adjust for array offset start_index = end_index - how_many end start_index.upto(end_index) {|i| print_line i} end |
#history_do(lines = (Readline::HISTORY.size - 2)) ⇒ Object Also known as: h!
-2 because -1 is ourself
45 46 47 |
# File 'lib/command_history.rb', line 45 def history_do(lines = (Readline::HISTORY.size - 2)) irb_eval lines end |
#history_to_vi ⇒ Object Also known as: hvi
TODO: history_write should go to a file, or the clipboard, or a file which opens in an application
59 60 61 62 63 64 65 66 |
# File 'lib/command_history.rb', line 59 def history_to_vi file = Tempfile.new("irb_tempfile") get_lines(0..(Readline::HISTORY.size - 1)).each do |line| file << "#{line}\n" end file.close system("vim #{file.path}") end |
#history_write(filename, lines) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/command_history.rb', line 50 def history_write(filename, lines) file = File.open(filename, 'w') get_lines(lines).each do |l| file << "#{l}\n" end file.close end |
#log ⇒ Object
4 5 6 7 |
# File 'lib/rails_verbosity_control.rb', line 4 def log ActiveRecord::Base.clear_active_connections! ActiveRecord::Base.logger = Logger.new(STDOUT) end |
#mate ⇒ Object
34 35 36 |
# File 'lib/interactive_editor.rb', line 34 def mate edit(:mate) end |
#pastie ⇒ Object Also known as: pst
4 5 6 7 8 9 10 11 12 |
# File 'lib/pastie.rb', line 4 def pastie pastie_url = Net::HTTP.post_form(URI.parse("http://pastie.caboo.se/pastes/create"), {"paste_parser" => "ruby", "paste[authorization]" => "burger", "paste[body]" => MacClipboard.read}).body.match(/href="([^\"]+)"/)[1] MacClipboard.write(pastie_url) system("open #{pastie_url}") pastie_url end |
#quiet ⇒ Object Also known as: q
23 24 25 |
# File 'lib/irb_verbosity_control.rb', line 23 def quiet IRB.hide_results end |
#verbose ⇒ Object Also known as: v
18 19 20 |
# File 'lib/irb_verbosity_control.rb', line 18 def verbose IRB.show_results end |
#vi ⇒ Object
30 31 32 |
# File 'lib/interactive_editor.rb', line 30 def vi edit(:vim) end |
#with(object, &block) ⇒ Object
17 18 19 |
# File 'lib/with.rb', line 17 def with(object, &block) object.instance_eval &block end |