irt 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.2.1
data/bin/irt CHANGED
@@ -63,11 +63,7 @@ puts copy
63
63
 
64
64
  paths = if ARGV.empty?
65
65
  options[:interactive_eof] = true
66
- tmp_path = IRT::Utils.create_tmp_file do |as_file, tmp_path|
67
- ENV['IRT_COMMAND'] = ENV['IRT_COMMAND'].sub(/#{Regexp.quote(tmp_path)}/, as_file)
68
- exec ENV['IRT_COMMAND']
69
- end
70
- [ tmp_path ]
66
+ [ IRT::Utils.create_tmp_file ]
71
67
  else
72
68
  ARGV.map {|p| File.expand_path(p) }
73
69
  end
data/irt.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Domizio Demichelis"]
9
9
  s.email = 'dd.nexus@gmail.com'
10
10
  s.homepage = 'http://github.com/ddnexus/irt'
11
- s.summary = 'Interactive Ruby Tools - Improved irb and rails console with a lot of easy and powerful tools.'
12
- s.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.'
11
+ s.summary = 'Interactive Ruby Tools - Very improved irb and Rails Console with a lot of cool features.'
12
+ s.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.'
13
13
 
14
14
  s.add_runtime_dependency('differ', [">= 0.1.1"])
15
15
  s.add_runtime_dependency('dye', [">= 0.1.3"])
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
 
30
30
  s.required_rubygems_version = ">= 1.3.6"
31
31
  s.rdoc_options = ["--charset=UTF-8"]
32
+ s.extra_rdoc_files = ["README.markdown"]
32
33
  s.require_paths = ["lib"]
33
34
 
34
35
  end
@@ -44,10 +44,8 @@ module IRT
44
44
  end
45
45
  alias_method :tt, :add_test
46
46
 
47
- def save_as(path)
48
- IRT::Utils.save_as(path) do |as_file|
49
- IRT::Session.run_file as_file
50
- end
47
+ def save_as(file_path)
48
+ IRT::Utils.save_as(file_path)
51
49
  end
52
50
  alias_method :sa, :save_as
53
51
 
@@ -101,7 +101,7 @@ private
101
101
 
102
102
  def process_exception(e)
103
103
  bktr = e.backtrace.reject do |m|
104
- workspace.filter_backtrace(m).nil? || !IRT.debug && File.expand_path(m).match(/^#{IRT.lib_path}/)
104
+ workspace.filter_backtrace(m).nil? || !IRT.debug && File.expand_path(m).match(/^#{Regexp.quote(IRT.lib_path)}/)
105
105
  end
106
106
  e.set_backtrace map_backtrace(bktr)
107
107
  end
@@ -41,7 +41,7 @@ module IRB #:nodoc:
41
41
 
42
42
  module HistorySavingAbility
43
43
  def HistorySavingAbility.extended(obj)
44
- # save_history has to be called just one time at exit
44
+ # save_history has to be called just once at exit
45
45
  # IRB.conf[:AT_EXIT].push proc{obj.save_history}
46
46
  obj.load_history
47
47
  obj
@@ -12,7 +12,7 @@ module Kernel
12
12
 
13
13
  def irt(bind)
14
14
  raise IRT::ArgumentTypeError, "You must pass binding instead of #{bind.class.name} object" unless bind.is_a?(Binding)
15
- IRT::Utils.load_irt
15
+ IRT.start
16
16
  IRT::Session.enter :binding, bind
17
17
  end
18
18
 
@@ -24,7 +24,7 @@ module Kernel
24
24
  def irt(bind)
25
25
  raise IRT::ArgumentTypeError, "You must pass binding instead of #{bind.class.name} object" unless bind.is_a?(Binding)
26
26
  IRT.send(:rails_server_notice_wrap) do
27
- IRT::Utils.load_irt
27
+ IRT.start
28
28
  IRT::Session.enter :binding, bind
29
29
  end
30
30
  end
@@ -38,7 +38,7 @@ module Rack
38
38
  def server
39
39
  # override the SIGINT trap in the Rack::Server.start method allowing multiple choices
40
40
  # since #server is also called after the Rack::Server.start trap
41
- IRT::Utils.load_irt(false)
41
+ IRT.start
42
42
  IRT.rails_server_sigint_trap = trap('SIGINT') { IRT.rails_signal_handle }
43
43
  IRT.rails_server = original_server
44
44
  end
@@ -88,6 +88,17 @@ private
88
88
  end
89
89
 
90
90
 
91
+ module Utils
92
+ alias_method :original_ask_run_new_file, :ask_run_new_file
93
+ # skips asking to run the save file if it is a tmp file in a server session
94
+ # because the server is exiting so no rerun is possible
95
+ def ask_run_new_file(new_file_path, source_path, tmp)
96
+ return if tmp && IRT.rails_server
97
+ original_ask_run_new_file(new_file_path, source_path, tmp)
98
+ end
99
+ end
100
+
101
+
91
102
  module Commands
92
103
  module Core
93
104
 
data/lib/irt/session.rb CHANGED
@@ -84,13 +84,12 @@ module IRT
84
84
  def set_binding_file_pointers(context)
85
85
  caller.each do |c|
86
86
  file, line = c.sub(/:in .*$/,'').split(':', 2)
87
- next if File.expand_path(file).match(/^#{IRT.lib_path}/) # exclude irt internal callers
87
+ next if File.expand_path(file).match(/^#{Regexp.quote(IRT.lib_path)}/) # exclude irt internal callers
88
88
  context.binding_file = file
89
89
  context.binding_line_no = line
90
90
  break
91
91
  end
92
92
  end
93
93
 
94
-
95
94
  end
96
95
  end
data/lib/irt/utils.rb CHANGED
@@ -2,49 +2,37 @@ require 'irt/prompter'
2
2
 
3
3
  module IRT
4
4
 
5
+ extend self
6
+
7
+ def cli?
8
+ !!ENV['IRT_COMMAND']
9
+ end
10
+
11
+
5
12
  module Utils
6
13
 
7
14
  extend self
8
15
 
9
- # this will create a tmp file and start IRB
10
- # but it will be left in file mode at EOF (sort of irt-standby)
11
- def load_irt(run=true)
12
- return if IRT.initialized
13
- puts IRT::Utils.copyright
14
- ARGV.clear
15
- tmp_path = if run
16
- create_tmp_file {|as_file| IRT::Session.run_file as_file}
17
- else
18
- create_tmp_file
19
- end
20
- ARGV.push tmp_path
21
- IRB.start
22
- end
23
-
24
- def create_tmp_file(&block)
16
+ def create_tmp_file()
25
17
  require 'tempfile'
26
18
  tmp_file = Tempfile.new(['', '.irt'])
27
19
  tmp_file << "\n" # one empty line makes irb of 1.9.2 happy
28
20
  tmp_file.flush
29
21
  # ENV used because with IRT.cli? 2 different processes need to access the same path
30
- ENV['IRT_TMP_PATH'] = tmp_path = tmp_file.path
31
- at_exit { check_save_tmp_file(tmp_file, &block) }
32
- tmp_path
22
+ ENV['IRT_TMP_PATH'] = tmp_file.path
23
+ at_exit { check_save_tmp_file(tmp_file) }
24
+ ENV['IRT_TMP_PATH']
33
25
  end
34
26
 
35
- def save_as(as_file_local, source_path=IRT.irt_file, &block)
36
- as_file = File.expand_path(as_file_local)
37
- if File.exists?(as_file)
38
- return false if IRT::Prompter.no? %(Do you want to overwrite "#{as_file}"?), :hint => '[y|<enter=n]', :default => 'n'
27
+ def save_as(file_path, source_path=IRT.irt_file, tmp=false)
28
+ new_file_path = File.expand_path(file_path)
29
+ if File.exists?(new_file_path)
30
+ return false if IRT::Prompter.no? %(Do you want to overwrite "#{new_file_path}"?), :hint => '[y|<enter=n]', :default => 'n'
39
31
  end
40
- dirname = File.dirname(as_file)
32
+ dirname = File.dirname(new_file_path)
41
33
  FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
42
- FileUtils.cp source_path, as_file
43
- if block && IRT::Prompter.yes?( %(Do you want to run the file "#{as_file_local}" now?) )
44
- # reset the tmpfile content so the at_exit proc will not be triggered
45
- File.open(source_path, 'w'){|f| f.puts "\n"} if IRT.irt_file == Pathname.new(ENV['IRT_TMP_PATH']).realpath
46
- block.call as_file, source_path
47
- end
34
+ FileUtils.cp source_path, new_file_path
35
+ ask_run_new_file new_file_path, source_path, tmp
48
36
  end
49
37
 
50
38
  def version
@@ -57,11 +45,28 @@ module IRT
57
45
 
58
46
  private
59
47
 
60
- def check_save_tmp_file(tmp_file, &block)
48
+ def ask_run_new_file(new_file_path, source_path, tmp)
49
+ if IRT::Prompter.yes?( %(Do you want to run the file "#{File.basename(new_file_path)}" now?) )
50
+ # if we are saving a tmp_file from a save_as command (not from an at_exit block)
51
+ if ENV['IRT_TMP_PATH'] && IRT.respond_to?(:irt_file) && IRT.irt_file == Pathname.new(ENV['IRT_TMP_PATH']).realpath
52
+ ENV.delete('IRT_TMP_PATH')
53
+ # reset tmp file content so check_save_tmp_file will be skipped
54
+ File.open(source_path, 'w'){|f| f.puts "\n"}
55
+ end
56
+ if tmp && IRT.cli?
57
+ ENV['IRT_COMMAND'] = ENV['IRT_COMMAND'].sub(/#{Regexp.quote(source_path)}/, new_file_path)
58
+ exec ENV['IRT_COMMAND']
59
+ else
60
+ IRT::Session.run_file new_file_path
61
+ end
62
+ end
63
+ end
64
+
65
+ def check_save_tmp_file(tmp_file)
61
66
  if tmp_file.size > 1
62
67
  IRT::Prompter.yes? %(The template file has been modified, do you want to save it?) do
63
- IRT::Prompter.choose %(Enter the file path to save:), /[\w0-9_]/ do |as_file|
64
- save_as(as_file, tmp_file.path, &block)
68
+ IRT::Prompter.choose %(Enter the file path to save:), /[\w0-9_]/ do |file_path|
69
+ save_as(file_path, tmp_file.path, tmp=true)
65
70
  end
66
71
  end
67
72
  end
data/lib/irt.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # allows standard rails 3 console to run without loading irt
2
+ unless defined?(Rails::Console) && !ENV['IRT_COMMAND']
3
+
1
4
  at_exit{ Dye.print_reset_colors }
2
5
 
3
6
  require 'rubygems'
@@ -50,10 +53,6 @@ module IRT
50
53
  :copy_to_clipboard_command, :nano_command_format, :vi_command_format, :edit_command_format, :ri_command_format
51
54
  attr_reader :log, :irt_file, :initialized
52
55
 
53
- def cli?
54
- !!ENV['IRT_COMMAND']
55
- end
56
-
57
56
  def force_color=(bool)
58
57
  Dye.color = bool
59
58
  end
@@ -140,8 +139,20 @@ module IRT
140
139
  yml.gsub(/ +\n/, "\n")
141
140
  end
142
141
 
142
+ # this will create a tmp file and start IRB
143
+ # but it will be left in file mode at EOF (sort of irt-standby)
144
+ def start
145
+ return if initialized
146
+ puts IRT::Utils.copyright
147
+ ARGV.clear
148
+ ARGV.push IRT::Utils.create_tmp_file
149
+ IRB.start
150
+ end
151
+
143
152
  end
144
153
 
145
154
  IRT.init_config
146
155
  require 'irt/prompter'
147
156
  require 'irt/extensions/rails' if defined?(ActiveSupport::BufferedLogger)
157
+
158
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: irt
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.0
5
+ version: 1.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Domizio Demichelis
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-24 00:00:00 -04:00
13
+ date: 2011-03-05 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -57,7 +57,7 @@ dependencies:
57
57
  version: 0.1.5
58
58
  type: :runtime
59
59
  version_requirements: *id004
60
- 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.
60
+ 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.
61
61
  email: dd.nexus@gmail.com
62
62
  executables:
63
63
  - irt
@@ -65,8 +65,8 @@ executables:
65
65
  - irt_rails2
66
66
  extensions: []
67
67
 
68
- extra_rdoc_files: []
69
-
68
+ extra_rdoc_files:
69
+ - README.markdown
70
70
  files:
71
71
  - .gitignore
72
72
  - LICENSE
@@ -133,6 +133,6 @@ rubyforge_project:
133
133
  rubygems_version: 1.5.0
134
134
  signing_key:
135
135
  specification_version: 3
136
- summary: Interactive Ruby Tools - Improved irb and rails console with a lot of easy and powerful tools.
136
+ summary: Interactive Ruby Tools - Very improved irb and Rails Console with a lot of cool features.
137
137
  test_files: []
138
138