grep-interactors 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d6a1bc71641b2b1683ca2c35892ebb15f365c38ac9e150e9ea8e696d7818363
4
- data.tar.gz: 33221ec7aadb4f246e9aae9076ece6216d73874348a2a6ddf0611946031bad68
3
+ metadata.gz: 1e3e12d742ed0f4ae908b3d4450363ff4895fa706a58546bfb6a24677703921f
4
+ data.tar.gz: f82e5bbcf97d93dde28735a6cf0a9ed5ff0b0a89e93a45387b3701122a09dfac
5
5
  SHA512:
6
- metadata.gz: 42bb60b9ebeff22d5d10211c8b1b21684ca5df34177f003f51efbae55ede72c96d3cdc60042e3ea8e96fedbb459c0c205f25086d213b56229517f15e96276835
7
- data.tar.gz: 28b0964bc7f7eb48c0fd8ad7236f8e806ad167164252a433e99847cc6fe78a0b96d8f61b03fc91aaa596f4cddf75de0c4f097525ced92f96ae6504ae56c46e3d
6
+ metadata.gz: dd8857b59eb8a0f586e50a296839f5e3d3afe584bda196b8a0524130bb65dd18607d3b41ddc8958f2214150539d81d1fd10a14e9b88ed5b6e0235e85fc736855
7
+ data.tar.gz: 24c2c3f0b265dac5a7c21ba4c1f146774f0e8753b3396a8f638a6bfd9716dc28e19abe4d318f51dd2a2c0b13a930bea11b635e451ecf13bff92911d2f895945e
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grep-interactors (0.1.2)
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 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
 
@@ -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 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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'cli'
3
+ require "grep_interactors"
4
4
 
5
- Cli.call(ARGV[0], ARGV[1], ARGV[2])
5
+ GrepInteractors::Cli.call(ARGV)
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'cli'
3
+ require "grep_interactors"
4
4
 
5
- Cli.call(ARGV[0], ARGV[1], ARGV[2])
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.2"
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,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
- # 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
+
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
@@ -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,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
@@ -0,0 +1,3 @@
1
+ module GrepInteractors
2
+ VERSION = "0.1.3"
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,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grep-interactors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
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-18 00:00:00.000000000 Z
12
- dependencies: []
13
- description: WIP
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/cli.rb
35
- - lib/grep_in_paths.rb
50
+ - lib/containers/base.rb
36
51
  - lib/grep_interactors.rb
37
- - lib/parser.rb
38
- - lib/terminal_app.rb
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
@@ -1,9 +0,0 @@
1
- require_relative "grep_interactors"
2
-
3
- class Cli
4
- def self.call(interactors_path, file_path, query, out = STDOUT)
5
- out << GrepInteractors.call(interactors_path, file_path, query).join("\n")
6
- out << "\n"
7
- exit 0
8
- end
9
- end
@@ -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])