mona 0.2.3 → 0.4.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.

Potentially problematic release.


This version of mona might be problematic. Click here for more details.

Files changed (98) hide show
  1. data/.document +5 -0
  2. data/.rspec +0 -2
  3. data/.travis.yml +3 -0
  4. data/Gemfile +9 -0
  5. data/LICENSE.txt +17 -18
  6. data/README.md +2 -192
  7. data/Rakefile +46 -5
  8. data/VERSION +1 -0
  9. data/lib/mona/board.rb +50 -0
  10. data/lib/mona/client.rb +10 -0
  11. data/lib/mona/response.rb +27 -0
  12. data/lib/mona/thread.rb +64 -0
  13. data/lib/mona.rb +22 -105
  14. data/mona.gemspec +66 -47
  15. data/spec/board_spec.rb +27 -0
  16. data/spec/client_spec.rb +15 -0
  17. data/spec/mona_spec.rb +5 -0
  18. data/spec/response_spec.rb +39 -0
  19. data/spec/spec_helper.rb +12 -0
  20. data/spec/test_data/dat.txt +119 -0
  21. data/spec/test_data/subject.txt +2 -0
  22. data/spec/thread_spec.rb +68 -0
  23. metadata +75 -219
  24. checksums.yaml +0 -7
  25. data/.ruby-version +0 -1
  26. data/.standard.yml +0 -3
  27. data/CHANGELOG.md +0 -5
  28. data/CODE_OF_CONDUCT.md +0 -84
  29. data/example/Gemfile +0 -1
  30. data/example/Gemfile.lock +0 -51
  31. data/example/Monafile.rb +0 -16
  32. data/example/bounded_contexts/cart/cart_app/Package.rb +0 -11
  33. data/example/bounded_contexts/cart/cart_app/bin/console +0 -11
  34. data/example/bounded_contexts/cart/cart_app/package/cart_app.rb +0 -2
  35. data/example/bounded_contexts/cart/cart_core/Package.rb +0 -12
  36. data/example/bounded_contexts/cart/cart_core/bin/console +0 -9
  37. data/example/bounded_contexts/cart/cart_core/package/cart_core.rb +0 -2
  38. data/example/bounded_contexts/cart/cart_datasets/Package.rb +0 -10
  39. data/example/bounded_contexts/cart/cart_datasets/bin/console +0 -9
  40. data/example/bounded_contexts/cart/cart_datasets/package/cart_datasets.rb +0 -2
  41. data/example/bounded_contexts/orders/orders_app/Package.rb +0 -12
  42. data/example/bounded_contexts/orders/orders_app/bin/console +0 -9
  43. data/example/bounded_contexts/orders/orders_app/package/orders_app.rb +0 -2
  44. data/example/bounded_contexts/orders/orders_core/Package.rb +0 -13
  45. data/example/bounded_contexts/orders/orders_core/bin/console +0 -9
  46. data/example/bounded_contexts/orders/orders_core/package/orders_core.rb +0 -2
  47. data/example/bounded_contexts/orders/orders_datasets/Package.rb +0 -11
  48. data/example/bounded_contexts/orders/orders_datasets/bin/console +0 -9
  49. data/example/bounded_contexts/orders/orders_datasets/package/orders_datasets.rb +0 -2
  50. data/example/bounded_contexts/orders/orders_query_api/Package.rb +0 -13
  51. data/example/bounded_contexts/orders/orders_query_api/bin/console +0 -9
  52. data/example/bounded_contexts/orders/orders_query_api/package/cart_query_api.rb +0 -2
  53. data/example/bounded_contexts/orders/paypal_client/Package.rb +0 -9
  54. data/example/bounded_contexts/orders/paypal_client/bin/console +0 -9
  55. data/example/bounded_contexts/orders/paypal_client/package/paypal_client.rb +0 -2
  56. data/example/bounded_contexts/shared/db_connection/Package.rb +0 -10
  57. data/example/bounded_contexts/shared/db_connection/bin/console +0 -9
  58. data/example/bounded_contexts/shared/db_connection/package/db_connection.rb +0 -2
  59. data/example/bounded_contexts/shared/test_utils/Package.rb +0 -9
  60. data/example/bounded_contexts/shared/test_utils/bin/console +0 -9
  61. data/example/bounded_contexts/shared/test_utils/package/test_utils.rb +0 -2
  62. data/example/bounded_contexts/storefront/storefront_app/Package.rb +0 -11
  63. data/example/bounded_contexts/storefront/storefront_app/bin/console +0 -9
  64. data/example/bounded_contexts/storefront/storefront_app/package/storefront_app.rb +0 -2
  65. data/example/bounded_contexts/storefront/storefront_core/Package.rb +0 -11
  66. data/example/bounded_contexts/storefront/storefront_core/bin/console +0 -9
  67. data/example/bounded_contexts/storefront/storefront_core/package/storefront_core.rb +0 -2
  68. data/example/bounded_contexts/storefront/storefront_datasets/Package.rb +0 -11
  69. data/example/bounded_contexts/storefront/storefront_datasets/bin/console +0 -9
  70. data/example/bounded_contexts/storefront/storefront_datasets/package/storefront_datasets.rb +0 -2
  71. data/example/configs/cart_app/default.yml +0 -4
  72. data/example/configs/cart_app/test.yml +0 -3
  73. data/example/configs/orders_app/default.yml +0 -4
  74. data/example/configs/orders_app/test.yml +0 -2
  75. data/exe/mona +0 -15
  76. data/lib/mona/config/loader.rb +0 -74
  77. data/lib/mona/config/manager.rb +0 -20
  78. data/lib/mona/config.rb +0 -23
  79. data/lib/mona/loaders/base.rb +0 -63
  80. data/lib/mona/loaders/zeitwerk.rb +0 -77
  81. data/lib/mona/package/builder.rb +0 -27
  82. data/lib/mona/package/dependency_bypasser.rb +0 -43
  83. data/lib/mona/package/factory.rb +0 -95
  84. data/lib/mona/package/find_root.rb +0 -33
  85. data/lib/mona/package/indexer.rb +0 -30
  86. data/lib/mona/package/initializer.rb +0 -46
  87. data/lib/mona/package/list.rb +0 -10
  88. data/lib/mona/package/repo.rb +0 -63
  89. data/lib/mona/package.rb +0 -51
  90. data/lib/mona/project/builder.rb +0 -20
  91. data/lib/mona/project/factory.rb +0 -115
  92. data/lib/mona/project/find_root.rb +0 -31
  93. data/lib/mona/project/initializer.rb +0 -26
  94. data/lib/mona/project.rb +0 -43
  95. data/lib/mona/task/manager.rb +0 -36
  96. data/lib/mona/task.rb +0 -21
  97. data/lib/mona/version.rb +0 -5
  98. data/sig/mona.rbs +0 -4
@@ -1,13 +0,0 @@
1
- package do
2
- name 'orders_core'
3
- end
4
-
5
- dependency do
6
- import 'orders_datasets'
7
- import 'paypal_client'
8
- end
9
-
10
- dependency :test do
11
- import 'test_utils'
12
- import 'storefront_core'
13
- end
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'mona'
5
-
6
- Mona.init(__dir__)
7
-
8
- require 'irb'
9
- IRB.start
@@ -1,2 +0,0 @@
1
- module OrdersCore
2
- end
@@ -1,11 +0,0 @@
1
- package do
2
- name 'orders_datasets'
3
- end
4
-
5
- dependency do
6
- import 'db_connection'
7
- end
8
-
9
- dependency :test do
10
- import 'test_utils'
11
- end
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'mona'
5
-
6
- Mona.init(__dir__)
7
-
8
- require 'irb'
9
- IRB.start
@@ -1,2 +0,0 @@
1
- module OrdersDatasets
2
- end
@@ -1,13 +0,0 @@
1
- package do
2
- name 'cart_query_api'
3
- end
4
-
5
- dependency do
6
- import 'orders_core'
7
- import 'orders_datasets'
8
- end
9
-
10
- dependency :test do
11
- import 'test_utils'
12
- import 'storefront_core'
13
- end
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'mona'
5
-
6
- Mona.init(__dir__)
7
-
8
- require 'irb'
9
- IRB.start
@@ -1,2 +0,0 @@
1
- module CartQueryApi
2
- end
@@ -1,9 +0,0 @@
1
- package do
2
- name 'paypal_client'
3
- end
4
-
5
- dependency do
6
- end
7
-
8
- dependency :test do
9
- end
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'mona'
5
-
6
- Mona.init(__dir__)
7
-
8
- require 'irb'
9
- IRB.start
@@ -1,2 +0,0 @@
1
- module PaypalClient
2
- end
@@ -1,10 +0,0 @@
1
- package do
2
- name 'db_connection'
3
- end
4
-
5
- dependency do
6
- end
7
-
8
- dependency :test do
9
- import 'test_utils'
10
- end
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'mona'
5
-
6
- Mona.init(__dir__)
7
-
8
- require 'irb'
9
- IRB.start
@@ -1,2 +0,0 @@
1
- module DbConnection
2
- end
@@ -1,9 +0,0 @@
1
- package do
2
- name 'test_utils'
3
- end
4
-
5
- dependency do
6
- end
7
-
8
- dependency :test do
9
- end
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'mona'
5
-
6
- Mona.init(__dir__)
7
-
8
- require 'irb'
9
- IRB.start
@@ -1,2 +0,0 @@
1
- module TestUtils
2
- end
@@ -1,11 +0,0 @@
1
- package do
2
- name 'storefront_app'
3
- end
4
-
5
- dependency do
6
- import 'storefront_core'
7
- end
8
-
9
- dependency :test do
10
- import 'test_utils'
11
- end
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'mona'
5
-
6
- Mona.init(__dir__)
7
-
8
- require 'irb'
9
- IRB.start
@@ -1,2 +0,0 @@
1
- module StorefrontApp
2
- end
@@ -1,11 +0,0 @@
1
- package do
2
- name 'storefront_core'
3
- end
4
-
5
- dependency do
6
- import 'storefront_datasets'
7
- end
8
-
9
- dependency :test do
10
- import 'test_utils'
11
- end
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'mona'
5
-
6
- Mona.init(__dir__)
7
-
8
- require 'irb'
9
- IRB.start
@@ -1,2 +0,0 @@
1
- module StorefrontCore
2
- end
@@ -1,11 +0,0 @@
1
- package do
2
- name 'storefront_datasets'
3
- end
4
-
5
- dependency do
6
- import 'db_connection'
7
- end
8
-
9
- dependency :test do
10
- import 'test_utils'
11
- end
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'mona'
5
-
6
- Mona.init(__dir__)
7
-
8
- require 'irb'
9
- IRB.start
@@ -1,2 +0,0 @@
1
- module StorefrontDatasets
2
- end
@@ -1,4 +0,0 @@
1
- cart_app:
2
- host: 'some_host'
3
- port: 1234
4
- db: 'some_db'
@@ -1,3 +0,0 @@
1
- cart_app:
2
- host: 'some_test_host'
3
- db: 'some_test_db'
@@ -1,4 +0,0 @@
1
- orders_app:
2
- host: 'some_host'
3
- port: 1234
4
- db: 'some_db'
@@ -1,2 +0,0 @@
1
- orders_app:
2
- host: 'some_test_host'
data/exe/mona DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "mona"
6
- require "thor"
7
-
8
- class MonaCli < Thor
9
- desc "mona cd PACKAGE", "go to PACKAGE"
10
- def cd(package)
11
- puts "cd #{Mona.packages(File.expand_path(".")).find(package.to_sym).root_path}"
12
- end
13
- end
14
-
15
- MonaCli.start(ARGV)
@@ -1,74 +0,0 @@
1
- require 'yaml'
2
- require 'erb'
3
- require 'ostruct'
4
-
5
- class Mona::Config::Loader
6
- include Mona::Mixins
7
-
8
- DEFAULT_CONFIG_FILENAME = 'default.yml'
9
-
10
- sig do
11
- params(
12
- config_name: T.any(String, Symbol),
13
- )
14
- .returns(Mona::Config)
15
- end
16
- def call(config_name)
17
- config_name = config_name.to_s
18
- config = Mona::Config.new
19
-
20
- default_config_filename = File.join(
21
- Mona.current_project.root_path,
22
- Mona.current_project.configs_dir,
23
- config_name,
24
- DEFAULT_CONFIG_FILENAME
25
- )
26
-
27
- unless File.exist?(default_config_filename)
28
- raise StandardError.new("Config '#{config_name}' was not found. Add it to '#{default_config_filename}'")
29
- end
30
-
31
- hash =
32
- begin
33
- YAML.load( ERB.new(File.read(default_config_filename)).result )
34
- rescue => e
35
- puts ERB.new(File.read(default_config_filename)).result.inspect
36
- end
37
-
38
- hash_to_config(
39
- hash: hash,
40
- config: config
41
- )
42
-
43
- env_config_filename = File.join(
44
- Mona.current_project.root_path,
45
- Mona.current_project.configs_dir,
46
- config_name,
47
- "#{Mona.current_project.env}.yml"
48
- )
49
-
50
- hash_to_config(
51
- hash: YAML.load( ERB.new(File.read(env_config_filename)).result ),
52
- config: config
53
- ) if File.exist?(env_config_filename)
54
-
55
- config.send(config_name)
56
- end
57
-
58
- private
59
-
60
- def hash_to_config(hash:, config:)
61
- hash.each do |key, value|
62
- if value.is_a?(Hash)
63
- nested_config = config.read_attribute(key)
64
- if nested_config.nil? || !nested_config.is_a?(Mona::Config)
65
- nested_config = Mona::Config.new
66
- end
67
- hash_to_config(hash: value, config: nested_config)
68
- config.write_attribute(key, nested_config)
69
- else
70
- config.write_attribute(key, value)
71
- end
72
- end
73
- end
74
- end
@@ -1,20 +0,0 @@
1
- class Mona::Config::Manager
2
- include Mona::Mixins
3
-
4
- Inject = Mona::Deps[
5
- config_loader: "config.loader"
6
- ]
7
-
8
- include Inject
9
-
10
- sig do
11
- params(
12
- method_name: Symbol,
13
- args: T.anything
14
- )
15
- .returns(Mona::Config)
16
- end
17
- def method_missing(method_name, *args)
18
- config_loader.call(method_name)
19
- end
20
- end
data/lib/mona/config.rb DELETED
@@ -1,23 +0,0 @@
1
- class Mona::Config
2
- def initialize(attributes = {})
3
- @attributes = attributes
4
- end
5
-
6
- def read_attribute(key)
7
- @attributes[key.to_s]
8
- end
9
-
10
- def write_attribute(key, value)
11
- @attributes[key.to_s] = value
12
- end
13
-
14
- def method_missing(method_name, *_args)
15
- read_attribute(method_name)
16
- end
17
-
18
- def to_h
19
- @attributes.each_with_object({}) do |(k, v), h|
20
- h[k] = self.class === v ? v.to_h : v
21
- end
22
- end
23
- end
@@ -1,63 +0,0 @@
1
- class Mona::Loaders::Base
2
- include Mona::Mixins
3
-
4
- class << self
5
- def registry
6
- @registry ||= {}
7
- end
8
-
9
- def inherited(subclass)
10
- name = subclass.to_s.split("::").last.downcase.to_sym
11
-
12
- registry[name] = subclass
13
- end
14
- end
15
-
16
- attr_reader :overwriters, :inflections, :ignore_dirs, :autoload_dirs, :loader, :root_path
17
-
18
- def initialize(root_path, &block)
19
- @root_path = root_path
20
- @overwriters = []
21
- @inflections = {}
22
- @ignore_dirs = []
23
- @autoload_dirs = []
24
-
25
- instance_exec(&block) if block_given?
26
- end
27
-
28
- def push_dir(dir)
29
- @autoload_dirs.push(dir)
30
- end
31
-
32
- def setup
33
- raise StandardError.new('not implemented')
34
- end
35
-
36
- def reload
37
- raise StandardError.new('not implemented')
38
- end
39
-
40
- def eager_load
41
- raise StandardError.new('not implemented')
42
- end
43
-
44
- def check_classes
45
- raise StandardError.new('not implemented')
46
- end
47
-
48
- module SetupDsl
49
- def inflect(hash)
50
- @inflections.merge!(hash)
51
- end
52
-
53
- def overwrite(proc)
54
- overwriters.push(proc)
55
- end
56
-
57
- def ignore(glob)
58
- @ignore_dirs.push(glob)
59
- end
60
- end
61
-
62
- include SetupDsl
63
- end
@@ -1,77 +0,0 @@
1
- require 'zeitwerk'
2
- require 'benchmark'
3
-
4
- class Mona::Loaders::Zeitwerk < Mona::Loaders::Base
5
- include Mona::Mixins
6
-
7
- ERROR_MESSAGE_REGEX = /expected file (?<path>[\w\/]+.rb) to define constant (?<klass>[\w:]+)/
8
-
9
- def initialize(...)
10
- @loader = Zeitwerk::Loader.new
11
- @loader.inflector = Class.new(Zeitwerk::Inflector).new
12
-
13
- super(...)
14
- end
15
-
16
- def setup
17
- apply_rules_for(@loader)
18
- @loader.setup
19
- end
20
-
21
- def eager_load
22
- time = Benchmark.realtime do
23
- @loader.eager_load
24
- end
25
-
26
- puts "eager_load dependencies in #{'%.2f' % time} seconds"
27
- end
28
-
29
- def check_classes
30
- check_classes_loader = @loader.dup
31
- check_classes_loader.on_load { |cpath, value, abspath| puts value }
32
-
33
- errors = []
34
-
35
- begin
36
- check_classes_loader.eager_load
37
- rescue Zeitwerk::NameError => e
38
- match = e.message.match(ERROR_MESSAGE_REGEX)
39
-
40
- raise e if match.nil?
41
-
42
- # TODO: use logger
43
- errors << "#{match[:path]} => #{match[:klass]}"
44
- check_classes_loader.ignore(match[:path])
45
- retry
46
- end
47
-
48
- puts errors
49
- raise StandardError.new("loader fails with #{errors.count} errors") if errors.any?
50
-
51
- nil
52
- end
53
-
54
- def apply_rules_for(entity)
55
- @autoload_dirs.uniq.each { entity.push_dir(_1) }
56
- @ignore_dirs.uniq
57
- .map { File.join(Mona.current_project.root_path, _1) }
58
- .each { entity.ignore( _1 ) }
59
-
60
- entity.inflector.inflect(@inflections)
61
-
62
- result_overwriter = ->(kname) { @overwriters.each { |o| kname = o.call(kname) }; kname }
63
- entity.inflector.define_singleton_method(:camelize) do |basename, abspath|
64
- result_overwriter.call( super(basename, abspath) )
65
- end
66
- end
67
-
68
- def ignore(glob)
69
- super(glob)
70
-
71
- # TODO: if loader.setup is true => push dir directly to the @loader
72
- @ignore_dirs
73
- .uniq
74
- .map { File.join(root_path, _1) }
75
- .each { @loader.ignore( _1 ) }
76
- end
77
- end
@@ -1,27 +0,0 @@
1
- class Mona::Package::Builder
2
- include Mona::Mixins
3
-
4
- Inject = Mona::Deps[
5
- "package.find_root",
6
- "package.factory"
7
- ]
8
-
9
- include Inject
10
-
11
- sig do
12
- params(
13
- package_path: String,
14
- project_root: String,
15
- package_dirname: String
16
- )
17
- .returns(Mona::Package)
18
- end
19
- def call(package_path, project_root, package_dirname)
20
- package_root_path = find_root.call(package_path, project_root)
21
- package_file_path = "#{package_root_path}/#{Mona::PACKAGE_FILENAME}"
22
-
23
- package_init_proc = proc { instance_eval(File.read(package_file_path)) }
24
-
25
- package = factory.call(package_root_path, package_dirname, init_proc: package_init_proc)
26
- end
27
- end
@@ -1,43 +0,0 @@
1
- require 'set'
2
-
3
- class Mona::Package::DependencyBypasser
4
- include Mona::Mixins
5
-
6
- Inject = Mona::Deps[
7
- packages_repo: "package.repo"
8
- ]
9
-
10
- include Inject
11
-
12
- sig do
13
- params(
14
- package_name: Symbol,
15
- env: Symbol,
16
- )
17
- .returns(T::Array[Symbol])
18
- end
19
- def call(package_name:, env:)
20
- walk(package_name: package_name, env: env, imported: Set.new)
21
- end
22
-
23
- private
24
-
25
- def walk(package_name:, env:, imported:, packages_order: [])
26
- package = packages_repo.find!(package_name)
27
-
28
- return if !imported.add?(package_name)
29
-
30
- package_dependencies = package.get_dependencies(env)
31
-
32
- package_dependencies.each do |name|
33
- walk(
34
- package_name: name,
35
- imported: imported,
36
- packages_order: packages_order,
37
- env: Mona::Package::DEFAULT_ENV,
38
- )
39
- end
40
-
41
- packages_order.push(package_name)
42
- end
43
- end