hecks-adapters 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 32c2218095e25d7e73fac778ada0c9d476439b62
4
+ data.tar.gz: 273613aabd246fe519258820b2fcbe0a0e9bec5e
5
+ SHA512:
6
+ metadata.gz: 065aa61643e57503b06c3261dbaf6aad60f62966fda79ce782ee3a5c312d4c7d00fa95b2c4f8703c9a327a4becb95c4c835cf8adcfeb7483c9b0cbc5cc9ba540
7
+ data.tar.gz: c761460cbb7df5020164f6640e4f37d6813bdef1fd34c5fbea5a5b1c6f664b253ec3590a99716676a08777c33ee52ac616e183281c64d34bc9611d74088dfc6d
@@ -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,7 @@
1
+ # frozen_string_literal: true
2
+ require 'hecks-application'
3
+
4
+ require_relative 'memory_database/memory_database'
5
+ require_relative 'events/events'
6
+ require_relative 'logger/logger'
7
+ require_relative 'validator/validator'
@@ -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,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
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hecks-adapters
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Young
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Make the Domain the center of your programming world
14
+ email: chris@example.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/events/events.rb
20
+ - lib/hecks-adapters.rb
21
+ - lib/logger/logger.rb
22
+ - lib/memory_database/memory_database.rb
23
+ - lib/validator/validator.rb
24
+ homepage: https://github.com/chrisyoung/heckson
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.6.10
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: DDD and Hexagonal Code Generators
48
+ test_files: []