method_match 0.0.10 → 0.0.11
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 +4 -4
- data/.watchr +2 -2
- data/lib/method_match.rb +5 -5
- data/lib/method_match/command_runner.rb +3 -2
- data/lib/method_match/matcher.rb +28 -19
- data/lib/method_match/name_extractor.rb +20 -5
- data/lib/method_match/pry.rb +22 -11
- data/lib/method_match/version.rb +1 -1
- data/spec/method_match/command_runner_spec.rb +11 -1
- data/spec/method_match/matcher_spec.rb +2 -1
- data/spec/method_match/name_extractor_spec.rb +73 -4
- data/spec/method_match/pry_spec.rb +22 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee873555b2c027ef3eec2bbd005abd93a019bd66
|
4
|
+
data.tar.gz: 07b5159a0c193903aa91aa2a3472b8e9418e144d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 081500d42959a52e57eca26a67374509f954d663cb00301ac6d5a92d4c60de3044dc02a7559bb5181bb8af52dfcec799156ab3cedd67beef34292d35d0c33287
|
7
|
+
data.tar.gz: f9d6e1bc2fb5683f36e718ea5598da8cd86239cc8d746be72301603f36557022e1d70bef2f91c240a72c15f58848d658e1bbe949ce919326ab4269d68b979564
|
data/.watchr
CHANGED
data/lib/method_match.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require "method_match/version"
|
2
2
|
|
3
3
|
module MethodMatch
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
Pry.setup
|
4
|
+
require 'method_match/matcher'
|
5
|
+
require 'method_match/pry'
|
6
|
+
require 'method_match/command_runner'
|
7
|
+
require 'method_match/name_extractor'
|
8
|
+
Pry.new.setup
|
9
9
|
end
|
@@ -9,9 +9,10 @@ module MethodMatch
|
|
9
9
|
require 'pathname'
|
10
10
|
if Pathname.new(@matcher.spec_name).file?
|
11
11
|
::Pry.run_command rspec_command
|
12
|
-
|
13
|
-
puts "Spec #{@matcher.spec_name} does not exist"
|
12
|
+
return true
|
14
13
|
end
|
14
|
+
puts "Spec #{@matcher.spec_name} does not exist"
|
15
|
+
false
|
15
16
|
end
|
16
17
|
|
17
18
|
def rspec_command
|
data/lib/method_match/matcher.rb
CHANGED
@@ -3,52 +3,61 @@ module MethodMatch
|
|
3
3
|
attr_accessor :name, :line, :spec_name
|
4
4
|
SPEC_MODE = 'spec'
|
5
5
|
CODE_MODE = 'code'
|
6
|
+
RUBY_FILETYPE = ".rb"
|
7
|
+
SPEC_FILE_ENDING = '_spec.rb'
|
8
|
+
METHOD_NAME_REGEX = /def\s(self\.(\w+)|\w+).*/
|
6
9
|
|
7
10
|
def initialize name, line
|
8
|
-
@name = NameExtractor.new( name ).
|
11
|
+
@name = NameExtractor.new( name ).final_name
|
9
12
|
@line = line
|
10
13
|
create_spec_name
|
11
14
|
end
|
12
15
|
|
13
16
|
def mode
|
14
|
-
|
17
|
+
set_mode unless @mode
|
15
18
|
@mode
|
16
19
|
end
|
17
20
|
|
18
21
|
def method_name
|
19
|
-
return nil if
|
22
|
+
return nil if spec?
|
20
23
|
@match = get_method_match
|
21
24
|
return nil unless @match
|
22
|
-
@match.match(
|
25
|
+
@match.match(METHOD_NAME_REGEX)[1]
|
23
26
|
end
|
24
27
|
|
25
28
|
def spec?
|
26
29
|
mode == SPEC_MODE
|
27
30
|
end
|
28
31
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
def create_spec_name
|
33
|
+
@spec_name = name.split(File::SEPARATOR)
|
34
|
+
@spec_name = if spec?
|
35
|
+
name
|
36
|
+
else
|
37
|
+
convert_code_to_spec name.split(File::SEPARATOR)
|
33
38
|
end
|
34
|
-
@mode = CODE_MODE
|
35
|
-
return false
|
36
39
|
end
|
37
40
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
@spec_name[0] = SPEC_MODE
|
44
|
-
@spec_name[-1].sub!('.rb', '_spec.rb')
|
45
|
-
@spec_name = @spec_name.join('/')
|
41
|
+
def convert_code_to_spec name
|
42
|
+
name[0] = SPEC_MODE
|
43
|
+
name.last.sub!(RUBY_FILETYPE, SPEC_FILE_ENDING)
|
44
|
+
name.join File::SEPARATOR
|
46
45
|
end
|
47
46
|
|
48
47
|
def get_method_match
|
49
|
-
File.readlines(name).first(line).reverse.grep(
|
48
|
+
File.readlines(name).first(line).reverse.grep(METHOD_NAME_REGEX).first
|
50
49
|
rescue LoadError
|
51
50
|
return nil
|
52
51
|
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def set_mode
|
56
|
+
@mode = if spec_name.first == SPEC_MODE
|
57
|
+
SPEC_MODE
|
58
|
+
else
|
59
|
+
CODE_MODE
|
60
|
+
end
|
61
|
+
end
|
53
62
|
end
|
54
63
|
end
|
@@ -1,18 +1,33 @@
|
|
1
1
|
module MethodMatch
|
2
2
|
class NameExtractor
|
3
3
|
|
4
|
+
attr_accessor :name
|
5
|
+
|
6
|
+
PWD = "pwd"
|
7
|
+
|
4
8
|
def initialize name
|
5
9
|
@name = name
|
6
10
|
end
|
7
11
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
def final_name
|
13
|
+
@name.slice! base_directory if project_path?
|
14
|
+
name
|
15
|
+
end
|
16
|
+
|
17
|
+
def project_path?
|
18
|
+
name.index( full_path ) && name.index( full_path ).zero?
|
12
19
|
end
|
13
20
|
|
14
21
|
def pwd
|
15
|
-
`
|
22
|
+
`#{PWD}`
|
23
|
+
end
|
24
|
+
|
25
|
+
def full_path
|
26
|
+
pwd.chomp
|
27
|
+
end
|
28
|
+
|
29
|
+
def base_directory
|
30
|
+
full_path + File::SEPARATOR
|
16
31
|
end
|
17
32
|
end
|
18
33
|
end
|
data/lib/method_match/pry.rb
CHANGED
@@ -1,17 +1,28 @@
|
|
1
1
|
module MethodMatch
|
2
2
|
class Pry
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
PRY_PACKAGE = 'pry'
|
4
|
+
COMMAND_NAME = "rspec_method"
|
5
|
+
COMMAND_DESCRIPTION = "runs spec given name and line number"
|
6
|
+
|
7
|
+
def rspec_method
|
8
|
+
Proc.new do
|
9
|
+
create_command COMMAND_NAME, COMMAND_DESCRIPTION, &MethodMatch::Pry.new.command_proc
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def command_proc
|
14
|
+
Proc.new do
|
15
|
+
def process(*args)
|
16
|
+
CommandRunner.new(
|
17
|
+
Matcher.new(args[0], Integer(args[1]))
|
18
|
+
).run_command
|
13
19
|
end
|
14
|
-
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup
|
24
|
+
require PRY_PACKAGE
|
25
|
+
::Pry::CommandSet.new(&rspec_method).tap { |cmd| ::Pry::Commands.import cmd }
|
15
26
|
end
|
16
27
|
end
|
17
28
|
end
|
data/lib/method_match/version.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
|
2
3
|
describe MethodMatch::CommandRunner do
|
3
4
|
let(:matcher){MethodMatch::Matcher.new 'data/test_data/matcher.rb', 13}
|
4
5
|
let(:command_runner){MethodMatch::CommandRunner.new matcher}
|
@@ -11,4 +12,13 @@ describe MethodMatch::CommandRunner do
|
|
11
12
|
it { should eq('rspec spec/test_data/matcher_spec.rb -e \'.some_class_method\'')}
|
12
13
|
end
|
13
14
|
end
|
15
|
+
|
16
|
+
describe '#run_command' do
|
17
|
+
it 'requires pathname' do
|
18
|
+
require 'pathname'
|
19
|
+
command_runner.should_receive(:require).with('pathname')
|
20
|
+
command_runner.should_receive(:puts).with('Spec spec/test_data/matcher_spec.rb does not exist')
|
21
|
+
expect(command_runner.run_command).to be_false
|
22
|
+
end
|
23
|
+
end
|
14
24
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
|
2
3
|
describe MethodMatch::NameExtractor do
|
3
4
|
let(:extractor) do
|
4
5
|
e = MethodMatch::NameExtractor.new filename
|
@@ -6,16 +7,84 @@ describe MethodMatch::NameExtractor do
|
|
6
7
|
e
|
7
8
|
end
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
subject { MethodMatch::NameExtractor.new filename }
|
11
|
+
|
12
|
+
describe "#pwd" do
|
13
|
+
let(:filename) { '/home/othername/project/file.rb'}
|
14
|
+
it "executes pwd" do
|
15
|
+
subject.should_receive(:`).with 'pwd'
|
16
|
+
subject.pwd
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#final_name' do
|
21
|
+
subject { extractor.final_name }
|
11
22
|
context 'project dir' do
|
12
23
|
let(:filename) { '/home/name/project/file.rb'}
|
13
24
|
it { should eq( 'file.rb')}
|
14
25
|
end
|
15
26
|
|
16
|
-
context '
|
27
|
+
context 'somewhere else' do
|
17
28
|
let(:filename) { '/home/othername/project/file.rb'}
|
18
29
|
it { should eq( '/home/othername/project/file.rb')}
|
19
30
|
end
|
20
31
|
end
|
32
|
+
|
33
|
+
describe "#full_path" do
|
34
|
+
let(:extractor) do
|
35
|
+
e = MethodMatch::NameExtractor.new ''
|
36
|
+
e.stub(:pwd) { "/home/name/project\n"}
|
37
|
+
e
|
38
|
+
end
|
39
|
+
|
40
|
+
subject { extractor.full_path }
|
41
|
+
|
42
|
+
it "cleans line breaks of pwd" do
|
43
|
+
expect(subject).to eq('/home/name/project')
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#project_path?" do
|
49
|
+
subject { extractor.project_path? }
|
50
|
+
|
51
|
+
context "matching" do
|
52
|
+
let(:extractor) do
|
53
|
+
e = MethodMatch::NameExtractor.new ''
|
54
|
+
e.stub(:full_path) { "a" }
|
55
|
+
e.stub(:name) { "aaa" }
|
56
|
+
e
|
57
|
+
end
|
58
|
+
|
59
|
+
it "cleans line breaks of pwd" do
|
60
|
+
expect(subject).to be_true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "not matching" do
|
65
|
+
let(:extractor) do
|
66
|
+
e = MethodMatch::NameExtractor.new ''
|
67
|
+
e.stub(:full_path) { "a" }
|
68
|
+
e.stub(:name) { "bbb" }
|
69
|
+
e
|
70
|
+
end
|
71
|
+
|
72
|
+
it "cleans line breaks of pwd" do
|
73
|
+
expect(subject).to be_false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "not on start" do
|
78
|
+
let(:extractor) do
|
79
|
+
e = MethodMatch::NameExtractor.new ''
|
80
|
+
e.stub(:full_path) { "a" }
|
81
|
+
e.stub(:name) { "bba" }
|
82
|
+
e
|
83
|
+
end
|
84
|
+
|
85
|
+
it "cleans line breaks of pwd" do
|
86
|
+
expect(subject).to be_false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
21
90
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MethodMatch::Pry do
|
4
|
+
subject { MethodMatch::Pry.new }
|
5
|
+
describe "#setup" do
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#rspec_method' do
|
10
|
+
it "returns proc creating rspec_method command" do
|
11
|
+
expect(subject.rspec_method).to be_instance_of Proc
|
12
|
+
expect(subject.rspec_method.lambda?).to be_false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#command_proc' do
|
17
|
+
it "returns proc passed to create_command" do
|
18
|
+
expect(subject.command_proc).to be_instance_of Proc
|
19
|
+
expect(subject.command_proc.lambda?).to be_false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_match
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomasz Tokarski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- spec/method_match/command_runner_spec.rb
|
92
92
|
- spec/method_match/matcher_spec.rb
|
93
93
|
- spec/method_match/name_extractor_spec.rb
|
94
|
+
- spec/method_match/pry_spec.rb
|
94
95
|
- spec/spec_helper.rb
|
95
96
|
homepage: http://tomasztokarski.com/method_match
|
96
97
|
licenses: []
|
@@ -120,4 +121,5 @@ test_files:
|
|
120
121
|
- spec/method_match/command_runner_spec.rb
|
121
122
|
- spec/method_match/matcher_spec.rb
|
122
123
|
- spec/method_match/name_extractor_spec.rb
|
124
|
+
- spec/method_match/pry_spec.rb
|
123
125
|
- spec/spec_helper.rb
|