grep-interactors 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13371cc60413f745df6dd14ec5c45539f3ee7dccaedb70f5401ccf4f8f59fe7c
4
- data.tar.gz: 7e4a2b69cd84b721af0079e86429e37af818f07215ebe66a04b47f2a967b9116
3
+ metadata.gz: bf0c9dfcc8e8f5a79ae2b2dbf6e97bb00e0b359c5041c839c33c2d37d351c834
4
+ data.tar.gz: 321c39615a25918bdf9192679740bdc5e994d530a41d4107fdf7bb866e0c59bc
5
5
  SHA512:
6
- metadata.gz: 8d51cbd7df7831c63eadff494bb6c2d2024a23afe55fa1d05691afb8b47c3ad801dad6cdb45fba8b281e2761f0ef7fcf9223481c836455482d569319e4c032f3
7
- data.tar.gz: 5a484354429f6bd957540788d93ce26060ef6c75aaf931cd098a5dd63091628cb7c814745c713c69cbc0a37568b21ba711764abe58b0d2ad45622255f9663ddf
6
+ metadata.gz: c025db885a8ce9e45ec5250c4abc4d8b23c9ede52faba40c42cfa1b8b50a9ff105ce5a170db8e53c473c451b1c1d3e34e2ff66cccf5fb3bf6da7d566fbb244a9
7
+ data.tar.gz: 3f78a9ea5cdcf822f0855e91d072a763ca27ec3811632fae994e933a0bf822c17bc73cce0d92779175f5cdf04cc8fbb06c90c50b6a02bcb451e7e8df7947f4ab
@@ -0,0 +1 @@
1
+ 2.7.0
data/Gemfile CHANGED
@@ -4,9 +4,7 @@ ruby "2.7.0"
4
4
 
5
5
  gemspec
6
6
 
7
- gem "interactor"
8
7
  gem "rake"
9
8
  gem "rspec"
10
9
  gem "activesupport"
11
- gem "byebug"
12
- gem "parser"
10
+ gem "dry-auto_inject"
@@ -1,7 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grep-interactors (0.1.1)
4
+ grep-interactors (0.1.5)
5
+ activesupport
6
+ dry-auto_inject
5
7
 
6
8
  GEM
7
9
  remote: https://rubygems.org/
@@ -12,16 +14,23 @@ GEM
12
14
  minitest (~> 5.1)
13
15
  tzinfo (~> 1.1)
14
16
  zeitwerk (~> 2.2, >= 2.2.2)
15
- ast (2.4.1)
16
- byebug (11.1.3)
17
17
  concurrent-ruby (1.1.7)
18
18
  diff-lcs (1.4.4)
19
+ dry-auto_inject (0.7.0)
20
+ dry-container (>= 0.3.4)
21
+ dry-configurable (0.11.6)
22
+ concurrent-ruby (~> 1.0)
23
+ dry-core (~> 0.4, >= 0.4.7)
24
+ dry-equalizer (~> 0.2)
25
+ dry-container (0.7.2)
26
+ concurrent-ruby (~> 1.0)
27
+ dry-configurable (~> 0.1, >= 0.1.3)
28
+ dry-core (0.4.9)
29
+ concurrent-ruby (~> 1.0)
30
+ dry-equalizer (0.3.0)
19
31
  i18n (1.8.5)
20
32
  concurrent-ruby (~> 1.0)
21
- interactor (3.1.2)
22
33
  minitest (5.14.2)
23
- parser (2.7.1.4)
24
- ast (~> 2.4.1)
25
34
  rake (13.0.1)
26
35
  rspec (3.9.0)
27
36
  rspec-core (~> 3.9.0)
@@ -46,10 +55,8 @@ PLATFORMS
46
55
 
47
56
  DEPENDENCIES
48
57
  activesupport
49
- byebug
58
+ dry-auto_inject
50
59
  grep-interactors!
51
- interactor
52
- parser
53
60
  rake
54
61
  rspec
55
62
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Grep::Interactors
4
4
 
5
- Gem, which helps realize grep through organized Interactors.
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
 
@@ -26,11 +26,23 @@ Or install it yourself as:
26
26
 
27
27
  ## How to run
28
28
  ```bash
29
- $ grep-interactors terminal_app interactors_path file_path keyword
29
+ $ grep-interactors interactors_path file_path keyword
30
30
  ```
31
31
  eg
32
32
  ```bash
33
- $ grep-interactors terminal_app.rb /home/stanislav_lemm/Projects/solaris/app/interactors/ /home/stanislav_lemm/Projects/solaris/app/interactors/agreements/create.rb agreement
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.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "grep_interactors"
4
+
5
+ GrepInteractors::Cli.call(ARGV)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "grep_interactors"
4
+
5
+ GrepInteractors::Cli.call(ARGV)
@@ -1,12 +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 = "0.1.1"
8
+ spec.version = GrepInteractors::VERSION
4
9
  spec.authors = ["ArslanZamanov"]
5
10
  spec.email = ["arslan.zamanov@flatstack.com"]
6
- spec.executables << 'grep'
7
11
 
8
12
  spec.summary = "Recursive Grep keyword in called interactors inside requested interactor"
9
- spec.description = "WIP"
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"
10
15
  spec.homepage = "https://github.com/ZamanovArslan/grep-interactors"
11
16
  spec.license = "MIT"
12
17
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
@@ -16,12 +21,14 @@ Gem::Specification.new do |spec|
16
21
  spec.metadata["homepage_uri"] = spec.homepage
17
22
  spec.metadata["source_code_uri"] = "https://github.com/ZamanovArslan/grep-interactors"
18
23
 
19
- # Specify which files should be added to the gem when it is released.
20
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.add_runtime_dependency 'dry-auto_inject'
25
+ spec.add_runtime_dependency 'activesupport'
26
+
21
27
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
28
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
29
  end
24
30
  spec.bindir = "exe"
25
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+
26
33
  spec.require_paths = ["lib"]
27
34
  end
@@ -0,0 +1,5 @@
1
+ module Containers
2
+ class Base
3
+ extend Dry::Container::Mixin
4
+ end
5
+ end
@@ -1,10 +1,24 @@
1
- require_relative "grep_in_paths"
2
- require_relative "parser"
1
+ require "active_support"
2
+ require "dry/auto_inject"
3
+ require "containers/base"
3
4
 
4
- class GrepInteractors
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
- end
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.key?("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,15 @@
1
+ module GrepInteractors
2
+ class GrepInPaths
3
+ include Import["string_matcher"]
4
+
5
+ def call(query, file_paths)
6
+ file_paths.reduce([]) do |accum, file_path|
7
+ lines = File.open(file_path).readlines
8
+
9
+ accum + lines.each_with_index.map do |line, index|
10
+ ("#{file_path}:#{index + 1}") if string_matcher.match?(line, query)
11
+ end.compact
12
+ end.flatten
13
+ end
14
+ end
15
+ 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]*]*/).map do |constant|
29
+ get_full_class_name(constant, file_path)
30
+ end.compact
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
@@ -0,0 +1,3 @@
1
+ module GrepInteractors
2
+ VERSION = "0.1.6"
3
+ end
@@ -0,0 +1,7 @@
1
+ module StringMatcher
2
+ class Default
3
+ def self.match?(string, regexp)
4
+ string.include? regexp
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module StringMatcher
2
+ class Regex
3
+ def self.match?(string, regexp)
4
+ string.match? Regexp.new regexp
5
+ end
6
+ end
7
+ end
metadata CHANGED
@@ -1,25 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grep-interactors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.6
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-17 00:00:00.000000000 Z
12
- dependencies: []
13
- description: WIP
11
+ date: 2020-09-29 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
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: |-
42
+ Gem, which helps realize grep through organized Interactors. For example, if sent interactor as
43
+ ARG contains calling of other interactors, it will try to find entries in them. More in specs
14
44
  email:
15
45
  - arslan.zamanov@flatstack.com
16
46
  executables:
17
- - grep
47
+ - grep-interactors
18
48
  extensions: []
19
49
  extra_rdoc_files: []
20
50
  files:
21
51
  - ".gitignore"
22
52
  - ".rspec"
53
+ - ".ruby-version"
23
54
  - ".travis.yml"
24
55
  - Gemfile
25
56
  - Gemfile.lock
@@ -27,14 +58,18 @@ files:
27
58
  - README.md
28
59
  - Rakefile
29
60
  - bin/console
30
- - bin/grep
61
+ - bin/grep-interactors
31
62
  - bin/setup
32
- - exe/grep
63
+ - exe/grep-interactors
33
64
  - grep-interactors.gemspec
34
- - lib/grep_in_paths.rb
65
+ - lib/containers/base.rb
35
66
  - lib/grep_interactors.rb
36
- - lib/parser.rb
37
- - lib/terminal_app.rb
67
+ - lib/grep_interactors/cli.rb
68
+ - lib/grep_interactors/grep_in_paths.rb
69
+ - lib/grep_interactors/parser.rb
70
+ - lib/grep_interactors/version.rb
71
+ - lib/string_matcher/default.rb
72
+ - lib/string_matcher/regex.rb
38
73
  homepage: https://github.com/ZamanovArslan/grep-interactors
39
74
  licenses:
40
75
  - MIT
data/bin/grep DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'grep_interactors'
4
-
5
- puts GrepInteractors.call(ARGV[0], ARGV[1], ARGV[2])
data/exe/grep DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'grep_interactors'
4
-
5
- puts GrepInteractors.call(ARGV[0], ARGV[1], ARGV[2])
@@ -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
@@ -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
@@ -1,3 +0,0 @@
1
- require_relative "grep_interactors"
2
-
3
- puts GrepInteractors.call(ARGV[0], ARGV[1], ARGV[2])