Module: IRT

Extended by:
IRT, Utils
Included in:
IRT
Defined in:
lib/irt.rb,
lib/irt/log.rb,
lib/irt/hunks.rb,
lib/irt/utils.rb,
lib/irt/differ.rb,
lib/irt/history.rb,
lib/irt/session.rb,
lib/irt/prompter.rb,
lib/irt/directives.rb,
lib/irt/commands/ri.rb,
lib/irt/commands/log.rb,
lib/irt/ruby_version.rb,
lib/irt/commands/core.rb,
lib/irt/commands/edit.rb,
lib/irt/commands/help.rb,
lib/irt/commands/test.rb,
lib/irt/helpers/rails.rb,
lib/irt/directives/test.rb,
lib/irt/extensions/rails_server.rb,
lib/irt/extensions/rails.rb

Defined Under Namespace

Modules: Commands, Directives, Helpers, History, RubyVersion, Session, Utils Classes: ArgumentTypeError, Differ, IndexError, Log, NotImplementedError, Prompter, SessionModeError

Constant Summary collapse

OS =
case RbConfig::CONFIG['host_os']
when /mswin|msys|mingw32|windows/i
  :windows
when /darwin|mac os/i
  :macosx
when /linux/i
  :linux
when /solaris|bsd/i
  :unix
else
  :unknown
end
EDITORS =
{ :vi    => nil,
:nano  => :nn,
:emacs => :em,
:edit  => :ed }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

ask_run_new_file, copyright, create_tmp_file, edit_with, original_ask_run_new_file, save_as, version

Instance Attribute Details

#autoload_helper_filesObject

Returns the value of attribute autoload_helper_files.



51
52
53
# File 'lib/irt.rb', line 51

def autoload_helper_files
  @autoload_helper_files
end

#copy_to_clipboard_commandObject

Returns the value of attribute copy_to_clipboard_command.



51
52
53
# File 'lib/irt.rb', line 51

def copy_to_clipboard_command
  @copy_to_clipboard_command
end

#debugObject

Returns the value of attribute debug.



51
52
53
# File 'lib/irt.rb', line 51

def debug
  @debug
end

#dye_rails_logObject

Returns the value of attribute dye_rails_log.



51
52
53
# File 'lib/irt.rb', line 51

def dye_rails_log
  @dye_rails_log
end

#dye_stylesObject

Returns the value of attribute dye_styles.



51
52
53
# File 'lib/irt.rb', line 51

def dye_styles
  @dye_styles
end

#fix_readline_promptObject

Returns the value of attribute fix_readline_prompt.



51
52
53
# File 'lib/irt.rb', line 51

def fix_readline_prompt
  @fix_readline_prompt
end

#full_exitObject

Returns the value of attribute full_exit.



51
52
53
# File 'lib/irt.rb', line 51

def full_exit
  @full_exit
end

#initializedObject (readonly)

Returns the value of attribute initialized.



56
57
58
# File 'lib/irt.rb', line 56

def initialized
  @initialized
end

#irt_fileObject (readonly)

Returns the value of attribute irt_file.



56
57
58
# File 'lib/irt.rb', line 56

def irt_file
  @irt_file
end

#irt_on_diffsObject

Returns the value of attribute irt_on_diffs.



51
52
53
# File 'lib/irt.rb', line 51

def irt_on_diffs
  @irt_on_diffs
end

#logObject (readonly)

Returns the value of attribute log.



56
57
58
# File 'lib/irt.rb', line 56

def log
  @log
end

#pager_commandObject

Returns the value of attribute pager_command.



51
52
53
# File 'lib/irt.rb', line 51

def pager_command
  @pager_command
end

#rails_logObject

Returns the value of attribute rails_log.



51
52
53
# File 'lib/irt.rb', line 51

def rails_log
  @rails_log
end

#rails_serverObject

Returns the value of attribute rails_server.



51
52
53
# File 'lib/irt.rb', line 51

def rails_server
  @rails_server
end

#rails_server_sigint_trapObject

Returns the value of attribute rails_server_sigint_trap.



51
52
53
# File 'lib/irt.rb', line 51

def rails_server_sigint_trap
  @rails_server_sigint_trap
end

#ri_command_formatObject

Returns the value of attribute ri_command_format.



51
52
53
# File 'lib/irt.rb', line 51

def ri_command_format
  @ri_command_format
end

#session_noObject

Returns the value of attribute session_no.



51
52
53
# File 'lib/irt.rb', line 51

def session_no
  @session_no
end

#tail_on_irtObject

Returns the value of attribute tail_on_irt.



51
52
53
# File 'lib/irt.rb', line 51

def tail_on_irt
  @tail_on_irt
end

Instance Method Details

#cli?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/irt/utils.rb', line 10

def cli?
  !!ENV['IRT_COMMAND']
end

#force_color(bool) ⇒ Object



63
64
65
# File 'lib/irt.rb', line 63

def force_color(bool)
  Dye.color = bool
end

#force_color=(bool) ⇒ Object



58
59
60
61
# File 'lib/irt.rb', line 58

def force_color=(bool)
  force_color(bool)
  IRT::Prompter.say_warning "The 'IRT.force_color=' method is deprecated: use 'IRT.force_color(true/false)'"
end

#force_tty(bool) ⇒ Object



67
68
69
# File 'lib/irt.rb', line 67

def force_tty(bool)
  eval %(def STDIN.tty?; #{bool}; end)
end

#init_configObject



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
# File 'lib/irt.rb', line 71

def init_config
  @irt_on_diffs = true
  @tail_on_irt = false
  @fix_readline_prompt = false
  @rails_log = true
  @dye_rails_log = true
  @autoload_helper_files = true
  @dye_styles = { :null              => :clear,

                  :log_color         => :blue,
                  :file_color        => :cyan,
                  :interactive_color => :magenta,
                  :inspect_color     => :clear,
                  :binding_color     => :yellow,
                  :actual_color      => :green,
                  :ignored_color     => :yellow,

                  :error_color       => :red,
                  :ok_color          => :green,
                  :diff_color        => :yellow,
                  :diff_a_color      => :cyan,
                  :diff_b_color      => :green }
  define_dye_method @dye_styles
  case OS
  when :windows
    @copy_to_clipboard_command = 'clip'
    @edit_command_format = '%1$s'
  when :macosx
    @copy_to_clipboard_command = 'pbcopy'
    @edit_command_format = 'open -t %1$s'
  when :linux, :unix
    @copy_to_clipboard_command = 'xclip -selection c'
    @edit_command_format = case ENV['DESKTOP_SESSION']
                           when /kde/i
                             'kde-open %1$s'
                           when /gnome/i
                             'gnome-open %1$s'
                           end
  end
  @vi_command_format = %(vi "%1$s" +%2$d)
  @nano_command_format = %(nano +%2$d "%1$s")
  @emacs_command_format = %(emacs +%2$d "%1$s")
  @ri_command_format =  case IRT::Commands::Ri::GEM
                        when 'bri'    then %(bri "%s")
                        when 'fastri' then %(qri -f #{Dye.color? ? 'ansi' : 'plain'} "%s")
                        when 'ri'     then %(ri -f #{Dye.color? ? 'ansi' : 'bs'} "%s")
                        end
  @pager_command = 'less -R'
  @debug = false
end

#init_file(file = nil) ⇒ Object



144
145
146
147
148
149
150
151
# File 'lib/irt.rb', line 144

def init_file(file = nil)
  @session_no = 0
  irt_file = file.nil? ? IRB.conf[:SCRIPT] : (IRB.conf[:SCRIPT] = file)
  @irt_file = Pathname.new(irt_file).realpath
  @log = Log.new
  IRT::Directives.load_helper_files
  @log.print_running_file
end

#lib_pathObject



14
15
16
# File 'lib/irt/utils.rb', line 14

def lib_path
  File.expand_path '../../../lib', __FILE__
end

#rails_signal_handleObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/irt/extensions/rails_server.rb', line 33

def rails_signal_handle
  puts
  rails_server_notice_wrap do
    trap('SIGINT'){}
    input = IRT::Prompter.choose " [s]hutdown, [i]rt or [c]ancel?", /^(s|i|c)$/i,
                                 :hint => '[<enter>=s|i|c]', :default => 's'
    trap('SIGINT') { rails_signal_handle  }
    case input
    when 's'
      IRT.rails_server_sigint_trap.call
    when 'i'
      Session.enter :interactive
    end
  end
end

#setupObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/irt.rb', line 122

def setup
  IRB::ExtendCommandBundle.class_eval do
    [:p, :y, :pp, :ap].each do |m|
      next unless begin
                    method(m)
                  rescue NameError
                  end
      define_method(m) do |*args|
        args = [context.last_value] if args.empty?
        super *args
      end
    end
  end
  # sets the AR logger to Rails logger, so it will be available
  # inline in the IRT console (with the same log color)
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.logger = ::Rails.logger
  end
  @initialized = true
  init_file
end

#startObject

this will create a tmp file and start IRB but it will be left in file mode at EOF (sort of irt-standby)



155
156
157
158
159
160
161
162
# File 'lib/irt.rb', line 155

def start
  return if initialized
  puts copyright
  argv = ARGV
  ARGV.clear
  IRB.start
  ARGV.replace(argv)
end

#yaml_dump(val) ⇒ Object

this fixes a little imperfection of the YAML::dump method which adds a space at the end of the class



20
21
22
23
# File 'lib/irt/utils.rb', line 20

def yaml_dump(val)
  yml = "\n" + YAML.dump(val)
  yml.gsub(/ +\n/, "\n")
end