hecks 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/bin/hecks +6 -0
  3. data/bin/hecks_console +10 -0
  4. data/lib/adapters/adapters.rb +6 -0
  5. data/lib/adapters/events/events.rb +27 -0
  6. data/lib/adapters/logger/logger.rb +18 -0
  7. data/lib/adapters/memory_database/memory_database.rb +18 -0
  8. data/lib/adapters/resource_server/methods.rb +22 -0
  9. data/lib/adapters/resource_server/methods/create.rb +49 -0
  10. data/lib/adapters/resource_server/methods/delete.rb +45 -0
  11. data/lib/adapters/resource_server/methods/read.rb +44 -0
  12. data/lib/adapters/resource_server/methods/update.rb +50 -0
  13. data/lib/adapters/resource_server/resource_server.rb +52 -0
  14. data/lib/adapters/validator/validator.rb +33 -0
  15. data/lib/application/application.rb +45 -0
  16. data/lib/application/commands/commands.rb +5 -0
  17. data/lib/application/commands/create.rb +52 -0
  18. data/lib/application/commands/crud_handler.rb +40 -0
  19. data/lib/application/commands/delete.rb +40 -0
  20. data/lib/application/commands/runner.rb +48 -0
  21. data/lib/application/commands/update.rb +41 -0
  22. data/lib/application/queries/find_by_id.rb +19 -0
  23. data/lib/application/queries/queries.rb +2 -0
  24. data/lib/application/queries/query_runner.rb +28 -0
  25. data/lib/cli/cli.rb +24 -0
  26. data/lib/cli/command_runner.rb +25 -0
  27. data/lib/cli/commands.rb +5 -0
  28. data/lib/cli/commands/build.rb +10 -0
  29. data/lib/cli/commands/console.rb +8 -0
  30. data/lib/cli/commands/generate.rb +26 -0
  31. data/lib/cli/commands/generate/builder.rb +60 -0
  32. data/lib/cli/commands/generate/builder/aggregate_command_line_builder.rb +18 -0
  33. data/lib/cli/commands/generate/builder/reference_command_line_builder.rb +19 -0
  34. data/lib/cli/commands/generate/builder/value_object_command_line_builder.rb +19 -0
  35. data/lib/cli/commands/generate/generate_aws_package.rb +17 -0
  36. data/lib/cli/commands/generate/generate_binary_package.rb +92 -0
  37. data/lib/cli/commands/generate/generate_domain_object.rb +71 -0
  38. data/lib/cli/commands/generate/generate_domain_object/assignment_template.rb +36 -0
  39. data/lib/cli/commands/generate/generate_domain_object/option_formatter.rb +30 -0
  40. data/lib/cli/commands/generate/generate_lambda_package.rb +20 -0
  41. data/lib/cli/commands/generate/generate_resource_server.rb +17 -0
  42. data/lib/cli/commands/generate/new.rb +47 -0
  43. data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/%head_name%.rb.tt +16 -0
  44. data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/%name%.rb.tt +9 -0
  45. data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/repository.rb.tt +40 -0
  46. data/lib/cli/commands/generate/templates/binary_package/build/linux-x86_64/lib/app/hello.rb +1 -0
  47. data/lib/cli/commands/generate/templates/binary_package/build/resources/%domain_name%.rb.tt +17 -0
  48. data/lib/cli/commands/generate/templates/binary_package/build/resources/Dockerfile.tt +8 -0
  49. data/lib/cli/commands/generate/templates/binary_package/build/resources/Gemfile.tt +4 -0
  50. data/lib/cli/commands/generate/templates/binary_package/build/resources/bundle/config +3 -0
  51. data/lib/cli/commands/generate/templates/binary_package/build/resources/wrapper.tt +13 -0
  52. data/lib/cli/commands/generate/templates/domain/%name%.gemspec.tt +12 -0
  53. data/lib/cli/commands/generate/templates/domain/Version +1 -0
  54. data/lib/cli/commands/generate/templates/domain/lib/%name%.rb.tt +21 -0
  55. data/lib/cli/commands/generate/templates/domain/spec/spec_helper.rb.tt +4 -0
  56. data/lib/cli/commands/generate/templates/lambda_package/handler.js.tt +12 -0
  57. data/lib/cli/commands/generate/templates/lambda_package/serverless.yml.tt +100 -0
  58. data/lib/cli/commands/generate/templates/reference/lib/domain/%module_name%/%file_name%.rb.tt +25 -0
  59. data/lib/cli/commands/generate/templates/resource_server/config.ru.tt +8 -0
  60. data/lib/cli/commands/generate/templates/value_object/lib/domain/%module_name%/%name%.rb.tt +24 -0
  61. data/lib/cli/commands/package.rb +16 -0
  62. data/lib/cli/commands/test.rb +41 -0
  63. data/lib/console/commands.rb +9 -0
  64. data/lib/console/console.rb +24 -0
  65. data/lib/domain_builder/attribute.rb +33 -0
  66. data/lib/domain_builder/domain.rb +17 -0
  67. data/lib/domain_builder/domain_builder.rb +35 -0
  68. data/lib/domain_builder/domain_module.rb +26 -0
  69. data/lib/domain_builder/domain_object.rb +37 -0
  70. data/lib/domain_builder/head.rb +6 -0
  71. data/lib/domain_builder/reference.rb +17 -0
  72. data/lib/domain_builder/value.rb +6 -0
  73. data/lib/hecks.rb +7 -0
  74. metadata +229 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dee163de927cbfaec6d4e4c5019cad4cb25e4c9f
4
+ data.tar.gz: aa357a7fa670cd173039f58a6ad30dd59c42235a
5
+ SHA512:
6
+ metadata.gz: 73424faad274f2bfbc2c2d52b181c94f3ba90a50e721c4b9ef7d31b450e0688a8aed055e314d92169404bbd72e54c86cef93ed6642c740f8576659a54fc931be
7
+ data.tar.gz: 303c18af2a8731005d6ae715cfc2cd5a759d6eb8830511f382c4f85592fcea9d99b3de3191f4e0f67c85dbbd55f9530cf228698b0ed84afb49e89b5ca9c3ddc1
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/hecks'
5
+
6
+ Hecks::CLI.start(ARGV)
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/console/console'
4
+ require Hecks::Console.full_path
5
+
6
+ puts "Hecks Loaded!"
7
+ puts "Using the " + Hecks::Console.domain_name + " domain"
8
+
9
+ IRB::ExtendCommandBundle.include(Hecks::Console::Commands)
10
+ IRB.start
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'memory_database/memory_database'
3
+ require_relative 'resource_server/resource_server'
4
+ require_relative 'events/events'
5
+ require_relative 'logger/logger'
6
+ require_relative 'validator/validator'
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ module Adapters
4
+ class Events
5
+ def initialize(listeners: [])
6
+ @listeners = listeners
7
+ end
8
+
9
+ def send(module_name:, command:)
10
+ @command = command
11
+ @module_name = module_name
12
+ listeners.each do |listener|
13
+ next unless listener.respond_to?(event_name)
14
+ listener.public_send(event_name, command)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :listeners, :command, :module_name
21
+
22
+ def event_name
23
+ "#{module_name}_#{command.name}".to_sym
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ module Adapters
4
+ class Logger
5
+ def initialize(output: [])
6
+ @output = output
7
+ end
8
+
9
+ def method_missing(name, *args, &block)
10
+ @output << {name: name, command: args.first.to_h.to_s}.to_s
11
+ end
12
+
13
+ def respond_to?(name)
14
+ true
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ module Adapters
4
+ class MemoryDatabase
5
+ def initialize(domain:)
6
+ @repositories = domain.repositories
7
+ end
8
+
9
+ def [](module_name)
10
+ @repositories[module_name]
11
+ end
12
+
13
+ def delete_all
14
+ @repositories.values.each(&:delete_all)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'methods/create'
3
+ require_relative 'methods/read'
4
+ require_relative 'methods/update'
5
+ require_relative 'methods/delete'
6
+
7
+ module Hecks
8
+ module Adapters
9
+ class ResourceServer
10
+ class Methods
11
+ attr_reader :create, :read, :update, :delete
12
+
13
+ def initialize(application_adapter:)
14
+ @create = Create.new(application_adapter: application_adapter)
15
+ @read = Read.new(application_adapter: application_adapter)
16
+ @update = Update.new(application_adapter: application_adapter)
17
+ @delete = Delete.new(application_adapter: application_adapter)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ module Adapters
4
+ class ResourceServer < Sinatra::Base
5
+ class Methods
6
+ class Create
7
+ attr_reader :result
8
+
9
+ def initialize(application_adapter:)
10
+ @application_adapter = application_adapter
11
+ end
12
+
13
+ def call(body:, module_name:)
14
+ @body = body.read
15
+ @module_name = module_name.to_sym
16
+ run_command
17
+ build_json
18
+ self
19
+ end
20
+
21
+ def status
22
+ return 500 if command_result.errors.count.positive?
23
+ 200
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :application_adapter, :body, :module_name, :command_result
29
+
30
+ def build_json
31
+ @result = JSON.generate(command_result.to_h)
32
+ end
33
+
34
+ def run_command
35
+ @command_result = application_adapter.call(
36
+ module_name: module_name,
37
+ command_name: :create,
38
+ args: params
39
+ )
40
+ end
41
+
42
+ def params
43
+ JSON.parse(body, symbolize_names: true)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ module Adapters
4
+ class ResourceServer < Sinatra::Base
5
+ class Methods
6
+ class Delete
7
+ attr_reader :result
8
+
9
+ def initialize(application_adapter:)
10
+ @application_adapter = application_adapter
11
+ end
12
+
13
+ def call(id:, module_name:)
14
+ @id = id.to_i
15
+ @module_name = module_name.to_sym
16
+ run_command
17
+ convert_to_json
18
+ self
19
+ end
20
+
21
+ def status
22
+ return 500 if command_result.errors.count.positive?
23
+ 200
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :application_adapter, :module_name, :id, :command_result
29
+
30
+ def convert_to_json
31
+ @result = JSON.generate(command_result.to_h)
32
+ end
33
+
34
+ def run_command
35
+ @command_result = application_adapter.call(
36
+ module_name: module_name,
37
+ command_name: :delete,
38
+ args: { id: id }
39
+ )
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ module Adapters
4
+ class ResourceServer < Sinatra::Base
5
+ class Methods
6
+ class Read
7
+ attr_reader :result, :status
8
+ def initialize(application_adapter:)
9
+ @application_adapter = application_adapter
10
+ end
11
+
12
+ def call(id:, module_name:)
13
+ @id = id.to_i
14
+ @module_name = module_name.to_sym
15
+ run_query
16
+ convert_to_json
17
+ self
18
+ end
19
+
20
+ def status
21
+ return 404 if command_result.nil?
22
+ 200
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :application_adapter, :id, :module_name, :command_result
28
+
29
+ def convert_to_json
30
+ @result = command_result.to_json
31
+ end
32
+
33
+ def run_query
34
+ @command_result = application_adapter.query(
35
+ query_name: :find_by_id,
36
+ module_name: module_name,
37
+ args: { id: id }
38
+ )
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ module Adapters
4
+ class ResourceServer < Sinatra::Base
5
+ class Methods
6
+ class Update
7
+ attr_reader :result
8
+
9
+ def initialize(application_adapter:)
10
+ @application_adapter = application_adapter
11
+ end
12
+
13
+ def call(id:, body:, module_name:)
14
+ @id = id.to_i
15
+ @body = body.read
16
+ @module_name = module_name.to_sym
17
+ run_command
18
+ convert_to_json
19
+ self
20
+ end
21
+
22
+ def status
23
+ return 500 if command_result.errors.count.positive?
24
+ 200
25
+ end
26
+
27
+ private
28
+
29
+ attr_accessor :application_adapter, :id, :body, :module_name, :command_result
30
+
31
+ def convert_to_json
32
+ @result = JSON.generate(command_result.to_h)
33
+ end
34
+
35
+ def run_command
36
+ @command_result = application_adapter.call(
37
+ module_name: module_name,
38
+ command_name: :update,
39
+ args: params
40
+ )
41
+ end
42
+
43
+ def params
44
+ JSON.parse(body, symbolize_names: true).merge(id: id)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+ require 'sinatra'
3
+ require 'json'
4
+ require_relative 'methods'
5
+
6
+ module Hecks
7
+ module Adapters
8
+ class ResourceServer < Sinatra::Base
9
+ configure do
10
+ set :raise_errors, true
11
+ set :show_exceptions, false
12
+ end
13
+
14
+ def initialize(app: nil, application_adapter:)
15
+ super(app)
16
+ @methods = Methods.new(application_adapter: application_adapter)
17
+ end
18
+
19
+ get '/:module_name/:id' do |module_name, id|
20
+ command = methods.read.call(id: id, module_name: module_name)
21
+ body command.result
22
+ status command.status
23
+ end
24
+
25
+ post '/:module_name' do |module_name|
26
+ command = methods.create.call(body: request.body, module_name: module_name)
27
+ status command.status
28
+ body command.result
29
+ end
30
+
31
+ put '/:module_name/:id' do |module_name, id|
32
+ command = methods.update.call(
33
+ id: id,
34
+ body: request.body,
35
+ module_name: module_name
36
+ )
37
+ status command.status
38
+ body command.result
39
+ end
40
+
41
+ delete '/:module_name/:id' do |module_name, id|
42
+ command = methods.delete.call(id: id, module_name: module_name)
43
+ status command.status
44
+ body command.result
45
+ end
46
+
47
+ private
48
+
49
+ attr_reader :methods
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,33 @@
1
+ module Hecks
2
+ module Adapters
3
+ class Validator
4
+ attr_reader :errors
5
+
6
+ def initialize(command:)
7
+ @args = command.args
8
+ @head_spec = command.domain_module.head
9
+ @errors = {}
10
+ end
11
+
12
+ def call
13
+ validate
14
+ return self
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :args, :head_spec
20
+
21
+ def validate
22
+ (missing_attributes).each do |missing_attribute|
23
+ errors[missing_attribute] = []
24
+ errors[missing_attribute] << "missing"
25
+ end
26
+ end
27
+
28
+ def missing_attributes
29
+ head_spec.attribute_hash.keys - args.keys
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'commands/commands'
3
+ require_relative 'queries/queries'
4
+
5
+ module Hecks
6
+ module Adapters
7
+ class Application
8
+ attr_reader :database, :domain_spec, :events_port
9
+ def initialize(database: nil, listeners: [], domain:)
10
+ load(domain.spec_path)
11
+ @domain = domain
12
+ @database = database.new(domain: @domain) if @database
13
+ @events_port = Adapters::Events.new(listeners: listeners)
14
+ @domain_spec = Hecks.specification
15
+ end
16
+
17
+ def call(command_name:, module_name:, args: {})
18
+ Runner.new(
19
+ command_name: command_name,
20
+ module_name: module_name,
21
+ args: args,
22
+ application: self
23
+ ).call
24
+ end
25
+
26
+ def [](module_name)
27
+ CRUDHandler.new(module_name: module_name, application: self)
28
+ end
29
+
30
+ def query(query_name:, module_name:, args: {})
31
+ QueryRunner.new(
32
+ module_name: module_name,
33
+ query_name: query_name,
34
+ args: args,
35
+ application: self
36
+ ).call
37
+ end
38
+
39
+ def database
40
+ return MemoryDatabase.new(domain: @domain) unless @database
41
+ @database
42
+ end
43
+ end
44
+ end
45
+ end