sexp_cli_tools 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +56 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +86 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +101 -0
- data/Rakefile +12 -0
- data/bin/console +24 -0
- data/bin/setup +8 -0
- data/exe/sexp +8 -0
- data/lib/sexp_cli_tools/cli.rb +19 -0
- data/lib/sexp_cli_tools/matchers/super_caller.rb +7 -0
- data/lib/sexp_cli_tools/version.rb +5 -0
- data/lib/sexp_cli_tools.rb +16 -0
- data/sexp_cli_tools.gemspec +36 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5450748309abadaaf12185fbffbc943f92ffa80b5cb16956c7737ee4dbe5e848
|
4
|
+
data.tar.gz: dd45f667572f84d72dee8006a61bcf5949b162eff7e40235708097dae8d147df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ba7cbb70b5e2990444c971b93ac47d9d3086bb41e5974f1a0e28a08c06237c025af84d285ab9b7fe8eaccc92dc484c5a60af0fc0387e0e78057d1988215b1810
|
7
|
+
data.tar.gz: 1b23f5d3b0a41a95255d9de7496f4e138157d3f8767ed73b1cb260ede47e74b9789e204d908e8a7b1c992ccd35b89708a21770e94fc83b2cf77f85964e8b4b69
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at me@cpb.ca. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sexp_cli_tools (0.1.0)
|
5
|
+
ruby_parser (~> 3.18.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
aruba (2.0.0)
|
11
|
+
bundler (>= 1.17, < 3.0)
|
12
|
+
childprocess (>= 2.0, < 5.0)
|
13
|
+
contracts (>= 0.16.0, < 0.18.0)
|
14
|
+
cucumber (>= 4.0, < 8.0)
|
15
|
+
rspec-expectations (~> 3.4)
|
16
|
+
thor (~> 1.0)
|
17
|
+
builder (3.2.4)
|
18
|
+
childprocess (4.1.0)
|
19
|
+
coderay (1.1.3)
|
20
|
+
contracts (0.17)
|
21
|
+
cucumber (7.1.0)
|
22
|
+
builder (~> 3.2, >= 3.2.4)
|
23
|
+
cucumber-core (~> 10.1, >= 10.1.0)
|
24
|
+
cucumber-create-meta (~> 6.0, >= 6.0.1)
|
25
|
+
cucumber-cucumber-expressions (~> 14.0, >= 14.0.0)
|
26
|
+
cucumber-gherkin (~> 22.0, >= 22.0.0)
|
27
|
+
cucumber-html-formatter (~> 17.0, >= 17.0.0)
|
28
|
+
cucumber-messages (~> 17.1, >= 17.1.1)
|
29
|
+
cucumber-wire (~> 6.2, >= 6.2.0)
|
30
|
+
diff-lcs (~> 1.4, >= 1.4.4)
|
31
|
+
mime-types (~> 3.3, >= 3.3.1)
|
32
|
+
multi_test (~> 0.1, >= 0.1.2)
|
33
|
+
sys-uname (~> 1.2, >= 1.2.2)
|
34
|
+
cucumber-core (10.1.0)
|
35
|
+
cucumber-gherkin (~> 22.0, >= 22.0.0)
|
36
|
+
cucumber-messages (~> 17.1, >= 17.1.1)
|
37
|
+
cucumber-tag-expressions (~> 4.0, >= 4.0.2)
|
38
|
+
cucumber-create-meta (6.0.3)
|
39
|
+
cucumber-messages (~> 17.1, >= 17.1.1)
|
40
|
+
sys-uname (~> 1.2, >= 1.2.2)
|
41
|
+
cucumber-cucumber-expressions (14.0.0)
|
42
|
+
cucumber-gherkin (22.0.0)
|
43
|
+
cucumber-messages (~> 17.1, >= 17.1.1)
|
44
|
+
cucumber-html-formatter (17.0.0)
|
45
|
+
cucumber-messages (~> 17.1, >= 17.1.0)
|
46
|
+
cucumber-messages (17.1.1)
|
47
|
+
cucumber-tag-expressions (4.1.0)
|
48
|
+
cucumber-wire (6.2.0)
|
49
|
+
cucumber-core (~> 10.1, >= 10.1.0)
|
50
|
+
cucumber-cucumber-expressions (~> 14.0, >= 14.0.0)
|
51
|
+
cucumber-messages (~> 17.1, >= 17.1.1)
|
52
|
+
diff-lcs (1.4.4)
|
53
|
+
ffi (1.15.4)
|
54
|
+
method_source (1.0.0)
|
55
|
+
mime-types (3.4.0)
|
56
|
+
mime-types-data (~> 3.2015)
|
57
|
+
mime-types-data (3.2021.1115)
|
58
|
+
minitest (5.14.4)
|
59
|
+
multi_test (0.1.2)
|
60
|
+
pry (0.14.1)
|
61
|
+
coderay (~> 1.1)
|
62
|
+
method_source (~> 1.0)
|
63
|
+
rake (13.0.6)
|
64
|
+
rspec-expectations (3.10.1)
|
65
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
66
|
+
rspec-support (~> 3.10.0)
|
67
|
+
rspec-support (3.10.3)
|
68
|
+
ruby_parser (3.18.1)
|
69
|
+
sexp_processor (~> 4.16)
|
70
|
+
sexp_processor (4.16.0)
|
71
|
+
sys-uname (1.2.2)
|
72
|
+
ffi (~> 1.1)
|
73
|
+
thor (1.1.0)
|
74
|
+
|
75
|
+
PLATFORMS
|
76
|
+
x86_64-darwin-21
|
77
|
+
|
78
|
+
DEPENDENCIES
|
79
|
+
aruba
|
80
|
+
minitest (~> 5.0)
|
81
|
+
pry (~> 0.14.1)
|
82
|
+
rake (~> 13.0)
|
83
|
+
sexp_cli_tools!
|
84
|
+
|
85
|
+
BUNDLED WITH
|
86
|
+
2.2.22
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Caleb Buxton
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Caleb Buxton
|
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,101 @@
|
|
1
|
+
# sexp_cli_tools
|
2
|
+
Educational project exploring the utility in searching and manipulating codebases using S-expressions.
|
3
|
+
|
4
|
+
## Inspiration
|
5
|
+
|
6
|
+
I once found wide spread use of a "magical" Ruby method which was unnecessary. The intent of this method was to relieve the developer from the repetition of setting instance variables from method parameters. How this magic method did this was difficult to understand for most. Upon examining this method, I noticed it made costly calls to do at run time what could have been done by a developer with a keyboard, or if you wanted to, with code at load time.
|
7
|
+
|
8
|
+
I was new to the team and project, and because the use of this method was wide spread, I wanted a systematic and repeatable approach to refactoring it out of existence so that I and my new colleagues could trust the widespread change.
|
9
|
+
|
10
|
+
## Concrete Examples We Can All Learn From
|
11
|
+
|
12
|
+
### Decoupling Subclasses Using Hook Messages
|
13
|
+
|
14
|
+
In Chapter 6 of Practical Object-Oriented Design in Ruby by Sandi Metz, part of the discussion is focused on finding the ideal coupling between child and parent classes. One proposal introduced in that chapter is to use hook methods, instead of calling super.
|
15
|
+
|
16
|
+
Lets imagine a scenario where we have achieved total consensus in an organization, and the new direction is to dogmatically use hook methods, instead of calling super.
|
17
|
+
|
18
|
+
#### Goal
|
19
|
+
|
20
|
+
- Replace methods that call super with a hook method
|
21
|
+
- Modify parent classes implementation of the supered method to call hook methods
|
22
|
+
|
23
|
+
#### Initial state
|
24
|
+
|
25
|
+
We will begin with the classes [`Bicycle`](test/fixtures/coupling_between_superclasses_and_subclasses/bicycle.rb), [`RoadBike`](test/fixtures/coupling_between_superclasses_and_subclasses/road_bike.rb) and [`MountainBike`](test/fixtures/coupling_between_superclasses_and_subclasses/mountain_bike.rb). We will build them up to the state from **Managing Coupling Between Superclasses and Subclasses** until we can recognize the important parts of the "discernible pattern."
|
26
|
+
|
27
|
+
#### Milestones
|
28
|
+
|
29
|
+
Things we must be able to interogate about this code:
|
30
|
+
- Which are the children, and which is the parent class?
|
31
|
+
- Which methods call super, and which is the method that responds to super?
|
32
|
+
- What in each method that calls super needs to be in the respective hook method?
|
33
|
+
- What change needs to occur in the method responding to super to leverage the hook methods?
|
34
|
+
|
35
|
+
#### Finding the parent of child classes
|
36
|
+
|
37
|
+
An s-expression for an empty class in Ruby, as parsed by `ruby_parser`, looks like this:
|
38
|
+
|
39
|
+
``` ruby
|
40
|
+
class Bicycle
|
41
|
+
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
s(:class, :Bicycle, nil)
|
47
|
+
```
|
48
|
+
|
49
|
+
An s-expression has a **type** and a **body**. The above s-expression's **type** is `:class` and the body is `s(:Bicycle, nil)`.
|
50
|
+
|
51
|
+
An s-expression for an empty class with a parent looks like this:
|
52
|
+
|
53
|
+
``` ruby
|
54
|
+
class MountainBike < Bicycle
|
55
|
+
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
s(:class, :MountainBike, s(:const, Bicycle))
|
61
|
+
```
|
62
|
+
|
63
|
+
This s-expression's **type** is still `:class`, but the `body` is: `s(:MountainBike, s(:const, :Bicycle))`.
|
64
|
+
|
65
|
+
An s-expression is a representation of the abstract syntax tree, and the s-expressions generated by `ruby_parser` use this `sexp_body` recursion to create that tree.
|
66
|
+
|
67
|
+
##### Matching a class
|
68
|
+
|
69
|
+
`ruby_parser` comes with a class `Sexp::Matcher` which provides a terse syntax that we can use to select nodes from the s-expression tree.
|
70
|
+
|
71
|
+
The `Sexp::Matcher` expression that matches any class definition is: `(class ___)`. That expression uses the triple underscore `___` wildcard to match anything following a `class` **type** s-expression.
|
72
|
+
|
73
|
+
##### Matching a class with an explicit parent
|
74
|
+
|
75
|
+
The `Sexp::Matcher` expression that matches any class with an explicit parent is: `(class _ (const _) ___)`. This uses the single underscore `_` positional wild card match, and then matches the constant s-expression containing the parent class.
|
76
|
+
|
77
|
+
##### Matching a class with an implicit parent
|
78
|
+
|
79
|
+
It is also possible to include negation in `Sexp::Matcher`. A class with an implicit parent does not have the constant s-expression `(const _)`. Right now, our class s-expression matcher, `(class ___)` matches all our classes. To match only `Bicycle` we must use negation. That s-expression is `(class _ [not? (const _)] ___)`.
|
80
|
+
|
81
|
+
##### Capturing what we've learned in a tool that people can use
|
82
|
+
|
83
|
+
Knowing the syntax for `Sexp::Matcher` expressions gives us some confidence that we can start iterating on a tool to help us achieve our goal. The implicit expectation in the project name is that a command line interface is provided. To complete an initial release of a command line tool, we'll use the rubygem `aruba` to help with test setup and teardown.
|
84
|
+
|
85
|
+
The `sexp` command offers a convenient shortcut to the `Sexp::Matcher` expressions we'll develop. As we figure out the s-expression matchers along the way, we can add to the list of known matchers to create simple shortcuts, like with the builtin `sexp find child-class` or `sexp find parent-class`.
|
86
|
+
|
87
|
+
- Checkout the [tests for examples](https://github.com/cpb/sexp_cli_tools/blob/main/test/sexp_cli_tools/cli_test.rb#L34-L54) of how to test drive your own.
|
88
|
+
- Checkout the [implementation](https://github.com/cpb/sexp_cli_tools/blob/main/lib/sexp_cli_tools.rb#L8-L9) to see how easy it is to add one.
|
89
|
+
|
90
|
+
#### Methods that call super, and methods that are super
|
91
|
+
|
92
|
+
##### Iterating on figuring out `Sexp::Matcher` patterns
|
93
|
+
|
94
|
+
What isn't show 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
|
+
|
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
|
+
|
98
|
+
#### Hook methods from super callers
|
99
|
+
|
100
|
+
#### Hook calls from super methods
|
101
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
|
6
|
+
require "ruby_parser"
|
7
|
+
|
8
|
+
def fixture_code(basename, relative_path=Pathname.new('test/fixtures/coupling_between_superclasses_and_subclasses'))
|
9
|
+
relative_path.join(basename).read
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse_file(basename)
|
13
|
+
RubyParser.new.parse(fixture_code(basename))
|
14
|
+
end
|
15
|
+
|
16
|
+
puts parse_file('bicycle.rb').inspect
|
17
|
+
puts parse_file('mountain_bike.rb').inspect
|
18
|
+
|
19
|
+
CLASS_MATCHER = Sexp::Matcher.parse('(class ___)')
|
20
|
+
CLASS_WITH_PARENT_MATCHER = Sexp::Matcher.parse('(class _ (const _) ___)')
|
21
|
+
CLASS_WITH_IMPLICIT_PARENT_MATCHER = Sexp::Matcher.parse('(class _ [not? (const _)] ___)')
|
22
|
+
|
23
|
+
require "pry"
|
24
|
+
Pry.start
|
data/bin/setup
ADDED
data/exe/sexp
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "sexp_cli_tools"
|
3
|
+
|
4
|
+
module SexpCliTools
|
5
|
+
class Cli < Thor
|
6
|
+
desc "version", "Prints version"
|
7
|
+
default_command def version
|
8
|
+
puts "SexpCliTools version: %p" % SexpCliTools::VERSION
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "find sexp-matcher [**/*.rb]", "Finds Ruby files matching the s-expression matcher in the glob pattern. Defaults to search all Ruby files with the pattern **/*.rb"
|
12
|
+
def find(requested_sexp_matcher, glob="**/*.rb")
|
13
|
+
sexp_matcher = SexpCliTools::MATCHERS.fetch(requested_sexp_matcher)
|
14
|
+
Pathname.glob(glob).each do |path|
|
15
|
+
puts path.to_s if sexp_matcher.satisfy?(RubyParser.new.parse(path.read))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
module SexpCliTools
|
2
|
+
module Matchers
|
3
|
+
# Thanks to this test: https://github.com/seattlerb/sexp_processor/blob/93712e31b6d5e23c7d68cea805b40a642aad3e10/test/test_sexp.rb#L1625
|
4
|
+
# zsuper I noticed while simplifying the examples
|
5
|
+
SuperCaller = Sexp::Matcher.parse('[child (super ___)]') | Sexp::Matcher.parse('[child (zsuper)]')
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ruby_parser"
|
4
|
+
|
5
|
+
require_relative "sexp_cli_tools/version"
|
6
|
+
require_relative "sexp_cli_tools/matchers/super_caller"
|
7
|
+
|
8
|
+
module SexpCliTools
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
MATCHERS = {
|
12
|
+
"child-class" => Sexp::Matcher.parse('(class _ (const _) ___)'),
|
13
|
+
"parent-class" => Sexp::Matcher.parse('(class _ [not? (const _)] ___)'),
|
14
|
+
"super-caller" => Matchers::SuperCaller,
|
15
|
+
}.freeze
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/sexp_cli_tools/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "sexp_cli_tools"
|
7
|
+
spec.version = SexpCliTools::VERSION
|
8
|
+
spec.authors = ["Caleb Buxton"]
|
9
|
+
spec.email = ["me@cpb.ca"]
|
10
|
+
|
11
|
+
spec.summary = "Educational project exploring the utility in searching and manipulating codebases using S-expressions."
|
12
|
+
spec.homepage = "https://github.com/cpb/sexp_cli_tools"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 2.4.0"
|
15
|
+
|
16
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Uncomment to register a new dependency of your gem
|
32
|
+
spec.add_dependency "ruby_parser", "~> 3.18.1"
|
33
|
+
|
34
|
+
# For more information and examples about making a new gem, checkout our
|
35
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sexp_cli_tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Caleb Buxton
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-11-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby_parser
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.18.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.18.1
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- me@cpb.ca
|
30
|
+
executables:
|
31
|
+
- sexp
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".gitignore"
|
36
|
+
- CODE_OF_CONDUCT.md
|
37
|
+
- Gemfile
|
38
|
+
- Gemfile.lock
|
39
|
+
- LICENSE
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/console
|
44
|
+
- bin/setup
|
45
|
+
- exe/sexp
|
46
|
+
- lib/sexp_cli_tools.rb
|
47
|
+
- lib/sexp_cli_tools/cli.rb
|
48
|
+
- lib/sexp_cli_tools/matchers/super_caller.rb
|
49
|
+
- lib/sexp_cli_tools/version.rb
|
50
|
+
- sexp_cli_tools.gemspec
|
51
|
+
homepage: https://github.com/cpb/sexp_cli_tools
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata:
|
55
|
+
homepage_uri: https://github.com/cpb/sexp_cli_tools
|
56
|
+
source_code_uri: https://github.com/cpb/sexp_cli_tools
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.4.0
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubygems_version: 3.2.22
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Educational project exploring the utility in searching and manipulating codebases
|
76
|
+
using S-expressions.
|
77
|
+
test_files: []
|