grep-interactors 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +14 -1
- data/README.md +19 -2
- data/bin/grep-interactors +2 -2
- data/exe/grep-interactors +2 -2
- data/grep-interactors.gemspec +10 -4
- data/lib/containers/base.rb +5 -0
- data/lib/grep_interactors.rb +19 -5
- data/lib/grep_interactors/cli.rb +39 -0
- data/lib/grep_interactors/grep_in_paths.rb +17 -0
- data/lib/grep_interactors/parser.rb +53 -0
- data/lib/grep_interactors/version.rb +3 -0
- data/lib/string_matcher/default.rb +7 -0
- data/lib/string_matcher/regex.rb +7 -0
- metadata +27 -8
- data/lib/cli.rb +0 -9
- data/lib/grep_in_paths.rb +0 -11
- data/lib/parser.rb +0 -52
- data/lib/terminal_app.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e3e12d742ed0f4ae908b3d4450363ff4895fa706a58546bfb6a24677703921f
|
4
|
+
data.tar.gz: f82e5bbcf97d93dde28735a6cf0a9ed5ff0b0a89e93a45387b3701122a09dfac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd8857b59eb8a0f586e50a296839f5e3d3afe584bda196b8a0524130bb65dd18607d3b41ddc8958f2214150539d81d1fd10a14e9b88ed5b6e0235e85fc736855
|
7
|
+
data.tar.gz: 24c2c3f0b265dac5a7c21ba4c1f146774f0e8753b3396a8f638a6bfd9716dc28e19abe4d318f51dd2a2c0b13a930bea11b635e451ecf13bff92911d2f895945e
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grep-interactors (0.1.
|
4
|
+
grep-interactors (0.1.3)
|
5
|
+
dry-auto_inject
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -16,6 +17,18 @@ GEM
|
|
16
17
|
byebug (11.1.3)
|
17
18
|
concurrent-ruby (1.1.7)
|
18
19
|
diff-lcs (1.4.4)
|
20
|
+
dry-auto_inject (0.7.0)
|
21
|
+
dry-container (>= 0.3.4)
|
22
|
+
dry-configurable (0.11.6)
|
23
|
+
concurrent-ruby (~> 1.0)
|
24
|
+
dry-core (~> 0.4, >= 0.4.7)
|
25
|
+
dry-equalizer (~> 0.2)
|
26
|
+
dry-container (0.7.2)
|
27
|
+
concurrent-ruby (~> 1.0)
|
28
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
29
|
+
dry-core (0.4.9)
|
30
|
+
concurrent-ruby (~> 1.0)
|
31
|
+
dry-equalizer (0.3.0)
|
19
32
|
i18n (1.8.5)
|
20
33
|
concurrent-ruby (~> 1.0)
|
21
34
|
interactor (3.1.2)
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# Grep::Interactors
|
4
4
|
|
5
|
-
Gem, which helps
|
5
|
+
Gem, which helps grep through organized Interactors.
|
6
6
|
For example, if sent interactor as ARG contains calling of other interactors, it will try to find entries in them.
|
7
7
|
More in spec/
|
8
8
|
|
@@ -30,7 +30,19 @@ $ grep-interactors interactors_path file_path keyword
|
|
30
30
|
```
|
31
31
|
eg
|
32
32
|
```bash
|
33
|
-
$ grep-interactors /home/stanislav_lemm/Projects/solaris/app/interactors/ /home/stanislav_lemm/Projects/solaris/app/interactors/agreements/create.rb
|
33
|
+
$ grep-interactors /home/stanislav_lemm/Projects/solaris/app/interactors/ /home/stanislav_lemm/Projects/solaris/app/interactors/agreements/create.rb user
|
34
|
+
|
35
|
+
/home/stanislav_lemm/Projects/solaris/app/interactors/user/update_attributes.rb:6
|
36
|
+
/home/stanislav_lemm/Projects/solaris/app/interactors/user/update_attributes.rb:9
|
37
|
+
/home/stanislav_lemm/Projects/solaris/app/interactors/user/update_attributes.rb:12
|
38
|
+
/home/stanislav_lemm/Projects/solaris/app/interactors/user/update_attributes.rb:18
|
39
|
+
/home/stanislav_lemm/Projects/solaris/app/interactors/user/update_attributes.rb:30
|
40
|
+
/home/stanislav_lemm/Projects/solaris/app/interactors/user/update_attributes.rb:34
|
41
|
+
/home/stanislav_lemm/Projects/solaris/app/interactors/user/mind/refresh_value.rb:8
|
42
|
+
/home/stanislav_lemm/Projects/solaris/app/interactors/user/mind/refresh_value.rb:9
|
43
|
+
/home/stanislav_lemm/Projects/solaris/app/interactors/user/mind/refresh_value.rb:13
|
44
|
+
/home/stanislav_lemm/Projects/solaris/app/interactors/user/mind/refresh_value.rb:35
|
45
|
+
/home/stanislav_lemm/Projects/solaris/app/interactors/user/mind/refresh_value.rb:39
|
34
46
|
```
|
35
47
|
_Works only with absolute path for now_
|
36
48
|
|
@@ -40,6 +52,11 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
40
52
|
|
41
53
|
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).
|
42
54
|
|
55
|
+
## Roadmap
|
56
|
+
* Add docs
|
57
|
+
* intellij idea plugin
|
58
|
+
* Sublime Text 3 package
|
59
|
+
|
43
60
|
## Contributing
|
44
61
|
|
45
62
|
Bug reports and pull requests are welcome on GitHub at https://github.com/ZamanovArslan/grep-interactors.
|
data/bin/grep-interactors
CHANGED
data/exe/grep-interactors
CHANGED
data/grep-interactors.gemspec
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require "grep_interactors/version"
|
5
|
+
|
1
6
|
Gem::Specification.new do |spec|
|
2
7
|
spec.name = "grep-interactors"
|
3
|
-
spec.version =
|
8
|
+
spec.version = GrepInteractors::VERSION
|
4
9
|
spec.authors = ["ArslanZamanov"]
|
5
10
|
spec.email = ["arslan.zamanov@flatstack.com"]
|
6
11
|
|
7
12
|
spec.summary = "Recursive Grep keyword in called interactors inside requested interactor"
|
8
|
-
spec.description = "
|
13
|
+
spec.description = "Gem, which helps realize grep through organized Interactors. For example, if sent interactor as
|
14
|
+
ARG contains calling of other interactors, it will try to find entries in them. More in specs"
|
9
15
|
spec.homepage = "https://github.com/ZamanovArslan/grep-interactors"
|
10
16
|
spec.license = "MIT"
|
11
17
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
@@ -15,8 +21,8 @@ Gem::Specification.new do |spec|
|
|
15
21
|
spec.metadata["homepage_uri"] = spec.homepage
|
16
22
|
spec.metadata["source_code_uri"] = "https://github.com/ZamanovArslan/grep-interactors"
|
17
23
|
|
18
|
-
|
19
|
-
|
24
|
+
spec.add_runtime_dependency 'dry-auto_inject'
|
25
|
+
|
20
26
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
27
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
28
|
end
|
data/lib/grep_interactors.rb
CHANGED
@@ -1,10 +1,24 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require "active_support"
|
2
|
+
require "dry/auto_inject"
|
3
|
+
require "containers/base"
|
3
4
|
|
4
|
-
|
5
|
+
module GrepInteractors
|
5
6
|
def self.call(interactors_path, file_path, query)
|
6
7
|
file_paths = Parser.new(interactors_path, file_path).file_paths
|
7
8
|
|
8
|
-
GrepInPaths.call(query, file_paths)
|
9
|
+
GrepInPaths.new.call(query, file_paths)
|
9
10
|
end
|
10
|
-
|
11
|
+
|
12
|
+
def self.container
|
13
|
+
@@container ||= Containers::Base
|
14
|
+
end
|
15
|
+
|
16
|
+
Import = Dry::AutoInject(container)
|
17
|
+
end
|
18
|
+
|
19
|
+
require "grep_interactors/parser"
|
20
|
+
require "grep_interactors/cli"
|
21
|
+
require "grep_interactors/grep_in_paths"
|
22
|
+
require "grep_interactors/version"
|
23
|
+
require "string_matcher/default"
|
24
|
+
require "string_matcher/regex"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "optparse"
|
2
|
+
require "grep_interactors"
|
3
|
+
|
4
|
+
module GrepInteractors
|
5
|
+
class Cli
|
6
|
+
def self.call(args, out = STDOUT)
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.on("-r", "--regexp", "Use regexp to search entries") do
|
9
|
+
GrepInteractors.container.register("string_matcher", ::StringMatcher::Regex)
|
10
|
+
end
|
11
|
+
|
12
|
+
opts.on_tail("-v", "--version", "Print version number") do
|
13
|
+
out << "Grep Interactors #{GrepInteractors::VERSION}\n"
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on_tail("-h", "--help", "Print this help") do
|
18
|
+
out << "Search entries in interactors chain calls \n\n"
|
19
|
+
out << opts
|
20
|
+
out << "\nCreated and maintained by Arslan Zamanov, available under the MIT License.\n"
|
21
|
+
out << "Report bugs and contribute at https://github.com/ZamanovArslan/grep-interactors\n"
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
end.parse!(args)
|
25
|
+
|
26
|
+
GrepInteractors.container.register("string_matcher", ::StringMatcher::Default) unless GrepInteractors.container.resolve("string_matcher")
|
27
|
+
|
28
|
+
if args[0..3].empty?
|
29
|
+
out << "Args should be defined\n"
|
30
|
+
return false
|
31
|
+
end
|
32
|
+
|
33
|
+
out << GrepInteractors.call(args[0], args[1], args[2]).join("\n")
|
34
|
+
out << "\n"
|
35
|
+
|
36
|
+
exit 0
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'byebug'
|
2
|
+
|
3
|
+
module GrepInteractors
|
4
|
+
class GrepInPaths
|
5
|
+
include Import["string_matcher"]
|
6
|
+
|
7
|
+
def call(query, file_paths)
|
8
|
+
file_paths.reduce([]) do |accum, file_path|
|
9
|
+
lines = File.open(file_path).readlines
|
10
|
+
|
11
|
+
accum + lines.each_with_index.filter_map do |line, index|
|
12
|
+
("#{file_path}:#{index + 1}") if string_matcher.match?(line, query)
|
13
|
+
end
|
14
|
+
end.flatten
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
module GrepInteractors
|
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
|
53
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grep-interactors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ArslanZamanov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2020-09-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dry-auto_inject
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: |-
|
28
|
+
Gem, which helps realize grep through organized Interactors. For example, if sent interactor as
|
29
|
+
ARG contains calling of other interactors, it will try to find entries in them. More in specs
|
14
30
|
email:
|
15
31
|
- arslan.zamanov@flatstack.com
|
16
32
|
executables:
|
@@ -31,11 +47,14 @@ files:
|
|
31
47
|
- bin/setup
|
32
48
|
- exe/grep-interactors
|
33
49
|
- grep-interactors.gemspec
|
34
|
-
- lib/
|
35
|
-
- lib/grep_in_paths.rb
|
50
|
+
- lib/containers/base.rb
|
36
51
|
- lib/grep_interactors.rb
|
37
|
-
- lib/
|
38
|
-
- lib/
|
52
|
+
- lib/grep_interactors/cli.rb
|
53
|
+
- lib/grep_interactors/grep_in_paths.rb
|
54
|
+
- lib/grep_interactors/parser.rb
|
55
|
+
- lib/grep_interactors/version.rb
|
56
|
+
- lib/string_matcher/default.rb
|
57
|
+
- lib/string_matcher/regex.rb
|
39
58
|
homepage: https://github.com/ZamanovArslan/grep-interactors
|
40
59
|
licenses:
|
41
60
|
- MIT
|
data/lib/cli.rb
DELETED
data/lib/grep_in_paths.rb
DELETED
@@ -1,11 +0,0 @@
|
|
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
DELETED
@@ -1,52 +0,0 @@
|
|
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
DELETED