grep-interactors 0.1.0 → 0.1.5

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: dd1ccd7dd934649a98013455d25e771fc047f2c520461b45edceb029f4fc2720
4
- data.tar.gz: 3016cacc4d01fb136c0cf3af02cead00ce434588c4a705d287550dd1e9804052
3
+ metadata.gz: 854569c021db02cca1255e15def32b75f97da3a55801784e1c252b4acb63a7fa
4
+ data.tar.gz: 8bc1a8d811b39cc30afb51893c1ef6b372c509239dab479f9a43f5da437446ab
5
5
  SHA512:
6
- metadata.gz: 63ad9c42824083e1140fd046acb5e1bea1d41776fc0432e8232ecb2391cdf82e2b9b4e0d6a6c4d730cd61a8eed340abfea373ab431c1b5045e499b97a4f39be6
7
- data.tar.gz: 8cf8d7006ed8a9e5ec04539d770327f2b18c4172060033ba951b42507e2936a6928579defaac3f113f3613e2cfafda4073cefa5c6c15c6df02fe4c641010a392
6
+ metadata.gz: b75b6d5cd1a205bfb4050d65b0d097c69ec636bdc59d3f0994da3894d2a7ba3f56f2a85d28fb430789313d850acf430ae19e6380680390e786bb54645e36a7c6
7
+ data.tar.gz: abdc2c2b9bd83f71396d776bf269960350c4226c7e64b71bd764e3b229ec89ae79ed9d04a44752d9f17d52ad53ab71c6f3aaaddadef411a01cff08a0b7080b39
@@ -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.0)
4
+ grep-interactors (0.1.4)
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
@@ -1,6 +1,8 @@
1
+ [![Gem Version](https://badge.fury.io/rb/grep-interactors.svg)](https://badge.fury.io/rb/grep-interactors)
2
+
1
3
  # Grep::Interactors
2
4
 
3
- Gem, which helps realize grep through organized Interactors.
5
+ Gem, which helps grep through organized Interactors.
4
6
  For example, if sent interactor as ARG contains calling of other interactors, it will try to find entries in them.
5
7
  More in spec/
6
8
 
@@ -24,11 +26,23 @@ Or install it yourself as:
24
26
 
25
27
  ## How to run
26
28
  ```bash
27
- $ grep-interactors terminal_app interactors_path file_path keyword
29
+ $ grep-interactors interactors_path file_path keyword
28
30
  ```
29
31
  eg
30
32
  ```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
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
32
46
  ```
33
47
  _Works only with absolute path for now_
34
48
 
@@ -38,6 +52,11 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
38
52
 
39
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).
40
54
 
55
+ ## Roadmap
56
+ * Add docs
57
+ * intellij idea plugin
58
+ * Sublime Text 3 package
59
+
41
60
  ## Contributing
42
61
 
43
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)
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "grep_interactors"
4
+
5
+ GrepInteractors::Cli.call(ARGV)
@@ -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 = "0.1.0"
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 = "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"
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,12 +21,14 @@ 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
- # 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.
24
+ spec.add_runtime_dependency 'dry-auto_inject'
25
+ spec.add_runtime_dependency 'activesupport'
26
+
20
27
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
28
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
29
  end
23
30
  spec.bindir = "exe"
24
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+
25
33
  spec.require_paths = ["lib"]
26
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.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,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.5"
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,16 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grep-interactors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
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:
@@ -20,6 +50,7 @@ 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,13 +58,18 @@ files:
27
58
  - README.md
28
59
  - Rakefile
29
60
  - bin/console
61
+ - bin/grep-interactors
30
62
  - bin/setup
31
63
  - exe/grep-interactors
32
64
  - grep-interactors.gemspec
33
- - lib/grep_in_paths.rb
65
+ - lib/containers/base.rb
34
66
  - lib/grep_interactors.rb
35
- - lib/parser.rb
36
- - 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
37
73
  homepage: https://github.com/ZamanovArslan/grep-interactors
38
74
  licenses:
39
75
  - MIT
@@ -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])