kanal 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +14 -0
  5. data/.ruby-version +1 -0
  6. data/.vscode/settings.json +8 -0
  7. data/CHANGELOG.md +15 -0
  8. data/Gemfile +26 -0
  9. data/Gemfile.lock +108 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +45 -0
  12. data/Rakefile +12 -0
  13. data/kanal.gemspec +39 -0
  14. data/lib/kanal/core/conditions/condition.rb +36 -0
  15. data/lib/kanal/core/conditions/condition_creator.rb +32 -0
  16. data/lib/kanal/core/conditions/condition_pack.rb +52 -0
  17. data/lib/kanal/core/conditions/condition_pack_creator.rb +41 -0
  18. data/lib/kanal/core/conditions/condition_storage.rb +58 -0
  19. data/lib/kanal/core/core.rb +214 -0
  20. data/lib/kanal/core/helpers/condition_finder.rb +26 -0
  21. data/lib/kanal/core/helpers/parameter_bag.rb +22 -0
  22. data/lib/kanal/core/helpers/parameter_bag_with_registrator.rb +46 -0
  23. data/lib/kanal/core/helpers/parameter_finder_with_method_missing_mixin.rb +38 -0
  24. data/lib/kanal/core/helpers/parameter_registrator.rb +48 -0
  25. data/lib/kanal/core/helpers/router_proc_parser.rb +47 -0
  26. data/lib/kanal/core/hooks/hook_storage.rb +109 -0
  27. data/lib/kanal/core/input/input.rb +20 -0
  28. data/lib/kanal/core/interfaces/interface.rb +65 -0
  29. data/lib/kanal/core/logger/logger.rb +12 -0
  30. data/lib/kanal/core/output/output.rb +31 -0
  31. data/lib/kanal/core/output/output_creator.rb +17 -0
  32. data/lib/kanal/core/plugins/plugin.rb +44 -0
  33. data/lib/kanal/core/router/router.rb +97 -0
  34. data/lib/kanal/core/router/router_node.rb +131 -0
  35. data/lib/kanal/core/router/router_storage.rb +33 -0
  36. data/lib/kanal/core/services/service_container.rb +97 -0
  37. data/lib/kanal/interfaces/simple_cli/simple_cli_interface.rb +51 -0
  38. data/lib/kanal/plugins/batteries/batteries_plugin.rb +116 -0
  39. data/lib/kanal/version.rb +5 -0
  40. data/lib/kanal.rb +9 -0
  41. data/sig/kanal/core/conditions/condition_pack.rbs +9 -0
  42. data/sig/kanal/core/conditions/condition_storage.rbs +9 -0
  43. data/sig/kanal.rbs +4 -0
  44. metadata +90 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 45f85bfae55ce0c37d296113ba2af2933667fd3fd7ec9e181ff12dd17105b524
4
+ data.tar.gz: 9f160009467a4cbf0412d266ae693b279064286ca91ec53e5ad55bb93582d31a
5
+ SHA512:
6
+ metadata.gz: f4275c770b3607a4617e5413a4634e2436fcb245af8dd3c6d3c5a86b39b64a70020f87ddb4c23323b9fcf3b640fd45bf572992edee3041bb5b918d6989fc79ab
7
+ data.tar.gz: 9c11421ecd4b230ab8d994b17a016b9e9649c9820ae9ad04503c8bbfa77798fd323fda5249c47cc6bd712d19493a7373d68dbb78fe559f08f53d4a36194776d3
data/.DS_Store ADDED
Binary file
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Layout/LineLength:
14
+ Max: 120
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.6
@@ -0,0 +1,8 @@
1
+ {
2
+ "ruby.interpreter.commandPath": "/Users/idchlife/.rvm/rubies/ruby-2.7.2/bin/ruby",
3
+ "ruby.useBundler": false,
4
+ "solargraph.commandPath": "bin/solargraph",
5
+ "solargraph.bundlerPath": "bin/bundle",
6
+ "solargraph.useBundler": true,
7
+ "solargraph.diagnostics": false
8
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.3.0]
4
+ - Kanal::Core::Core.get_plugin method added to get plugins for additional configuration by other plugins or developer code, if needed
5
+ - Kanal::Core::Plugins::Plugin.rake_tasks method introduced, for plugins to have their own rake tasks that can be merged inside
6
+ some kind of parent rake tasks, whether it's users Rakefile or kanal framework/interface or something Rakefile
7
+
8
+ ## [0.2.5] - 2022-11-15
9
+ - Private release with more features and tests, basically working core, router,
10
+ plugins, services, interfaces etc
11
+
12
+ ## [0.1.0] - 2022-05-24
13
+ - Initial release of library in private repository, with basic building blocks
14
+ like core, router, etc
15
+
data/Gemfile ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in kanal.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ # gem "method_source", "1.0.0"
13
+
14
+ # Move outside to plugin repo
15
+ # gem 'telegram-bot-ruby'
16
+
17
+ group :development do
18
+ gem "rubocop", "~> 1.21"
19
+ gem "ruby-debug-ide"
20
+ gem "solargraph"
21
+ gem "yard"
22
+ end
23
+
24
+ group :test do
25
+ gem "simplecov", require: false
26
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,108 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kanal (0.3.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ backport (1.2.0)
11
+ benchmark (0.2.0)
12
+ diff-lcs (1.5.0)
13
+ docile (1.4.0)
14
+ e2mmap (0.1.0)
15
+ jaro_winkler (1.5.4)
16
+ json (2.6.2)
17
+ kramdown (2.4.0)
18
+ rexml
19
+ kramdown-parser-gfm (1.1.0)
20
+ kramdown (~> 2.0)
21
+ mini_portile2 (2.8.0)
22
+ nokogiri (1.13.8)
23
+ mini_portile2 (~> 2.8.0)
24
+ racc (~> 1.4)
25
+ nokogiri (1.13.8-x86_64-darwin)
26
+ racc (~> 1.4)
27
+ parallel (1.22.1)
28
+ parser (3.1.2.0)
29
+ ast (~> 2.4.1)
30
+ racc (1.6.0)
31
+ rainbow (3.1.1)
32
+ rake (13.0.6)
33
+ regexp_parser (2.5.0)
34
+ reverse_markdown (2.1.1)
35
+ nokogiri
36
+ rexml (3.2.5)
37
+ rspec (3.11.0)
38
+ rspec-core (~> 3.11.0)
39
+ rspec-expectations (~> 3.11.0)
40
+ rspec-mocks (~> 3.11.0)
41
+ rspec-core (3.11.0)
42
+ rspec-support (~> 3.11.0)
43
+ rspec-expectations (3.11.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.11.0)
46
+ rspec-mocks (3.11.1)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.11.0)
49
+ rspec-support (3.11.0)
50
+ rubocop (1.33.0)
51
+ json (~> 2.3)
52
+ parallel (~> 1.10)
53
+ parser (>= 3.1.0.0)
54
+ rainbow (>= 2.2.2, < 4.0)
55
+ regexp_parser (>= 1.8, < 3.0)
56
+ rexml (>= 3.2.5, < 4.0)
57
+ rubocop-ast (>= 1.19.1, < 2.0)
58
+ ruby-progressbar (~> 1.7)
59
+ unicode-display_width (>= 1.4.0, < 3.0)
60
+ rubocop-ast (1.19.1)
61
+ parser (>= 3.1.1.0)
62
+ ruby-debug-ide (0.7.3)
63
+ rake (>= 0.8.1)
64
+ ruby-progressbar (1.11.0)
65
+ simplecov (0.21.2)
66
+ docile (~> 1.1)
67
+ simplecov-html (~> 0.11)
68
+ simplecov_json_formatter (~> 0.1)
69
+ simplecov-html (0.12.3)
70
+ simplecov_json_formatter (0.1.4)
71
+ solargraph (0.45.0)
72
+ backport (~> 1.2)
73
+ benchmark
74
+ bundler (>= 1.17.2)
75
+ diff-lcs (~> 1.4)
76
+ e2mmap
77
+ jaro_winkler (~> 1.5)
78
+ kramdown (~> 2.3)
79
+ kramdown-parser-gfm (~> 1.1)
80
+ parser (~> 3.0)
81
+ reverse_markdown (>= 1.0.5, < 3)
82
+ rubocop (>= 0.52)
83
+ thor (~> 1.0)
84
+ tilt (~> 2.0)
85
+ yard (~> 0.9, >= 0.9.24)
86
+ thor (1.2.1)
87
+ tilt (2.0.11)
88
+ unicode-display_width (2.2.0)
89
+ webrick (1.7.0)
90
+ yard (0.9.28)
91
+ webrick (~> 1.7.0)
92
+
93
+ PLATFORMS
94
+ ruby
95
+ x86_64-darwin-21
96
+
97
+ DEPENDENCIES
98
+ kanal!
99
+ rake (~> 13.0)
100
+ rspec (~> 3.0)
101
+ rubocop (~> 1.21)
102
+ ruby-debug-ide
103
+ simplecov
104
+ solargraph
105
+ yard
106
+
107
+ BUNDLED WITH
108
+ 2.3.12
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 idchlife
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.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Kanal
2
+
3
+ Welcome to kanal!
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add kanal
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install kanal
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## TODO
22
+
23
+ - [DONE] ~provide default response for branch with subbranches because default response could be handy~
24
+ Provided with the :flow condition pack with condition :any
25
+ - [DONE] ~rework hooks storage, make hooks without arguments validation~
26
+ - provide default logger with base class. this logger service should be used by every other service/plugin etc
27
+ - provide default response on error, when router node fails with error
28
+ - [DONE] ~provide :source condition for :source~
29
+ Created :source condition pack
30
+ - Allow to "append" conditions to condition packs
31
+
32
+
33
+ ## Development
34
+
35
+ 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.
36
+
37
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kanal.
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/kanal.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/kanal/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "kanal"
7
+ spec.version = Kanal::VERSION
8
+ spec.authors = ["idchlife"]
9
+ spec.email = ["idchlife@gmail.com"]
10
+
11
+ spec.summary = "Kanal library"
12
+ spec.description = "Thanks to the core library, ecosystem of Kanal tools can be extendted to use with input-output bot-like behaviour, with routing"
13
+ spec.homepage = "https://idchlife.github.io/kanal-documentation/"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.7.6"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/idchlife/kanal"
21
+ spec.metadata["changelog_uri"] = "https://github.com/idchlife/kanal/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+
37
+ # For more information and examples about making a new gem, check out our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
@@ -0,0 +1,36 @@
1
+ module Kanal
2
+ module Core
3
+ module Conditions
4
+ # Base class for conditions
5
+ # with this class you can
6
+ class Condition
7
+ attr_reader :name
8
+
9
+ def initialize(name, with_argument: false, &met_block)
10
+ @name = name
11
+
12
+ raise "Cannot create condition without block" unless met_block
13
+
14
+ @with_argument = with_argument
15
+
16
+ # NOTE: this whole bunch of code, including method, is used to allow
17
+ # in blocks returns without LocalJumpError
18
+ # Basically converting block/proc into lambda, which will allow
19
+ # unexpected returns for the comfortability of writing conditions
20
+ # Kudos to: https://stackoverflow.com/a/2946734/2739103
21
+ @proc_to_lambda_object = Object.new
22
+ @proc_to_lambda_object.define_singleton_method(:met_block, &met_block)
23
+ end
24
+
25
+ def with_argument?
26
+ @with_argument
27
+ end
28
+
29
+ # Check constructor for more info about this weird met block call
30
+ def met?(input, core, argument)
31
+ @proc_to_lambda_object.method(:met_block).call input, core, argument
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,32 @@
1
+ module Kanal
2
+ module Core
3
+ module Conditions
4
+ # This class helps creating conditions in dsl way,
5
+ # with using helper methods
6
+ class ConditionCreator
7
+ def initialize(name)
8
+ @name = name
9
+ @met_block = nil
10
+ @with_argument = false
11
+ end
12
+
13
+ def create(&block)
14
+ instance_eval(&block)
15
+
16
+ raise "Please provide name for condition" unless @name
17
+ raise "Please provide met? block for condition #{@name}" unless @met_block
18
+
19
+ Condition.new @name, with_argument: @with_argument, &@met_block
20
+ end
21
+
22
+ def with_argument
23
+ @with_argument = true
24
+ end
25
+
26
+ def met?(&block)
27
+ @met_block = block
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,52 @@
1
+ require_relative "./condition"
2
+ require_relative "./condition_creator"
3
+
4
+ module Kanal
5
+ module Core
6
+ module Conditions
7
+ # This class stores conditions inside
8
+ # It is served as some kind of namespace for conditions, with specific
9
+ # name of pack and helper methods
10
+ class ConditionPack
11
+ attr_reader :name
12
+
13
+ def initialize(name)
14
+ @name = name
15
+ @conditions = []
16
+ end
17
+
18
+ def get_condition_by_name!(name)
19
+ condition = get_condition_by_name name
20
+
21
+ raise "Condition #{name} was not found in pack #{@name}. Maybe it was not added?" unless condition
22
+
23
+ condition
24
+ end
25
+
26
+ def get_condition_by_name(name)
27
+ @conditions.find { |c| c.name == name }
28
+ end
29
+
30
+ def register_condition(condition)
31
+ raise "Can register only conditions that inherit Condition class" unless condition.is_a? Condition
32
+
33
+ return self if condition_registered? condition
34
+
35
+ @conditions.append condition
36
+
37
+ self
38
+ end
39
+
40
+ def condition_registered?(condition)
41
+ @conditions.each do |c|
42
+ return true if c.name == condition.name
43
+ end
44
+
45
+ false
46
+ end
47
+
48
+ private :condition_registered?
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,41 @@
1
+ require_relative "./condition_pack"
2
+ require_relative "./condition_creator"
3
+
4
+ module Kanal
5
+ module Core
6
+ module Conditions
7
+ # This class helps in condition pack creation
8
+ # with the help of dsl
9
+ class ConditionPackCreator
10
+ TEMP_NAME = :temp_name
11
+
12
+ def initialize(name)
13
+ @name = name
14
+ @conditions = []
15
+ end
16
+
17
+ def create(&block)
18
+ instance_eval(&block)
19
+
20
+ raise "Please provide condition pack name" unless @name
21
+
22
+ raise "Please provide conditions for condition pack #{@name}" if @conditions.empty?
23
+
24
+ pack = ConditionPack.new(@name)
25
+
26
+ @conditions.each do |c|
27
+ pack.register_condition c
28
+ end
29
+
30
+ pack
31
+ end
32
+
33
+ def add_condition(name, &block)
34
+ creator = ConditionCreator.new name
35
+ condition = creator.create(&block)
36
+ @conditions.append condition
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,58 @@
1
+ module Kanal
2
+ module Core
3
+ module Conditions
4
+ # This class contains all needed functionality to store,
5
+ # search conditions
6
+ class ConditionStorage
7
+ def initialize
8
+ @condition_packs = []
9
+ end
10
+
11
+ def get_condition_pack_by_name!(name)
12
+ pack = get_condition_pack_by_name name
13
+
14
+ raise "Condition pack #{name} is not registered, but was requested from ConditionStorage" unless pack
15
+
16
+ pack
17
+ end
18
+
19
+ def get_condition_pack_by_name(name)
20
+ @condition_packs.find { |p| p.name == name }
21
+ end
22
+
23
+ def condition_pack_or_condition_exists?(name)
24
+ pack = get_condition_pack_by_name name
25
+
26
+ unless pack
27
+ found_condition = false
28
+ # Checking every pack for conditions inside of it
29
+ @condition_packs.each do |cp|
30
+ condition = cp.get_condition_by_name name
31
+
32
+ if condition
33
+ found_condition = true
34
+ break
35
+ end
36
+ end
37
+
38
+ return found_condition
39
+ end
40
+
41
+ !pack.nil?
42
+ end
43
+
44
+ def register_condition_pack(pack)
45
+ return if condition_pack_exists? pack
46
+
47
+ raise "Condition pack should be descendant of ConditionPack class" unless pack.is_a? ConditionPack
48
+
49
+ @condition_packs.append pack
50
+ end
51
+
52
+ def condition_pack_exists?(pack)
53
+ !(@condition_packs.find { |cp| cp.name == pack.name }).nil?
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end