read_source 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a794d573c3b86ef51a54aceff6519fc1e6ff1768
4
+ data.tar.gz: 7510310d465840fe9819a5443358454a3c0140a6
5
+ SHA512:
6
+ metadata.gz: 86a075da435a0fc7072d0db4b8bb844805e4e74b0595c4312c3e84b81fb05f08234fc1f921265895a0ec8b75ef35a1b9bb7a8f8f43b0b25eaf6f1456e0221ad8
7
+ data.tar.gz: 0372d7ded8fce1cfb45b30ccdd2a5d1030bad5ac3c28f1b556a3f2e93a46462196d0220dc1e1c84d3ae85b6b6345e125a7bf618b299e74d5157f5267499018e5
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in read_source.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Daniel P. Clark
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # ReadSource
2
+
3
+ Haha! This little gem was a distraction from my duties but I had to make it.
4
+
5
+ At first I was going to name it VIM-something because it lets you open the source code for a method in your VIM editor.
6
+ But as I thought about it I discovered it would be so simple to have Ruby read the method for itself. *Yes
7
+ I know there is the `method_source` gem that has been around forever.* But if I'm writing a VIM method
8
+ to read the source file I might as well throw in a method to string function.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'read_source'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install read_source
25
+
26
+ ## Usage
27
+
28
+ This gem adds instance methods to the Method and UnboundMethod objects.
29
+
30
+ * `Method#vim`
31
+ * `Method#read_source`
32
+ * `UnboundMethod#vim`
33
+ * `UnboundMethod#read_source`
34
+
35
+ Currently this assumes VIM is in your executable path. Future versions of this gem will be more
36
+ accommodating to where VIM may be.
37
+
38
+ ```ruby
39
+ require 'read_source'
40
+
41
+ require 'pathname'
42
+ puts Pathname.instance_method(:root?).read_source
43
+ #def root?
44
+ # !!(chop_basename(@path) == nil && /#{SEPARATOR_PAT}/o =~ @path)
45
+ #end
46
+
47
+ require 'prime'
48
+ puts Integer.method(:each_prime).read_source
49
+ #def Integer.each_prime(ubound, &block) # :yields: prime
50
+ # Prime.each(ubound, &block)
51
+ #end
52
+ ```
53
+
54
+ You can type `vim` instead of the `read_source` method on either the `Method` or `UnboundMethod` objects
55
+ and it will close irb (or rails console) and open the source code file in VIM at the exact line where
56
+ the method is defined.
57
+
58
+ ---
59
+
60
+ In case you didn't know Ruby already has a bunch of nice methods on `Method` and `UnboundMethod`
61
+ that are quite helpful.
62
+
63
+ ```ruby
64
+ require 'read_source'
65
+ require 'pathname'
66
+
67
+ Pathname.method(:autoload).owner
68
+ # => Module
69
+ Pathname.method(:pwd).owner
70
+ # => #<Class:Pathname>
71
+ Pathname.instance_method(:root?).source_location
72
+ # => ["/home/danielpclark/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/pathname.rb", 208]
73
+ ```
74
+
75
+ ---
76
+
77
+ NOTES:
78
+ * If the source code is written in C then the `read_source` and `vim` methods only return nil.
79
+ * If the file is in `GEM_HOME` path then VIM opens it in read only mode.
80
+
81
+ ## Development
82
+
83
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
84
+
85
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
86
+
87
+ ## Contributing
88
+
89
+ Bug reports and pull requests are welcome on GitHub at https://github.com/danielpclark/read_source.
90
+
91
+
92
+ ## License
93
+
94
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
95
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module ReadSource
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ require "read_source/version"
2
+
3
+ module ReadSource
4
+ module VimSource
5
+ def vim
6
+ file, line_num = send :source_location
7
+ read_only = !!/#{ENV["GEM_HOME"]}/.match(file) ? "-M" : ""
8
+ exec("vim %s +%s %s" % [read_only, line_num, file]) if file
9
+ end
10
+ end
11
+ module ReadSource
12
+ def read_source
13
+ file, line_num = send :source_location
14
+ return unless file
15
+ readlines = IO.readlines(file)
16
+ source = readlines[line_num-1]
17
+ indent = /\A[[:space:]]*/.match(source).to_s.length
18
+ source = source[indent..-1]
19
+ readlines[line_num..-1].each do |l|
20
+ source += l[indent..-1]
21
+ if indent == /\A[[:space:]]*/.match(l).to_s.length
22
+ break source
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ ::Method.include VimSource
29
+ ::Method.include ReadSource
30
+ ::UnboundMethod.include VimSource
31
+ ::UnboundMethod.include ReadSource
32
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'read_source/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "read_source"
8
+ spec.version = ReadSource::VERSION
9
+ spec.authors = ["Daniel P. Clark"]
10
+ spec.email = ["6ftdan@gmail.com"]
11
+
12
+ spec.summary = %q{Read method source to String or in your VIM editor.}
13
+ spec.description = %q{Read method source to String or in your VIM editor!}
14
+ spec.homepage = "https://github.com/danielpclark/read_source"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: read_source
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel P. Clark
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Read method source to String or in your VIM editor!
42
+ email:
43
+ - 6ftdan@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/read_source.rb
55
+ - lib/read_source/version.rb
56
+ - read_source.gemspec
57
+ homepage: https://github.com/danielpclark/read_source
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.6.4
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Read method source to String or in your VIM editor.
81
+ test_files: []