sexp_cli_tools 0.2.1 → 1.0.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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +30 -1
- data/lib/sexp_cli_tools/cli.rb +5 -3
- data/lib/sexp_cli_tools/matchers/method_implementation.rb +17 -0
- data/lib/sexp_cli_tools/version.rb +1 -1
- data/lib/sexp_cli_tools.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a1dd5f9fed467c4a1d34ce7235494718afec4ffa1321abe3ff5d1c6ec36ea0c
|
4
|
+
data.tar.gz: 8c4bbf0cf2404e8ff508bb18b83423daf0a5a137aaa4716a63a38afc66054427
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc57297a5aa2d4b9ab1b93e69f09c34f65b7c0a8fe86e14f7eeb2b1178cd0bc7bc7abd6fdd0c65db5d7d4de39baa0810cf7fee70ba4df08bc831a07cc6c9d414
|
7
|
+
data.tar.gz: 367f2ef084b22883e87314e3f2b37594069f8224ea0c75329dff99634dacbb5d1cf43e6583258f23b013b5f6d6a63a050eacc346a69fe735de1a1a9a160c3554
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.2
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -91,7 +91,7 @@ The `sexp` command offers a convenient shortcut to the `Sexp::Matcher` expressio
|
|
91
91
|
|
92
92
|
##### Iterating on figuring out `Sexp::Matcher` patterns
|
93
93
|
|
94
|
-
What isn't
|
94
|
+
What isn't shown in [the commit which added the `Sexp::Matcher`](https://github.com/cpb/sexp_cli_tools/commit/34db6012b03f705b1d9c23025d3636fbf9d801dd) is the trial and error in the console trying to remember the terse rules.
|
95
95
|
|
96
96
|
Setting up a unit test can help close that iteration loop. [Consider the unit test for `SexpCliTools::Matchers::SuperCaller`](test/sexp_cli_tools/matchers/super_caller_test.rb)
|
97
97
|
|
@@ -101,6 +101,35 @@ Allowing users to experiment with s-expressions might enable exploration and dis
|
|
101
101
|
- `sexp find '[child (class ___)]'` to find class definitions nested in a namespace
|
102
102
|
- `sexp find '[child (case ___)]'` to find case statements
|
103
103
|
|
104
|
+
So having test driven the development of [the `super-caller` matcher](lib/sexp_cli_tools/matchers/super_caller.rb) next we have to find the methods that respond to `super`.
|
105
|
+
|
106
|
+
##### Finding super implementations
|
107
|
+
|
108
|
+
So far we've been using `Sexp::Matcher` strings to find quite abstract parts of our code. But, it's completely possible to fill in what in the parts we know that we'd like to find.
|
109
|
+
|
110
|
+
- `sexp find '(class :Bicycle ___)'` from my working copy of this project turns up the [test fixture file for `Bicycle`](https://github.com/cpb/sexp_cli_tools/blob/eb6ebe8722cd13cc91ba12bc69380e09c3bdfe0d/test/fixtures/coupling_between_superclasses_and_subclasses/bicycle.rb), as well as the copy of it `aruba` makes in the `tmp/` directory for testing purposes.
|
111
|
+
- `sexp find '[child (defn :initialize ___)]'` only turns up the [test fixture file for `RoadBike`](https://github.com/cpb/sexp_cli_tools/blob/eb6ebe8722cd13cc91ba12bc69380e09c3bdfe0d/test/fixtures/coupling_between_superclasses_and_subclasses/test/fixtures/coupling_between_superclasses_and_subclasses/road_bike.rb). I guess it is time to fill in more of our `Bicycle` class!
|
112
|
+
|
113
|
+
Finding the super implementation will involve finding a class that contains a method defintion. So far, our matchers haven't taken any parameters. A (naive) matcher for a super implementation might have two parameters, the name of the class we expect to define the method, and the name of the method.
|
114
|
+
|
115
|
+
##### Passing matcher parameters
|
116
|
+
|
117
|
+
Early on I chose to have the second sequence argument to the command line interface `sexp find` the glob pattern of files to include in the search. However, I want to prioritize matcher parameters for that position now. Although my test coverage didn't include tests for that glob pattern, I did document it.
|
118
|
+
|
119
|
+
So, when I [moved that out into the `--include` command line option](https://github.com/cpb/sexp_cli_tools/pull/12/commits/af66f0b7da549426ee0b6444f46b317da279e9a0), that was a breaking change to the public interface. That would necessitate incrementing the major version number according to semantic versioning. I have a hunch that because I'm still in the `0` major release, I could get away with not bumping it. But, I think the `--include` is something I can stick to.
|
120
|
+
|
121
|
+
What I remember about semantic versioning is that additions can just be minor version bumps. So, as long as I don't make a backwards incompatible change to the `find` command or the `--include` option I should be good.
|
122
|
+
|
123
|
+
Following merge of: [✨ `sexp find method-implementation passed_method` lists files that define the passed method](https://github.com/cpb/sexp_cli_tools/pull/12) I'll release `v1.0.0`! In that PR I chose to do inside-out testing because the `aruba` tests are a bit slow.
|
124
|
+
|
125
|
+
I found it helpful to run just the CLI command tests I was working on using the `TEST` and `TESTOPTS` options to the `rake` test tast, like so:
|
126
|
+
|
127
|
+
```shell
|
128
|
+
rake TEST='test/sexp_cli_tools/cli_test.rb' TESTOPTS="--name=/method-implementation/"
|
129
|
+
```
|
130
|
+
|
131
|
+
##### Capturing the Superclass name
|
132
|
+
|
104
133
|
#### Hook methods from super callers
|
105
134
|
|
106
135
|
#### Hook calls from super methods
|
data/lib/sexp_cli_tools/cli.rb
CHANGED
@@ -8,11 +8,13 @@ module SexpCliTools
|
|
8
8
|
puts "SexpCliTools version: %p" % SexpCliTools::VERSION
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
option :include, default: '**/*.rb'
|
12
|
+
desc "find sexp-matcher [--include='**/*.rb']", "Finds Ruby files matching the s-expression matcher in the glob pattern. Defaults to search all Ruby files with the pattern **/*.rb"
|
13
|
+
def find(requested_sexp_matcher, *matcher_params)
|
14
|
+
glob = options[:include]
|
13
15
|
sexp_matcher = SexpCliTools::MATCHERS[requested_sexp_matcher]
|
14
16
|
Pathname.glob(glob).each do |path|
|
15
|
-
puts path.to_s if sexp_matcher.satisfy?(RubyParser.new.parse(path.read))
|
17
|
+
puts path.to_s if sexp_matcher.satisfy?(RubyParser.new.parse(path.read), *matcher_params)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SexpCliTools
|
2
|
+
module Matchers
|
3
|
+
class MethodImplementation
|
4
|
+
def self.satisfy?(sexp, target_method)
|
5
|
+
new(target_method).satisfy?(sexp)
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(target_method)
|
9
|
+
@matcher = Sexp::Matcher.parse("[child (defn #{target_method} ___)]")
|
10
|
+
end
|
11
|
+
|
12
|
+
def satisfy?(sexp)
|
13
|
+
@matcher.satisfy?(sexp)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/sexp_cli_tools.rb
CHANGED
@@ -4,6 +4,7 @@ require "ruby_parser"
|
|
4
4
|
|
5
5
|
require_relative "sexp_cli_tools/version"
|
6
6
|
require_relative "sexp_cli_tools/matchers/super_caller"
|
7
|
+
require_relative "sexp_cli_tools/matchers/method_implementation"
|
7
8
|
|
8
9
|
module SexpCliTools
|
9
10
|
class Error < StandardError; end
|
@@ -14,5 +15,6 @@ module SexpCliTools
|
|
14
15
|
"child-class" => Sexp::Matcher.parse('(class _ (const _) ___)'),
|
15
16
|
"parent-class" => Sexp::Matcher.parse('(class _ [not? (const _)] ___)'),
|
16
17
|
"super-caller" => Matchers::SuperCaller,
|
18
|
+
"method-implementation" => Matchers::MethodImplementation,
|
17
19
|
})
|
18
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sexp_cli_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Buxton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby_parser
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- ".gitignore"
|
50
|
+
- ".ruby-version"
|
50
51
|
- CODE_OF_CONDUCT.md
|
51
52
|
- Gemfile
|
52
53
|
- Gemfile.lock
|
@@ -59,6 +60,7 @@ files:
|
|
59
60
|
- exe/sexp
|
60
61
|
- lib/sexp_cli_tools.rb
|
61
62
|
- lib/sexp_cli_tools/cli.rb
|
63
|
+
- lib/sexp_cli_tools/matchers/method_implementation.rb
|
62
64
|
- lib/sexp_cli_tools/matchers/super_caller.rb
|
63
65
|
- lib/sexp_cli_tools/version.rb
|
64
66
|
- sexp_cli_tools.gemspec
|