editorkicker 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,16 @@
1
1
  releases:
2
2
 
3
+ - version: 0.2.0
4
+ date: 2008-09-15
5
+ enhancements:
6
+ - |
7
+ Support ENV['EDITOR_KICKER_INCLUDE'] and ENV['EDITOR_KICKER_EXCLUDE']
8
+ to specify include or exclude path explicitly.
9
+
10
+ ## bash
11
+ export EDITOR_KICKER_INCLUDE='/usr/lib/ruby/site-ruby/1.8'
12
+ export EDITOR_KICKER_EXCLUDE='/usr/lib/ruby:./'
13
+
3
14
  - version: 0.1.0
4
15
  date: 2008-07-19
5
16
  enhancements:
data/README.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  = README.txt for EditorKicker
2
2
 
3
- Release: 0.1.0
3
+ Release: 0.2.0
4
4
 
5
5
  http://editorkicker.rubyforge.org/
6
6
  http://rubyforge.org/projects/editorkicker/
@@ -28,9 +28,9 @@ You must install CGI-Exception library, too.
28
28
  $ sudo gem install editorkicker
29
29
  ## or
30
30
  $ cd /tmp
31
- $ wget http://rubyforge.org/projects/editorkicker/.../editorkicker-XXX.tar.gz
32
- $ tar xzf editorkicker-XXX.tar.gz
33
- $ cd editorkicker-XXX/
31
+ $ wget http://rubyforge.org/projects/editorkicker/.../editorkicker-0.2.0.tar.gz
32
+ $ tar xzf editorkicker-0.2.0.tar.gz
33
+ $ cd editorkicker-0.2.0/
34
34
  $ sudo ruby install.rb
35
35
 
36
36
  ## install cgi-exception
@@ -42,8 +42,8 @@ You must install CGI-Exception library, too.
42
42
  $ cd cgi-exception-XXX/
43
43
  $ sudo ruby install.rb
44
44
 
45
- It is not recommended to install by RubyGems, because 'require rubygems'
46
- is an heavy-weight operation for CGI.
45
+ It is not recommended to install libraries by RubyGems, because
46
+ 'require rubygems' is an heavy-weight operation for CGI.
47
47
 
48
48
 
49
49
 
@@ -60,6 +60,12 @@ ATTENTION! Don't forget to call 'M-x server-start' if you're Emacs user.
60
60
  Setting of $EDITOR_KICKER is optional. If $EDITOR_KICKER is not set,
61
61
  EditorKicker will detect TextMate or Emacs automatically.
62
62
 
63
+ In addition, $EDITOR_KICKER_INCLUDE and $EDITOR_KICKER_EXCLUDE represents
64
+ include and exclude path to find file.
65
+
66
+ $ export EDITOR_KICKER_EXCLUDE='/usr:/opt:./vendor/plugins'
67
+
68
+
63
69
  (for CGI/mod_ruby)
64
70
 
65
71
  #!/usr/bin/env ruby
@@ -75,7 +81,14 @@ EditorKicker will detect TextMate or Emacs automatically.
75
81
  ## for Emacs
76
82
  emacsclient = '/Applications/Emacs.app/Contents/MacOS/bin/emacsclient'
77
83
  ENV['EDITOR_KICKER'] = "#{emacsclient} -n -s /tmp/emacs501/server +%s '%s'"
84
+ ## for NetBeans
85
+ netbeans = "#{ENV['HOME']}/netbeans-6.1/bin/netbeans"
86
+ ENV['EDITOR_KICKER'] = "#{netbeans} --open %2$s:%1$s"
78
87
  end
88
+
89
+ ## you can specify include and/or exclude path to find file.
90
+ ENV['EDITOR_KICKER_INCLUDE'] = '/usr/local/lib/ruby/1.8/site_ruby:./lib'
91
+ ENV['EDITOR_KICKER_EXCLUDE'] = '/usr/local/lib:/opt/local/lib'
79
92
 
80
93
  cgi = CGI.new
81
94
  print cgi.header
@@ -87,7 +100,7 @@ If you're Emacs user, you have to change owner of socket file
87
100
 
88
101
  ### assume that CGI script is executed by 'daemon' user.
89
102
  ### ('/tmp/emacs501/server' will be created by M-x server-strart)
90
- $ sudo chown -R daemon /tmp/emacs501/server
103
+ $ sudo chown -R daemon /tmp/emacs501
91
104
 
92
105
 
93
106
 
@@ -105,7 +118,7 @@ Solution:
105
118
 
106
119
  Type 'M-x server start' in your Emacs.
107
120
 
108
- In addition if you are CGI user, set $EDITOR_KICKER environment variable
121
+ In addition if you are CGI user, set ENV['EDITOR_KICKER'] environment variable
109
122
  to "emacsclient -n -s /tmp/emacs501/server +%s '%s'" in your CGI script
110
123
  to specify socket file by '-s' option.
111
124
  (Notice that '-s' option of emacsclient is available from Emacs 22.)
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
3
  ###
4
- ### $Release: 0.1.0 $
4
+ ### $Release: 0.2.0 $
5
5
  ### Copyright 2008 kuwata-lab.com all rights reserved.
6
6
  ###
7
7
 
@@ -13,7 +13,7 @@ spec = Gem::Specification.new do |s|
13
13
  s.author = "makoto kuwata"
14
14
  s.email = "kwa(at)kuwata-lab.com"
15
15
  s.rubyforge_project = 'editorkicker'
16
- s.version = "0.1.0"
16
+ s.version = "0.2.0"
17
17
  s.platform = Gem::Platform::RUBY
18
18
  s.homepage = "http://editorkicker.rubyforge.org/"
19
19
  s.summary = "a pretty tool to invoke your favorite editor when error raised"
@@ -28,6 +28,7 @@ spec = Gem::Specification.new do |s|
28
28
  files += %W[README.txt CHANGES.txt MIT-LICENSE setup.rb #{s.name}.gemspec]
29
29
  files += Dir.glob('plugin/**/*')
30
30
  #files += Dir.glob('doc-api/**/*')
31
+ files += Dir.glob('spec/**/*')
31
32
  s.files = files
32
33
  end
33
34
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev$
3
- ## $Release: 0.1.0 $
3
+ ## $Release: 0.2.0 $
4
4
  ## Copyright 2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -27,11 +27,28 @@ module EditorKicker
27
27
  @@handler = handler
28
28
  end
29
29
 
30
+
31
+ def self.writable_check
32
+ return ExceptionHandler.writable_check
33
+ end
34
+ def self.writable_check=(flag)
35
+ ExceptionHandler.writable_check = flag
36
+ end
37
+
38
+
30
39
  class ExceptionHandler
31
40
 
41
+ @@writable_check = false # don't check writable permission
42
+ def self.writable_check
43
+ @@writable_check
44
+ end
45
+ def self.writable_check=(flag)
46
+ @@writable_check = flag
47
+ end
48
+
32
49
  def initialize
33
50
  @kicker = self # you can set Proc object to @kicker
34
- @writable_check = false
51
+ @writable_check = @@writable_check
35
52
  end
36
53
 
37
54
  attr_accessor :command, :kicker, :writable_check
@@ -46,12 +63,13 @@ module EditorKicker
46
63
  def detect_location(ex, backtrace=nil)
47
64
  filepath = linenum = nil
48
65
  backtrace ||= ex.backtrace
66
+ @include, @exclude = detect_paths()
49
67
  if backtrace && !backtrace.empty?
50
68
  tuple = nil
51
69
  if backtrace.find {|str| tuple = get_location(str) }
52
70
  filepath, linenum = tuple
53
71
  end
54
- #elsif ex.is_a?(SyntaxEx)
72
+ #elsif ex.is_a?(SyntaxError)
55
73
  # if ex.to_s =~ /^(.+):(\d+): syntax error,/
56
74
  # filepath, linenum = $1, $2.to_i
57
75
  # end
@@ -61,11 +79,21 @@ module EditorKicker
61
79
  return filepath, linenum
62
80
  end
63
81
 
82
+ def _match_to(filename, path_list)
83
+ return path_list.any? {|path|
84
+ filename[0, path.length] == path }
85
+ end
86
+
64
87
  ## get filepath and linenum from string
65
88
  def get_location(str)
66
- return nil if str !~ /^(.+):(\d+)(:in `.+'|$)/
67
- return nil if @writable_check && !File.writable?($1)
68
- return [$1, $2.to_i]
89
+ return nil unless str =~ /^(.+):(\d+)(:in `.+'|$)/
90
+ filename, linenum = $1, $2.to_i
91
+ arr = [filename, linenum]
92
+ return nil unless File.exist?(filename)
93
+ return arr if _match_to(filename, @include)
94
+ return nil if _match_to(filename, @exclude)
95
+ return nil if @writable_check && !File.writable?(filename)
96
+ return arr
69
97
  end
70
98
 
71
99
  ## detect command to invoke editor
@@ -77,6 +105,15 @@ module EditorKicker
77
105
  return "emacsclient -n +%s '%s'"
78
106
  end
79
107
 
108
+ def detect_paths
109
+ sep = File::PATH_SEPARATOR
110
+ s = ENV['EDITOR_KICKER_INCLUDE']
111
+ include = s ? s.split(sep) : []
112
+ s = ENV['EDITOR_KICKER_EXCLUDE']
113
+ exclude = s ? s.split(sep) : []
114
+ return include, exclude
115
+ end
116
+
80
117
  ## open file with editor
81
118
  def kick(filepath, linenum)
82
119
  if File.exists?(filepath)
@@ -94,7 +131,7 @@ module EditorKicker
94
131
  end
95
132
 
96
133
  def log(message)
97
- $stderr.puts "** [EditorKicker] #{message}"
134
+ $stderr << "** [EditorKicker] #{message}\n"
98
135
  end
99
136
 
100
137
  end
@@ -1,5 +1,16 @@
1
1
  releases:
2
2
 
3
+ - version: 0.2.0
4
+ date: 2008-09-15
5
+ enhancements:
6
+ - |
7
+ Support ENV['EDITOR_KICKER_INCLUDE'] and ENV['EDITOR_KICKER_EXCLUDE']
8
+ to specify include or exclude path explicitly.
9
+
10
+ ## bash
11
+ export EDITOR_KICKER_INCLUDE='/usr/lib/ruby/site-ruby/1.8'
12
+ export EDITOR_KICKER_EXCLUDE='/usr/lib/ruby:./'
13
+
3
14
  - version: 0.1.0
4
15
  date: 2008-07-19
5
16
  enhancements:
@@ -2,7 +2,7 @@
2
2
  EditorKicker plugin for Ruby on Rails
3
3
  =====================================
4
4
 
5
- Release: 0.1.0
5
+ Release: 0.2.0
6
6
 
7
7
 
8
8
  About
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev$
3
- ## $Release: 0.1.0 $
3
+ ## $Release: 0.2.0 $
4
4
  ## Copyright 2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -17,10 +17,13 @@ if defined?(RAILS_ENV) && RAILS_ENV == 'development'
17
17
 
18
18
  class RailsExceptionHandler < ExceptionHandler
19
19
 
20
- def initialize(*args)
21
- super
22
- self.writable_check = true
23
- end
20
+ self.writable_check = true
21
+ #--
22
+ #def initialize(*args)
23
+ # super
24
+ # @writable_check = true
25
+ #end
26
+ #++
24
27
 
25
28
  ## detect filepath and linenum
26
29
  def detect_location(ex, backtrace=nil)
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev$
3
- ## $Release: 0.1.0 $
3
+ ## $Release: 0.2.0 $
4
4
  ## Copyright 2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -27,11 +27,28 @@ module EditorKicker
27
27
  @@handler = handler
28
28
  end
29
29
 
30
+
31
+ def self.writable_check
32
+ return ExceptionHandler.writable_check
33
+ end
34
+ def self.writable_check=(flag)
35
+ ExceptionHandler.writable_check = flag
36
+ end
37
+
38
+
30
39
  class ExceptionHandler
31
40
 
41
+ @@writable_check = false # don't check writable permission
42
+ def self.writable_check
43
+ @@writable_check
44
+ end
45
+ def self.writable_check=(flag)
46
+ @@writable_check = flag
47
+ end
48
+
32
49
  def initialize
33
50
  @kicker = self # you can set Proc object to @kicker
34
- @writable_check = false
51
+ @writable_check = @@writable_check
35
52
  end
36
53
 
37
54
  attr_accessor :command, :kicker, :writable_check
@@ -46,12 +63,13 @@ module EditorKicker
46
63
  def detect_location(ex, backtrace=nil)
47
64
  filepath = linenum = nil
48
65
  backtrace ||= ex.backtrace
66
+ @include, @exclude = detect_paths()
49
67
  if backtrace && !backtrace.empty?
50
68
  tuple = nil
51
69
  if backtrace.find {|str| tuple = get_location(str) }
52
70
  filepath, linenum = tuple
53
71
  end
54
- #elsif ex.is_a?(SyntaxEx)
72
+ #elsif ex.is_a?(SyntaxError)
55
73
  # if ex.to_s =~ /^(.+):(\d+): syntax error,/
56
74
  # filepath, linenum = $1, $2.to_i
57
75
  # end
@@ -61,11 +79,21 @@ module EditorKicker
61
79
  return filepath, linenum
62
80
  end
63
81
 
82
+ def _match_to(filename, path_list)
83
+ return path_list.any? {|path|
84
+ filename[0, path.length] == path }
85
+ end
86
+
64
87
  ## get filepath and linenum from string
65
88
  def get_location(str)
66
- return nil if str !~ /^(.+):(\d+)(:in `.+'|$)/
67
- return nil if @writable_check && !File.writable?($1)
68
- return [$1, $2.to_i]
89
+ return nil unless str =~ /^(.+):(\d+)(:in `.+'|$)/
90
+ filename, linenum = $1, $2.to_i
91
+ arr = [filename, linenum]
92
+ return nil unless File.exist?(filename)
93
+ return arr if _match_to(filename, @include)
94
+ return nil if _match_to(filename, @exclude)
95
+ return nil if @writable_check && !File.writable?(filename)
96
+ return arr
69
97
  end
70
98
 
71
99
  ## detect command to invoke editor
@@ -77,6 +105,15 @@ module EditorKicker
77
105
  return "emacsclient -n +%s '%s'"
78
106
  end
79
107
 
108
+ def detect_paths
109
+ sep = File::PATH_SEPARATOR
110
+ s = ENV['EDITOR_KICKER_INCLUDE']
111
+ include = s ? s.split(sep) : []
112
+ s = ENV['EDITOR_KICKER_EXCLUDE']
113
+ exclude = s ? s.split(sep) : []
114
+ return include, exclude
115
+ end
116
+
80
117
  ## open file with editor
81
118
  def kick(filepath, linenum)
82
119
  if File.exists?(filepath)
@@ -94,7 +131,7 @@ module EditorKicker
94
131
  end
95
132
 
96
133
  def log(message)
97
- $stderr.puts "** [EditorKicker] #{message}"
134
+ $stderr << "** [EditorKicker] #{message}\n"
98
135
  end
99
136
 
100
137
  end
@@ -0,0 +1,124 @@
1
+ ###
2
+ ### $Rev$
3
+ ### $Release: 0.2.0 $
4
+ ### Copyright 2008 kuwata-lab.com all rights reserved.
5
+ ### MIT License
6
+ ###
7
+
8
+ dir = File.dirname(File.dirname(File.expand_path(__FILE__)))
9
+ $:.unshift File.join(dir, "spec")
10
+ $:.unshift File.join(dir, "lib")
11
+
12
+ require 'rubygems'
13
+ require 'spec'
14
+ require 'editor_kicker'
15
+
16
+ def `(str) #`
17
+ $stdout << str
18
+ end
19
+
20
+ ENV['EDITOR_KICKER'] = '<kicked: %s:%s>'
21
+
22
+
23
+ class String
24
+ def write(arg)
25
+ self << arg
26
+ end
27
+ def puts(arg)
28
+ self << arg
29
+ self << arg unless arg[-1] == ?\n
30
+ end
31
+ end
32
+
33
+ def dummy_stdio
34
+ begin
35
+ $stdout = ''
36
+ $stderr = ''
37
+ yield $stdout, $stderr
38
+ ensure
39
+ $stdout = STDOUT
40
+ $stderr = STDERR
41
+ end
42
+ end
43
+
44
+
45
+ ## TODO: change to portable data
46
+ err = ArgumentError.new('***dummy***')
47
+ backtrace = [
48
+ "/usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.4/lib/spec/example/example_group_methods.rb:46:in `module_eval'",
49
+ "/usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.4/lib/spec/example/example_group_methods.rb:46:in `describe'",
50
+ "./spec/editor_kicker_spec.rb:9:in `raise_error'",
51
+ "./spec/editor_kicker_spec.rb:51",
52
+ "/usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.4/lib/spec/extensions/class.rb:14:in `instance_eval'",
53
+ ]
54
+ err.set_backtrace(backtrace)
55
+
56
+
57
+ describe "EditorKicker" do
58
+
59
+ it "kicks command with filename and linenum" do
60
+ dummy_stdio do |stdout, stderr|
61
+ EditorKicker.handle_exception(err)
62
+ stdout.should == "<kicked: 46:/usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.4/lib/spec/example/example_group_methods.rb>"
63
+ stderr.should == "** [EditorKicker] <kicked: 46:/usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.4/lib/spec/example/example_group_methods.rb>\n"
64
+ end
65
+ end
66
+
67
+ it "does nothing when file is not found." do
68
+ err.set_backtrace([])
69
+ dummy_stdio do |stdout, stderr|
70
+ EditorKicker.handle_exception(err)
71
+ stdout.should == ''
72
+ stderr.should == ''
73
+ end
74
+ err.set_backtrace(backtrace)
75
+ end
76
+
77
+ it "ignores unwritable file when check_writable is true" do
78
+ val = EditorKicker.handler.writable_check
79
+ EditorKicker.handler.writable_check = true
80
+ begin
81
+ dummy_stdio do |stdout, stderr|
82
+ EditorKicker.handle_exception(err)
83
+ stdout.should == "<kicked: 9:./spec/editor_kicker_spec.rb>"
84
+ stderr.should == "** [EditorKicker] <kicked: 9:./spec/editor_kicker_spec.rb>\n"
85
+ end
86
+ ensure
87
+ EditorKicker.handler.writable_check = val
88
+ end
89
+ end
90
+
91
+ it "selects file not in ENV['EDITOR_KICKER_EXCLUDE']" do
92
+ dummy_stdio do |stdout, stderr|
93
+ ENV['EDITOR_KICKER_EXCLUDE'] = '/usr/lib:/usr/local/lib:/opt/local'
94
+ EditorKicker.handle_exception(err)
95
+ stdout.should == "<kicked: 9:./spec/editor_kicker_spec.rb>"
96
+ stderr.should == "** [EditorKicker] <kicked: 9:./spec/editor_kicker_spec.rb>\n"
97
+ end
98
+ end
99
+
100
+ it "selects file in ENV['EDITOR_KICKER_INCLUDE']" do
101
+ dummy_stdio do |stdout, stderr|
102
+ ENV['EDITOR_KICKER_INCLUDE'] = '/usr/local/lib/ruby/gems/1.8/'
103
+ ENV['EDITOR_KICKER_EXCLUDE'] = '/usr/lib:/usr/local/lib:/opt/local'
104
+ EditorKicker.handle_exception(err)
105
+ stdout.should == "<kicked: 46:/usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.4/lib/spec/example/example_group_methods.rb>"
106
+ stderr.should == "** [EditorKicker] <kicked: 46:/usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.4/lib/spec/example/example_group_methods.rb>\n"
107
+ end
108
+ end
109
+
110
+ it "does nothing when all file are excluded" do
111
+ dummy_stdio do |stdout, stderr|
112
+ ENV['EDITOR_KICKER_INCLUDE'] = nil
113
+ ENV['EDITOR_KICKER_EXCLUDE'] = '/usr:./'
114
+ EditorKicker.handle_exception(err)
115
+ stdout.should == ''
116
+ stderr.should == ''
117
+ end
118
+ end
119
+
120
+ ENV['EDITOR_KICKER_INCLUDE'] = nil
121
+ ENV['EDITOR_KICKER_EXCLUDE'] = nil
122
+
123
+
124
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: editorkicker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - makoto kuwata
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-20 00:00:00 +09:00
12
+ date: 2008-09-15 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -36,6 +36,7 @@ files:
36
36
  - plugin/rails/editorkicker/lib/editor_kicker.rb
37
37
  - plugin/rails/editorkicker/MIT-LICENSE
38
38
  - plugin/rails/editorkicker/README.txt
39
+ - spec/editor_kicker_spec.rb
39
40
  has_rdoc: false
40
41
  homepage: http://editorkicker.rubyforge.org/
41
42
  post_install_message: