grep-interactors 0.1.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 +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +60 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/grep-interactors +3 -0
- data/grep-interactors.gemspec +26 -0
- data/lib/grep_in_paths.rb +11 -0
- data/lib/grep_interactors.rb +10 -0
- data/lib/parser.rb +52 -0
- data/lib/terminal_app.rb +3 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dd1ccd7dd934649a98013455d25e771fc047f2c520461b45edceb029f4fc2720
|
4
|
+
data.tar.gz: 3016cacc4d01fb136c0cf3af02cead00ce434588c4a705d287550dd1e9804052
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 63ad9c42824083e1140fd046acb5e1bea1d41776fc0432e8232ecb2391cdf82e2b9b4e0d6a6c4d730cd61a8eed340abfea373ab431c1b5045e499b97a4f39be6
|
7
|
+
data.tar.gz: 8cf8d7006ed8a9e5ec04539d770327f2b18c4172060033ba951b42507e2936a6928579defaac3f113f3613e2cfafda4073cefa5c6c15c6df02fe4c641010a392
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
grep-interactors (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (6.0.3.2)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 0.7, < 2)
|
12
|
+
minitest (~> 5.1)
|
13
|
+
tzinfo (~> 1.1)
|
14
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
15
|
+
ast (2.4.1)
|
16
|
+
byebug (11.1.3)
|
17
|
+
concurrent-ruby (1.1.7)
|
18
|
+
diff-lcs (1.4.4)
|
19
|
+
i18n (1.8.5)
|
20
|
+
concurrent-ruby (~> 1.0)
|
21
|
+
interactor (3.1.2)
|
22
|
+
minitest (5.14.2)
|
23
|
+
parser (2.7.1.4)
|
24
|
+
ast (~> 2.4.1)
|
25
|
+
rake (13.0.1)
|
26
|
+
rspec (3.9.0)
|
27
|
+
rspec-core (~> 3.9.0)
|
28
|
+
rspec-expectations (~> 3.9.0)
|
29
|
+
rspec-mocks (~> 3.9.0)
|
30
|
+
rspec-core (3.9.2)
|
31
|
+
rspec-support (~> 3.9.3)
|
32
|
+
rspec-expectations (3.9.2)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.9.0)
|
35
|
+
rspec-mocks (3.9.1)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.9.0)
|
38
|
+
rspec-support (3.9.3)
|
39
|
+
thread_safe (0.3.6)
|
40
|
+
tzinfo (1.2.7)
|
41
|
+
thread_safe (~> 0.1)
|
42
|
+
zeitwerk (2.4.0)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
activesupport
|
49
|
+
byebug
|
50
|
+
grep-interactors!
|
51
|
+
interactor
|
52
|
+
parser
|
53
|
+
rake
|
54
|
+
rspec
|
55
|
+
|
56
|
+
RUBY VERSION
|
57
|
+
ruby 2.7.0p0
|
58
|
+
|
59
|
+
BUNDLED WITH
|
60
|
+
2.1.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 ArslanZamanov
|
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,48 @@
|
|
1
|
+
# Grep::Interactors
|
2
|
+
|
3
|
+
Gem, which helps realize grep through organized Interactors.
|
4
|
+
For example, if sent interactor as ARG contains calling of other interactors, it will try to find entries in them.
|
5
|
+
More in spec/
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'grep-interactors'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install grep-interactors
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
## How to run
|
26
|
+
```bash
|
27
|
+
$ grep-interactors terminal_app interactors_path file_path keyword
|
28
|
+
```
|
29
|
+
eg
|
30
|
+
```bash
|
31
|
+
$ grep-interactors terminal_app.rb /home/stanislav_lemm/Projects/solaris/app/interactors/ /home/stanislav_lemm/Projects/solaris/app/interactors/agreements/create.rb agreement
|
32
|
+
```
|
33
|
+
_Works only with absolute path for now_
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
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).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ZamanovArslan/grep-interactors.
|
44
|
+
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "grep_interactors"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "grep-interactors"
|
3
|
+
spec.version = "0.1.0"
|
4
|
+
spec.authors = ["ArslanZamanov"]
|
5
|
+
spec.email = ["arslan.zamanov@flatstack.com"]
|
6
|
+
|
7
|
+
spec.summary = "Recursive Grep keyword in called interactors inside requested interactor"
|
8
|
+
spec.description = "WIP"
|
9
|
+
spec.homepage = "https://github.com/ZamanovArslan/grep-interactors"
|
10
|
+
spec.license = "MIT"
|
11
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
12
|
+
|
13
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/ZamanovArslan/grep-interactors"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class GrepInPaths
|
2
|
+
def self.call(query, file_paths)
|
3
|
+
file_paths.reduce([]) do |accum, file_path|
|
4
|
+
lines = File.open(file_path).readlines
|
5
|
+
|
6
|
+
accum + lines.each_with_index.filter_map do |line, index|
|
7
|
+
("#{file_path}:#{index + 1}") if line.include?(query)
|
8
|
+
end
|
9
|
+
end.flatten
|
10
|
+
end
|
11
|
+
end
|
data/lib/parser.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "pathname"
|
3
|
+
|
4
|
+
class Parser
|
5
|
+
attr_reader :interactors_path, :file_path
|
6
|
+
|
7
|
+
def initialize(interactors_path, file_path)
|
8
|
+
@interactors_path = interactors_path
|
9
|
+
@file_path = file_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def file_paths
|
13
|
+
recursive_parse_file_paths([file_path])
|
14
|
+
end
|
15
|
+
|
16
|
+
def recursive_parse_file_paths(file_paths)
|
17
|
+
return [] if file_paths.empty?
|
18
|
+
|
19
|
+
new_file_paths = parse_files_paths parse_interactors file_paths[0]
|
20
|
+
new_file_paths + recursive_parse_file_paths(file_paths[1..-1]) + recursive_parse_file_paths(new_file_paths)
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_files_paths(class_names)
|
24
|
+
class_names.map {|class_name| get_file_path_by_class(class_name) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_interactors(file_path)
|
28
|
+
interactors = File.read(file_path).scan(/[A-Z][a-z]*[::[A-Z][a-z]*]*/).filter_map do |constant|
|
29
|
+
get_full_class_name(constant, file_path)
|
30
|
+
end
|
31
|
+
current_class = get_class_name_by_path(file_path)
|
32
|
+
|
33
|
+
interactors - [current_class]
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_full_class_name(constant, file_path)
|
37
|
+
return constant if Pathname.new(get_file_path_by_class(constant)).exist?
|
38
|
+
|
39
|
+
current_module = get_class_name_by_path(file_path).split("::")[0..-2].join("::")
|
40
|
+
full_class_name = "#{current_module}::#{constant}"
|
41
|
+
|
42
|
+
full_class_name if Pathname.new(get_file_path_by_class(full_class_name)).exist?
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_class_name_by_path(path)
|
46
|
+
ActiveSupport::Inflector.camelize(path.gsub(interactors_path, "").gsub(".rb", ""))
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_file_path_by_class(class_name)
|
50
|
+
"#{interactors_path}#{ActiveSupport::Inflector.underscore(class_name)}.rb"
|
51
|
+
end
|
52
|
+
end
|
data/lib/terminal_app.rb
ADDED
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grep-interactors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ArslanZamanov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: WIP
|
14
|
+
email:
|
15
|
+
- arslan.zamanov@flatstack.com
|
16
|
+
executables:
|
17
|
+
- grep-interactors
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
22
|
+
- ".rspec"
|
23
|
+
- ".travis.yml"
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- bin/console
|
30
|
+
- bin/setup
|
31
|
+
- exe/grep-interactors
|
32
|
+
- grep-interactors.gemspec
|
33
|
+
- lib/grep_in_paths.rb
|
34
|
+
- lib/grep_interactors.rb
|
35
|
+
- lib/parser.rb
|
36
|
+
- lib/terminal_app.rb
|
37
|
+
homepage: https://github.com/ZamanovArslan/grep-interactors
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata:
|
41
|
+
allowed_push_host: https://rubygems.org
|
42
|
+
homepage_uri: https://github.com/ZamanovArslan/grep-interactors
|
43
|
+
source_code_uri: https://github.com/ZamanovArslan/grep-interactors
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.3.0
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubygems_version: 3.1.2
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Recursive Grep keyword in called interactors inside requested interactor
|
63
|
+
test_files: []
|