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.
@@ -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
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .byebug_history
13
+
14
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ ruby "2.7.0"
4
+
5
+ gemspec
6
+
7
+ gem "interactor"
8
+ gem "rake"
9
+ gem "rspec"
10
+ gem "activesupport"
11
+ gem "byebug"
12
+ gem "parser"
@@ -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
@@ -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.
@@ -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).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "grep_interactors"
@@ -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
@@ -0,0 +1,10 @@
1
+ require_relative "grep_in_paths"
2
+ require_relative "parser"
3
+
4
+ class GrepInteractors
5
+ def self.call(interactors_path, file_path, query)
6
+ file_paths = Parser.new(interactors_path, file_path).file_paths
7
+
8
+ GrepInPaths.call(query, file_paths)
9
+ end
10
+ end
@@ -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
@@ -0,0 +1,3 @@
1
+ require_relative "grep_interactors"
2
+
3
+ puts GrepInteractors.call(ARGV[0], ARGV[1], ARGV[2])
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: []