hecks 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/hecks +6 -0
- data/bin/hecks_console +10 -0
- data/lib/adapters/adapters.rb +6 -0
- data/lib/adapters/events/events.rb +27 -0
- data/lib/adapters/logger/logger.rb +18 -0
- data/lib/adapters/memory_database/memory_database.rb +18 -0
- data/lib/adapters/resource_server/methods.rb +22 -0
- data/lib/adapters/resource_server/methods/create.rb +49 -0
- data/lib/adapters/resource_server/methods/delete.rb +45 -0
- data/lib/adapters/resource_server/methods/read.rb +44 -0
- data/lib/adapters/resource_server/methods/update.rb +50 -0
- data/lib/adapters/resource_server/resource_server.rb +52 -0
- data/lib/adapters/validator/validator.rb +33 -0
- data/lib/application/application.rb +45 -0
- data/lib/application/commands/commands.rb +5 -0
- data/lib/application/commands/create.rb +52 -0
- data/lib/application/commands/crud_handler.rb +40 -0
- data/lib/application/commands/delete.rb +40 -0
- data/lib/application/commands/runner.rb +48 -0
- data/lib/application/commands/update.rb +41 -0
- data/lib/application/queries/find_by_id.rb +19 -0
- data/lib/application/queries/queries.rb +2 -0
- data/lib/application/queries/query_runner.rb +28 -0
- data/lib/cli/cli.rb +24 -0
- data/lib/cli/command_runner.rb +25 -0
- data/lib/cli/commands.rb +5 -0
- data/lib/cli/commands/build.rb +10 -0
- data/lib/cli/commands/console.rb +8 -0
- data/lib/cli/commands/generate.rb +26 -0
- data/lib/cli/commands/generate/builder.rb +60 -0
- data/lib/cli/commands/generate/builder/aggregate_command_line_builder.rb +18 -0
- data/lib/cli/commands/generate/builder/reference_command_line_builder.rb +19 -0
- data/lib/cli/commands/generate/builder/value_object_command_line_builder.rb +19 -0
- data/lib/cli/commands/generate/generate_aws_package.rb +17 -0
- data/lib/cli/commands/generate/generate_binary_package.rb +92 -0
- data/lib/cli/commands/generate/generate_domain_object.rb +71 -0
- data/lib/cli/commands/generate/generate_domain_object/assignment_template.rb +36 -0
- data/lib/cli/commands/generate/generate_domain_object/option_formatter.rb +30 -0
- data/lib/cli/commands/generate/generate_lambda_package.rb +20 -0
- data/lib/cli/commands/generate/generate_resource_server.rb +17 -0
- data/lib/cli/commands/generate/new.rb +47 -0
- data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/%head_name%.rb.tt +16 -0
- data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/%name%.rb.tt +9 -0
- data/lib/cli/commands/generate/templates/aggregate/lib/domain/%name%/repository.rb.tt +40 -0
- data/lib/cli/commands/generate/templates/binary_package/build/linux-x86_64/lib/app/hello.rb +1 -0
- data/lib/cli/commands/generate/templates/binary_package/build/resources/%domain_name%.rb.tt +17 -0
- data/lib/cli/commands/generate/templates/binary_package/build/resources/Dockerfile.tt +8 -0
- data/lib/cli/commands/generate/templates/binary_package/build/resources/Gemfile.tt +4 -0
- data/lib/cli/commands/generate/templates/binary_package/build/resources/bundle/config +3 -0
- data/lib/cli/commands/generate/templates/binary_package/build/resources/wrapper.tt +13 -0
- data/lib/cli/commands/generate/templates/domain/%name%.gemspec.tt +12 -0
- data/lib/cli/commands/generate/templates/domain/Version +1 -0
- data/lib/cli/commands/generate/templates/domain/lib/%name%.rb.tt +21 -0
- data/lib/cli/commands/generate/templates/domain/spec/spec_helper.rb.tt +4 -0
- data/lib/cli/commands/generate/templates/lambda_package/handler.js.tt +12 -0
- data/lib/cli/commands/generate/templates/lambda_package/serverless.yml.tt +100 -0
- data/lib/cli/commands/generate/templates/reference/lib/domain/%module_name%/%file_name%.rb.tt +25 -0
- data/lib/cli/commands/generate/templates/resource_server/config.ru.tt +8 -0
- data/lib/cli/commands/generate/templates/value_object/lib/domain/%module_name%/%name%.rb.tt +24 -0
- data/lib/cli/commands/package.rb +16 -0
- data/lib/cli/commands/test.rb +41 -0
- data/lib/console/commands.rb +9 -0
- data/lib/console/console.rb +24 -0
- data/lib/domain_builder/attribute.rb +33 -0
- data/lib/domain_builder/domain.rb +17 -0
- data/lib/domain_builder/domain_builder.rb +35 -0
- data/lib/domain_builder/domain_module.rb +26 -0
- data/lib/domain_builder/domain_object.rb +37 -0
- data/lib/domain_builder/head.rb +6 -0
- data/lib/domain_builder/reference.rb +17 -0
- data/lib/domain_builder/value.rb +6 -0
- data/lib/hecks.rb +7 -0
- metadata +229 -0
checksums.yaml
ADDED
@@ -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
|
data/bin/hecks
ADDED
data/bin/hecks_console
ADDED
@@ -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,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
|