Permalink
Browse files

Add shortcut syntax for (instance) methods in edit

  • Loading branch information...
1 parent 132a9c2 commit 4834e827550fb3e0224fa8e863e9bb8761698e85 @flori committed Aug 27, 2012
Showing with 21 additions and 11 deletions.
  1. +1 −1 Rakefile
  2. +16 −6 lib/utils/editor.rb
  3. +4 −4 utils.gemspec
View
@@ -15,7 +15,7 @@ GemHadar do
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', '.AppleDouble', 'tags'
readme 'README.rdoc'
- dependency 'tins', '~>0.5.0'
+ dependency 'tins', '~>0.5.3'
dependency 'term-ansicolor', '~>1.0'
dependency 'dslkit', '~>0.2.10'
dependency 'pry-editline'
View
@@ -1,18 +1,29 @@
require 'tins/xt/full'
+require 'tins/deep_const_get'
module Utils
class Editor
- FILE_LINENUMBER_REGEXP = /^\s*([^:]+):(\d+)/
+ FILE_LINENUMBER_REGEXP = /\A\s*([^:]+):(\d+)/
+ CLASS_METHOD_REGEXP = /\A([A-Z][\w:]+)([#.])(\S+)/
module SourceLocationExtension
+ include Tins::DeepConstGet
+
def source_location
filename = nil
linenumber = nil
if respond_to?(:to_str)
- if (string = to_str) =~ FILE_LINENUMBER_REGEXP
+ string = to_str
+ case string
+ when FILE_LINENUMBER_REGEXP
filename = $1
linenumber = $2.to_i
- [ $1, linenumber ]
+ when CLASS_METHOD_REGEXP
+ klassname = $1
+ method_kind = $2 == '#' ? :instance_method : :method
+ methodname = $3
+ filename, linenumber =
+ deep_const_get(klassname).__send__(method_kind, methodname).source_location
else
filename = string
end
@@ -106,9 +117,8 @@ def edit(*filenames)
then
edit_source_location(source_location) ||
edit_file(expand_globs(source_location[0, 1]))
- else
- filenames =
- expand_globs(filenames.map(&:source_location).map(&:first))
+ elsif source_locations = filenames.map(&:source_location).compact.full?
+ filenames = expand_globs(source_locations.map(&:first))
edit_file(*filenames)
end
end
View
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Florian Frank"]
- s.date = "2012-08-10"
+ s.date = "2012-08-27"
s.description = "This ruby gem provides some useful command line utilities"
s.email = "flori@ping.de"
s.executables = ["chroot-exec", "chroot-libs", "classify", "discover", "edit", "edit_wait", "enum", "errf", "git-empty", "myex", "number_files", "path", "probe", "same_files", "search", "sedit", "sshscreen", "strip_spaces", "unquarantine_apps", "untest", "utils-install-config", "utils-utilsrc", "vacuum_firefox_sqlite", "xmp"]
@@ -23,20 +23,20 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<gem_hadar>, ["~> 0.1.8"])
- s.add_runtime_dependency(%q<tins>, ["~> 0.5.0"])
+ s.add_runtime_dependency(%q<tins>, ["~> 0.5.3"])
s.add_runtime_dependency(%q<term-ansicolor>, ["~> 1.0"])
s.add_runtime_dependency(%q<dslkit>, ["~> 0.2.10"])
s.add_runtime_dependency(%q<pry-editline>, [">= 0"])
else
s.add_dependency(%q<gem_hadar>, ["~> 0.1.8"])
- s.add_dependency(%q<tins>, ["~> 0.5.0"])
+ s.add_dependency(%q<tins>, ["~> 0.5.3"])
s.add_dependency(%q<term-ansicolor>, ["~> 1.0"])
s.add_dependency(%q<dslkit>, ["~> 0.2.10"])
s.add_dependency(%q<pry-editline>, [">= 0"])
end
else
s.add_dependency(%q<gem_hadar>, ["~> 0.1.8"])
- s.add_dependency(%q<tins>, ["~> 0.5.0"])
+ s.add_dependency(%q<tins>, ["~> 0.5.3"])
s.add_dependency(%q<term-ansicolor>, ["~> 1.0"])
s.add_dependency(%q<dslkit>, ["~> 0.2.10"])
s.add_dependency(%q<pry-editline>, [">= 0"])

0 comments on commit 4834e82

Please sign in to comment.