subl 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd9574df749d2719ed6c33652806132b9b98759a
4
- data.tar.gz: 4f5825cfae6f95eb2c0dc318278b574cb768ae15
3
+ metadata.gz: 4ecb50de04626795261924f898604fade14e3641
4
+ data.tar.gz: 511920c22c8ebc25657183256c4b34f9b9e810d8
5
5
  SHA512:
6
- metadata.gz: b3f9a03f55b1640b527f294adeb7cd8f94a3ea7c156ab2eff80d0f158a3c018cc88961b19c5f3a99bd6a4fc9c4c5d729b44dad5001fc161338980853ea0064b4
7
- data.tar.gz: a4f456a4896d5fa136c128f31ea269fbea7fa8590ebf32924c731fa8513f1a691a800dceb0485432971d8f4d5aee7bdc24bb4ed44d56a13ff837311a1109218e
6
+ metadata.gz: 3600c272b3b43a61ac1e7d1bb84b5994e23b7f4feb37bee44d7d75ba93ea75d7b576d737942c99e1ecd046e0d666fa812df1c2dfbbd7e2b9c284b3dc9ea8d0fc
7
+ data.tar.gz: da93eacdb572456c4e142c53bab9f1a0b39a577b7675f572ab778aeb874fc60a97f0f7ef7a6299998955b89c7cac8080c33cb69d5220a4cb65e27f5ca58475a1
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ *.gem
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
@@ -0,0 +1,13 @@
1
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
+ Version 2, December 2004
3
+
4
+ Copyright (C) 2014 Johannes Opper <johannes.opper@gmail.com>
5
+
6
+ Everyone is permitted to copy and distribute verbatim or modified
7
+ copies of this license document, and changing it is allowed as long
8
+ as the name is changed.
9
+
10
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
+
13
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
data/README.md CHANGED
@@ -1,28 +1,22 @@
1
1
  # Subl
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/subl`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Provides `subl` command within `irb` or `pry`.
6
4
 
7
5
  ## Installation
8
6
 
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'subl'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install subl
7
+ Add `require 'subl'` to your `~/.irbrc` or `~/.pryrc`.
22
8
 
23
9
  ## Usage
24
10
 
25
- TODO: Write usage instructions here
11
+ ```ruby
12
+ subl '/path/to/file' # => open the given file path
13
+ subl 'foo.rb', 23 # => open foo.rb on line 23
14
+ subl :rake # => open gem
15
+ subl Foo.method(:bar) # => open source_location of the given method
16
+ subl Foo # => open class/module definition
17
+ MyClass.subl :bar # => open method definition
18
+ MyClass.subl /baz/ # => open first matching method definition
19
+ ```
26
20
 
27
21
  ## Development
28
22
 
@@ -30,7 +24,6 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
30
24
 
31
25
  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).
32
26
 
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/subl.
27
+ ## Contributions
36
28
 
29
+ Thanks @janosch-x for the additions!
@@ -1,11 +1,11 @@
1
1
  module Subl
2
2
  class Command
3
- attr_accessor :candidate, :line, :origial_binding
3
+ attr_accessor :candidate, :line, :original_binding
4
4
 
5
5
  def initialize(candidate:, line: nil, binding: nil)
6
- @candidate = candidate
7
- @line = line
8
- @origial_binding = binding
6
+ self.candidate = candidate
7
+ self.line = line
8
+ self.original_binding = binding
9
9
  end
10
10
 
11
11
  def call
@@ -21,13 +21,21 @@ module Subl
21
21
  def path
22
22
  case candidate
23
23
  when String then candidate
24
- when Symbol then resolve_gem(candidate.to_s)
24
+ when Symbol then resolve_symbol(candidate)
25
25
  when Class, Module then resolve_class(candidate)
26
26
  when Method then resolve_method(candidate)
27
27
  when Regexp then resolve_regexp(candidate)
28
28
  end
29
29
  end
30
30
 
31
+ def resolve_symbol(name)
32
+ if original_binding.class.in?([Object, NilClass])
33
+ resolve_gem(name)
34
+ else
35
+ resolve_regexp(/^#{name}$/)
36
+ end
37
+ end
38
+
31
39
  def resolve_method(m)
32
40
  loc = Array(m.source_location)
33
41
  self.line ||= loc.last
@@ -50,9 +58,9 @@ module Subl
50
58
  resolve_method(klass.instance_method(m))
51
59
  end
52
60
 
53
- def resolve_regexp(r)
54
- m = origial_binding.methods.grep(r).first or return
55
- resolve_method(origial_binding.method(m))
61
+ def resolve_regexp(regexp)
62
+ m = original_binding&.receiver.methods.grep(regexp).first or return
63
+ resolve_method(original_binding.receiver.method(m))
56
64
  end
57
65
 
58
66
  def resolve_gem(name)
@@ -1,3 +1,3 @@
1
1
  module Subl
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Opper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-15 00:00:00.000000000 Z
11
+ date: 2016-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -63,6 +63,7 @@ files:
63
63
  - ".rspec"
64
64
  - ".travis.yml"
65
65
  - Gemfile
66
+ - LICENSE.txt
66
67
  - README.md
67
68
  - Rakefile
68
69
  - bin/console
@@ -95,4 +96,3 @@ signing_key:
95
96
  specification_version: 4
96
97
  summary: Provides "subl" command within irb
97
98
  test_files: []
98
- has_rdoc: