show_method 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dmitry Vorotilin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ # Show me the method
2
+
3
+ This tiny gem can pretty easy open the method you need in your favorite text
4
+ editor. I found myself spending a lot of time in rails console and I often have
5
+ to see how some methods look like and with this gem I can do it easily:
6
+
7
+ User.show_method(:find_by_sql)
8
+
9
+ or even with short alias `s`:
10
+
11
+ ActiveRecord::ConnectionAdapters::Column.s :string_to_time
12
+
13
+ Nothing more, enjoy!
@@ -0,0 +1,34 @@
1
+ module ShowMethod
2
+ class Error < StandardError; end
3
+
4
+ def self.command
5
+ editor = ENV['EDITOR'] || 'vi'
6
+ command = case editor
7
+ when 'mvim', 'vim', 'vi', 'emacs', 'nano'
8
+ '%{editor} +%{line} %{file}'
9
+ when 'mate'
10
+ '%{editor} -l %{line} %{file}'
11
+ when 'subl'
12
+ '%{editor} %{file}:%{line}'
13
+ end
14
+ raise Error, "Editor #{editor} isn't supported" unless command
15
+ [command, editor]
16
+ end
17
+
18
+ def self.method_location(object, name)
19
+ file, line = object.method(name).source_location
20
+ raise Error, "Method `#{name}` is written on C language" unless file
21
+ [file, line]
22
+ end
23
+
24
+ def show_method(name)
25
+ file, line = ShowMethod.method_location(self, name)
26
+ command, editor = ShowMethod.command
27
+ system(command % { :editor => editor, :line => line, :file => file })
28
+ rescue ShowMethod::Error => error
29
+ warn error.message
30
+ end
31
+ alias :s :show_method
32
+ end
33
+
34
+ Object.send :include, ShowMethod
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'show_method'
3
+ gem.version = '1.0'
4
+ gem.authors = ['Dmitry Vorotilin']
5
+ gem.email = ['d.vorotilin@gmail.com']
6
+ gem.description = 'Show the method you need in your favorite editor'
7
+ gem.summary = 'Show you method in an editor'
8
+ gem.homepage = 'http://github.com/route/show_method'
9
+
10
+ gem.files = %w(LICENSE.txt README.md lib/show_method.rb show_method.gemspec)
11
+ gem.require_paths = ['lib']
12
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: show_method
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dmitry Vorotilin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-01 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Show the method you need in your favorite editor
15
+ email:
16
+ - d.vorotilin@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE.txt
22
+ - README.md
23
+ - lib/show_method.rb
24
+ - show_method.gemspec
25
+ homepage: http://github.com/route/show_method
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.8.25
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: Show you method in an editor
49
+ test_files: []