irt 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,4 +1,4 @@
1
- # irt
1
+ # IRT
2
2
 
3
3
  Interactive Ruby Tools - Improved irb and rails console with a lot of easy and powerful tools.
4
4
 
@@ -76,7 +76,7 @@ IRT uses colors consistently, so you will have an instant feedback about what a
76
76
  - __cyan__ for files, saved values (and object 'a' in a diff)
77
77
  - __magenta__ for interactive sessions
78
78
  - __black/white__ for generic stdin/stdout and inspecting sessions (e.g. 'irt my_obj')
79
- - __blue__ for the Virtual Log and generic labels
79
+ - __blue__ for the Virtual Log, Rails Log and generic labels
80
80
  - __yellow__ for result echo (not setting last value), for binding sessions and for tests with diffs
81
81
  - __green__ for result echo (setting last value) (and object 'b' in a diff)
82
82
  - __red__ for erros, exceptions and rerun
@@ -102,23 +102,21 @@ There are 4 irt modes / session types: file, interactive, inspect, binding.
102
102
  IRT always start in file mode, which simply means that it will execute the code in a file.
103
103
  Indeed you launch irt passing a path argument of one or more existing files or dirs. If any path does not refer
104
104
  to any existing file, irt will ask you to confirm that you want to create that file. Eventually
105
- if you don't pass any path argument, irt will create a temporary empty file.
106
-
107
- A new or temporary created file contains just one statement: 'irt' which will open an interactive session.
105
+ if you don't pass any path argument, irt will create a temporary one-empty-line file.
108
106
 
109
107
  Notice: When you pass a dir as the path, irt will recursively execute all the '.irt' files in it, so suffixing
110
108
  with '.irt' the files is not just a convention. It allows to skyp any non .irt file, like libraries or files
111
- used with the 'insert_file' directive.
109
+ used with the 'insert\_file' directive.
112
110
 
113
111
  #### Note about new files
114
112
 
115
113
  The new created files are implicitly run with the -i (--interative-eol) flag by default.
116
114
  That flag instruct irt to open an interactive session at the end of the file, so you will have the possibilty
117
115
  to add your statements. As long as you rerun the file (with the 'rr' command) IRT will remember the flag,
118
- anyway, if the session ends and you have to re-launch it from the command line, you must pass the -e flag
116
+ anyway, if the session ends and you have to re-launch it from the command line, you must pass the -i flag
119
117
  explicitly or no interactive session will be opened automatically.
120
118
 
121
- You can save any running file as another file with the 'save_as' command.
119
+ You can save any running file as another file with the 'save\_as' command.
122
120
 
123
121
  ### Interactive Sessions (magenta)
124
122
 
@@ -397,7 +395,7 @@ Besides it offers a very useful contextual search, that will find the ri doc of
397
395
  Example:
398
396
 
399
397
  # autocompletion
400
- >> ri "any string".eq[TAB]
398
+ >> ri "any string".eq[TAB][TAB]
401
399
  .eql? .equal?
402
400
 
403
401
  >> ri "a string".eql?
@@ -424,9 +422,16 @@ The status line shows the nesting status of your sessions: each time you open a
424
422
  session or exit from the current session it is automatically printed.
425
423
  You can also print it with 'status' (or 'ss') at any time.
426
424
 
427
- ### System Shortcuts
425
+ ### Quasi-shell
426
+
427
+ Save some typing for system calls and avoid to open a shell.
428
+ You can use the '$' as an alias of 'system' with the difference that you don't need to use quotes
429
+ (although quotes will work anyway), and the command will not be logged. Examples:
428
430
 
429
- Save some typing for common system calls like ls, cat, vi, nano
431
+ >> $ ls -F
432
+ >> $ tail /some/path
433
+ >> $ git rebase -i HEAD~5
434
+ >> $ cat #{file_path}
430
435
 
431
436
  ### FileUtils
432
437
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.4
1
+ 1.1.5
data/bin/irt CHANGED
@@ -84,6 +84,15 @@ end
84
84
 
85
85
  cmd_format = if File.exists?('./config/environment.rb')
86
86
  if File.exists?('./script/rails')
87
+ gemfile = File.read('Gemfile')
88
+ unless gemfile.match(/\bgem\b.+\birt\b/)
89
+ Prompter.say_warning %(The Gemfile doesn't look to include any 'gem "irt"' statement.\nIRT will probably not work until you add it!)
90
+ Prompter.yes?("Do you want to add irt to your Gemfile?", :hint => '[enter=y|n]', :default => 'y') do
91
+ File.open('Gemfile', 'a') do |f|
92
+ f.puts %(gem "irt")
93
+ end
94
+ end
95
+ end
87
96
  'rails c %s %s %s'
88
97
  elsif File.exists?('./script/console')
89
98
  'ruby script/console --irb="irt_rails2 %s"'
@@ -101,7 +110,7 @@ ENV['IRT_INTERACTIVE_EOF'] = options[:interactive_eof].inspect if options[:inter
101
110
  files.each do |file|
102
111
  ENV['IRT_COMMAND'] = sprintf cmd_format, file, options[:irb_options], options[:rails_env]
103
112
  unless system(ENV['IRT_COMMAND'])
104
- puts "\e[0m" if Dye.color?
113
+ puts Dye.sgr(:clear) if Dye.color?
105
114
  exit(1)
106
115
  end
107
116
  end
data/lib/irt.rb CHANGED
@@ -99,9 +99,9 @@ module IRT
99
99
 
100
100
  def init_files
101
101
  @irt_file = IRB.conf[:SCRIPT]
102
+ require 'irt/extensions/rails' if defined?(ActiveSupport::BufferedLogger)
102
103
  @log = Log.new
103
104
  @log.print_running_file
104
- require 'irt/extensions/rails' if defined?(ActiveSupport::BufferedLogger)
105
105
  IRT::Directives.load_helper_files
106
106
  end
107
107
 
@@ -1,18 +1,6 @@
1
1
  module IRT
2
2
  module Commands
3
- module System
4
-
5
- def cat(*args)
6
- ensure_session
7
- return system "cat #{context.file_line_pointers.first}" if args.empty?
8
- system "cat #{args * ' '}"
9
- end
10
-
11
- def ls(*args)
12
- ensure_session
13
- args = %w[.] if args.empty?
14
- system "ls #{args * ' '}"
15
- end
3
+ module Edit
16
4
 
17
5
  def copy_lines
18
6
  ensure_session
@@ -69,12 +69,17 @@ module IRT
69
69
  ri n Search the ri doc for the method n in a multiple
70
70
  choices list
71
71
 
72
+ #{label(" Rails Commands ", :interactive_color) + IRT.dye(" (only available for Rails Apps)", :interactive_color, :bold)}
73
+ rails_log_on Turn the rails log-in-console ON
74
+ rails_log_off Turn the rails log-in-console OFF
75
+
72
76
  #{label " Misc Commands ", :interactive_color}
73
77
  x|q Aliases for exit (from the current session)
74
78
  xx|qq Aliases for abort (abort the irt process)
75
79
  status|ss Prints the session status line
76
80
  rerun|rr Reruns the same file
77
81
  irt_help|hh Shows this screen
82
+ $ shell_command Alias for system("shell_command") (no quotes needed)
78
83
 
79
84
  #{label " Session Directives ", :file_color}
80
85
  irt Opens an interactive session which retains the
@@ -1,6 +1,6 @@
1
1
  require 'irt/commands/log'
2
2
  require 'irt/commands/test'
3
- require 'irt/commands/system'
3
+ require 'irt/commands/edit'
4
4
  require 'irt/commands/core'
5
5
  require 'irt/commands/help'
6
6
  require 'irt/commands/ri'
@@ -11,7 +11,7 @@ module IRB
11
11
 
12
12
  include IRT::Commands::Log
13
13
  include IRT::Commands::Test
14
- include IRT::Commands::System
14
+ include IRT::Commands::Edit
15
15
  include IRT::Commands::Core
16
16
  include IRT::Commands::Help
17
17
  include IRT::Commands::Ri
@@ -38,18 +38,18 @@ module IRB
38
38
  end
39
39
  log_file_line(line_no) if irt_mode == :file
40
40
  begin
41
- # ri arg to string
42
- if m = line.match(/^(\s*ri[ \t]+)(.+)$/)
43
- pre, to_search = m.captures
44
- line = "#{pre}#{to_search.inspect}" unless to_search.match(/^('|").+\1$/)
45
- else
46
- IRT::Commands::Ri.reset_choices_map
47
- end
48
41
  # skip setting last_value for non_setting_commands
49
- if line =~ /^\s*(#{IRT.log.non_setting_commands * '|'})\b/
42
+ if line =~ /^\s*(#{quoted_option_string(IRT.log.non_setting_commands)})(?:[ \t]+|\b)(.+)*/
43
+ command, args = $1, $2
44
+ if command =~ /^(\$|ri)$/ && irt_mode != :file
45
+ cmd = command == '$' ? 'system' : command
46
+ args = "%(#{args})" unless args.match(/^('|").+\1$/)
47
+ line = "#{cmd} #{args}"
48
+ end
49
+ IRT::Commands::Ri.reset_choices_map unless command == 'ri'
50
50
  self.echo = false
51
51
  res = @workspace.evaluate(self, line, irb_path, line_no)
52
- if line =~ /^\s*(#{IRT.log.ignored_echo_commands * '|'})\b/
52
+ if command =~ /^(#{IRT.log.ignored_echo_commands * '|'})$/
53
53
  output_ignored_echo_value(res)
54
54
  end
55
55
  else
@@ -59,14 +59,14 @@ module IRB
59
59
  rescue Exception => e
60
60
  @exception_raised = true
61
61
  process_exception(e)
62
- print "\e[31m" if Dye.color?
62
+ print Dye.sgr(IRT.dye_styles[:error_color]) if Dye.color?
63
63
  raise
64
64
  else
65
65
  log_session_line(line, line_no) unless irt_mode == :file
66
66
  end
67
67
  end
68
68
 
69
- %w[prompt_i prompt_s prompt_c prompt_n].each do |m|
69
+ [:prompt_i, :prompt_s, :prompt_c, :prompt_n].each do |m|
70
70
  define_method(m) do
71
71
  pr = instance_variable_get("@#{m}")
72
72
  col_pr = IRT.dye pr, "#{irt_mode}_color".to_sym
@@ -95,6 +95,10 @@ module IRB
95
95
 
96
96
  private
97
97
 
98
+ def quoted_option_string(arr)
99
+ arr.map{|c|Regexp.quote(c.to_s)} * '|'
100
+ end
101
+
98
102
  def process_exception(e)
99
103
  bktr = e.backtrace.reject do |m|
100
104
  workspace.filter_backtrace(m).nil? || !IRT.debug && File.expand_path(m).match(/^#{IRT.lib_path}/)
@@ -141,7 +145,9 @@ private
141
145
  i = -1
142
146
  str.each_line do |l|
143
147
  @last_line_no = line_no + i+=1
144
- IRT.log.add_line l, @last_line_no
148
+ unless l =~ /^\s*(#{quoted_option_string(IRT.log.ignored_commands)})/
149
+ IRT.log.add_line l, @last_line_no
150
+ end
145
151
  end
146
152
  end
147
153
 
@@ -16,16 +16,22 @@ class ActiveSupport::BufferedLogger
16
16
 
17
17
  end
18
18
 
19
- module IRB
20
- module ExtendCommandBundle #:nodoc:
19
+ module IRT
20
+ module Commands
21
+ module Rails
21
22
 
22
- def rails_log_on
23
- IRT.rails_log = true
24
- end
23
+ extend self
25
24
 
26
- def rails_log_off
27
- IRT.rails_log = false
28
- end
25
+ def rails_log_on
26
+ IRT.rails_log = true
27
+ end
29
28
 
29
+ def rails_log_off
30
+ IRT.rails_log = false
31
+ end
32
+
33
+ end
30
34
  end
31
35
  end
36
+
37
+ IRB::ExtendCommandBundle.send :include, IRT::Commands::Rails
data/lib/irt/hunks.rb CHANGED
@@ -74,12 +74,6 @@ module IRT
74
74
  @header = IRB.CurrentContext.irb_name
75
75
  end
76
76
 
77
- def add_line(content, line_no)
78
- ignored = IRT.log.ignored_commands + %w[_]
79
- return if content.match(/^\s*(#{ignored * '|'})\b/)
80
- super
81
- end
82
-
83
77
  end
84
78
 
85
79
 
data/lib/irt/log.rb CHANGED
@@ -5,11 +5,15 @@ module IRT
5
5
  attr_reader :status
6
6
 
7
7
  def initialize
8
- @ignored_echo_commands = FileUtils.own_methods
8
+ @ignored_echo_commands = FileUtils.own_methods + [:_]
9
+ @ignored_echo_commands += IRT::Commands::Rails.own_methods if defined?(IRT::Commands::Rails)
10
+ @ignored_echo_commands = @ignored_echo_commands.map(&:to_sym)
9
11
  @ignored_commands = @ignored_echo_commands +
10
12
  IRB::ExtendCommandBundle.instance_methods +
11
- %w[ p pp ap y puts print irt irb ]
13
+ [ :p, :pp, :ap, :y, :puts, :print, :irt, :irb, :'$']
14
+ @ignored_commands = @ignored_commands.map(&:to_sym)
12
15
  @non_setting_commands = @ignored_commands + IRT::Directives.own_methods
16
+ @non_setting_commands = @non_setting_commands.map(&:to_sym)
13
17
  @tail_size = tail_size || 10
14
18
  self << FileHunk.new(IRT.irt_file)
15
19
  @status = [[File.basename(IRT.irt_file), :file]]
@@ -1,20 +1,20 @@
1
1
  module IRT
2
2
  module RubyVersion
3
3
 
4
- extend self
5
-
6
4
  class Version < Array
7
5
  include Comparable
8
6
 
9
- def initialize(version=RUBY_VERSION)
10
- replace version.split('.').map(&:to_i)
11
- end
7
+ def initialize(version)
8
+ replace version.split('.').map(&:to_i)
9
+ end
12
10
  end
13
11
 
12
+ extend self
13
+
14
14
  [:>, :>=, :<, :<=, :==, :between?].each do |m|
15
15
  define_method(m) do |*args|
16
16
  vers = args.map{|a| Version.new(a)}
17
- Version.new.send m, *vers
17
+ Version.new(RUBY_VERSION).send m, *vers
18
18
  end
19
19
  end
20
20
 
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irt
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.1.4
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 5
10
+ version: 1.1.5
6
11
  platform: ruby
7
12
  authors:
8
13
  - Domizio Demichelis
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-02-05 00:00:00 -04:00
18
+ date: 2011-02-06 00:00:00 -04:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
@@ -21,6 +26,11 @@ dependencies:
21
26
  requirements:
22
27
  - - ">="
23
28
  - !ruby/object:Gem::Version
29
+ hash: 25
30
+ segments:
31
+ - 0
32
+ - 1
33
+ - 1
24
34
  version: 0.1.1
25
35
  type: :runtime
26
36
  version_requirements: *id001
@@ -32,6 +42,11 @@ dependencies:
32
42
  requirements:
33
43
  - - ">="
34
44
  - !ruby/object:Gem::Version
45
+ hash: 25
46
+ segments:
47
+ - 0
48
+ - 1
49
+ - 1
35
50
  version: 0.1.1
36
51
  type: :runtime
37
52
  version_requirements: *id002
@@ -43,18 +58,29 @@ dependencies:
43
58
  requirements:
44
59
  - - ">="
45
60
  - !ruby/object:Gem::Version
61
+ hash: 31
62
+ segments:
63
+ - 0
64
+ - 1
65
+ - 2
46
66
  version: 0.1.2
47
67
  type: :runtime
48
68
  version_requirements: *id003
49
69
  - !ruby/object:Gem::Dependency
50
- name: bri
70
+ name: fastri
51
71
  prerelease: false
52
72
  requirement: &id004 !ruby/object:Gem::Requirement
53
73
  none: false
54
74
  requirements:
55
75
  - - ">="
56
76
  - !ruby/object:Gem::Version
57
- version: 0.1.5
77
+ hash: 81
78
+ segments:
79
+ - 0
80
+ - 3
81
+ - 1
82
+ - 1
83
+ version: 0.3.1.1
58
84
  type: :runtime
59
85
  version_requirements: *id004
60
86
  description: If you use IRT in place of irb or rails console, you will have more tools that will make your life a lot easier.
@@ -83,10 +109,10 @@ files:
83
109
  - irtrc
84
110
  - lib/irt.rb
85
111
  - lib/irt/commands/core.rb
112
+ - lib/irt/commands/edit.rb
86
113
  - lib/irt/commands/help.rb
87
114
  - lib/irt/commands/log.rb
88
115
  - lib/irt/commands/ri.rb
89
- - lib/irt/commands/system.rb
90
116
  - lib/irt/commands/test.rb
91
117
  - lib/irt/differ.rb
92
118
  - lib/irt/directives.rb
@@ -117,17 +143,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
143
  requirements:
118
144
  - - ">="
119
145
  - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
120
149
  version: "0"
121
150
  required_rubygems_version: !ruby/object:Gem::Requirement
122
151
  none: false
123
152
  requirements:
124
153
  - - ">="
125
154
  - !ruby/object:Gem::Version
155
+ hash: 23
156
+ segments:
157
+ - 1
158
+ - 3
159
+ - 6
126
160
  version: 1.3.6
127
161
  requirements: []
128
162
 
129
163
  rubyforge_project:
130
- rubygems_version: 1.5.0
164
+ rubygems_version: 1.3.7
131
165
  signing_key:
132
166
  specification_version: 3
133
167
  summary: Interactive Ruby Tools - Improved irb and rails console with a lot of easy and powerful tools.