hecks-app 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 69aad83b88d1d41d0021b256f2120204eab01a1f454dcf30e2d859675d7cf53d
4
+ data.tar.gz: c57fad2eaf78c600ad0289cb01fa98a78fee28d6d0d058dd6b31fa1d8c7d7702
5
+ SHA512:
6
+ metadata.gz: 0baebba721a2ea2cb86f9e5b02c1234e94bfe71eafa27fc1f2f7302c038b96b4b6a5d51433db2d3deab184d85f0d783e319bcf9421a3124f1979e4221925a659
7
+ data.tar.gz: 9708e049dcb5f449afab39e4cc4dafdaf5f10ae4b6adbce7d328962b78ffe96d4c9cdad56ec8d5853da03daf4547e8e3053fb13f734b0aae09bc414615e7edd2
@@ -0,0 +1,4 @@
1
+ module HecksApp
2
+ module Adapters
3
+ end
4
+ end
@@ -0,0 +1,25 @@
1
+ module HecksApp
2
+ class ApplicationPort
3
+ class CommandRunner
4
+ class Event
5
+ attr_reader :errors, :domain_event
6
+ def initialize(errors: [], domain_event: nil)
7
+ @errors = errors
8
+ @domain_event = domain_event
9
+ end
10
+
11
+ def on_success
12
+ return unless @errors.empty?
13
+
14
+ yield self
15
+ end
16
+
17
+ def on_fail
18
+ return if @errors.empty?
19
+
20
+ yield self
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'command_runner/event'
2
+ module HecksApp
3
+ class ApplicationPort
4
+ class CommandRunner
5
+ attr_reader :runnable
6
+ def initialize(runnable)
7
+ @runnable =
8
+ case runnable
9
+ when Symbol
10
+ ApplicationPort.domain::Domain
11
+ .const_get(runnable)::Root
12
+ when Hash
13
+ ApplicationPort.domain::Domain
14
+ .const_get(runnable.keys.first)
15
+ .const_get(runnable.values.first)
16
+ else
17
+ runnable
18
+ end
19
+ end
20
+
21
+ def method_missing(name, *args, &block)
22
+ run(name, args, &block)
23
+ end
24
+
25
+ def run(name, args, &block)
26
+ @runnable.send(name, *args) do |domain_event|
27
+ yield(Event.new(domain_event: domain_event)) if block
28
+ end
29
+ rescue ApplicationPort.domain::InvariantViolationError => e
30
+ yield(Event.new(errors: [e.message])) && return if block
31
+
32
+ raise e
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,6 @@
1
+ module HecksApp
2
+ gem_dir = Gem::Specification.find_by_name(ApplicationPort.domain.to_s.underscore).gem_dir
3
+ DOMAIN_SCHEMA =
4
+ instance_eval(File.open("#{gem_dir}/Domainfile").read)
5
+ .domain.freeze
6
+ end
@@ -0,0 +1,32 @@
1
+ module HecksApp
2
+ class ApplicationPort
3
+ class Event
4
+ include Singleton
5
+
6
+ def initialize
7
+ @subscriptions = {}
8
+ end
9
+
10
+ def self.subscribe(subscriber, event)
11
+ instance.subscribe(subscriber, event)
12
+ end
13
+
14
+ def self.emit(event)
15
+ instance.emit(event)
16
+ end
17
+
18
+ def subscribe(subscriber, event)
19
+ @subscriptions[event] ||= []
20
+ @subscriptions[event] << subscriber
21
+ end
22
+
23
+ def emit(event)
24
+ return unless @subscriptions[event]
25
+
26
+ @subscriptions[event].each do |subscriber|
27
+ subscriber.notify(event)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
data/lib/hecks-app.rb ADDED
@@ -0,0 +1,67 @@
1
+ require 'active_record'
2
+ require 'hecks/domain'
3
+
4
+ require_relative 'application_port/command_runner'
5
+ require_relative 'application_port/adapters'
6
+ require_relative 'application_port/event'
7
+
8
+ module HecksApp
9
+ class ApplicationPort
10
+ include Singleton
11
+
12
+ attr_accessor :adapters, :event
13
+
14
+ def initialize
15
+ @adapters = []
16
+ @domain = nil
17
+ @event = Event
18
+ end
19
+
20
+ def self.in_repository(aggregate)
21
+ aggregate::Root::Repository.class_eval do
22
+ yield
23
+ end
24
+ end
25
+
26
+ def self.domain_object_from_repository(repository)
27
+ const_get(repository.to_s.gsub('::Repository', ''))
28
+ end
29
+
30
+ def self.find_aggregate(name)
31
+ domain::Domain.const_get(name)
32
+ end
33
+
34
+ def self.config(&block)
35
+ instance.instance_eval(&block)
36
+ instance.event.emit(:AppConfigured)
37
+ end
38
+
39
+ def self.subscribe(subscriber, event)
40
+ instance.event.subscribe(subscriber, event)
41
+ end
42
+
43
+ def self.domain
44
+ instance.domain_get
45
+ end
46
+
47
+ def domain_get
48
+ @domain
49
+ end
50
+
51
+ def self.[](value)
52
+ CommandRunner.new(value)
53
+ end
54
+
55
+ def domain(domain)
56
+ @domain = domain
57
+ require_relative 'application_port/domain_schema'
58
+ end
59
+
60
+ def adapter(name)
61
+ Adapters.const_get(name).new.tap do |adapter|
62
+ adapter.load
63
+ @adapters << adapter
64
+ end
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hecks-app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hecks App Developer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hecks-domain
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
41
+ description: Uses a hexagonal framework to plugin adapters to a domain
42
+ email: support@the_good_guys.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/application_port/adapters.rb
48
+ - lib/application_port/command_runner.rb
49
+ - lib/application_port/command_runner/event.rb
50
+ - lib/application_port/domain_schema.rb
51
+ - lib/application_port/event.rb
52
+ - lib/hecks-app.rb
53
+ homepage: https://www.example.com
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.0.3
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Build an application with a Hecks Domain
76
+ test_files: []