hecks-application 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: ae65b136d995774c776024097c136488ded32b4f
4
+ data.tar.gz: d0ee4938951a5edd4a01daec832c1c5d69966023
5
+ SHA512:
6
+ metadata.gz: fc833f79fa960dbf3812b3b1a98d682f135083d3cb39a1f3349a5fcd5789ec43752f983c9cd7120b9e4cde939cebf25de4ec59076a09dadd22f84bb38788534c
7
+ data.tar.gz: adb854836b3a107ff9a1673a3aea078cb58ab3d7daacbaf633ac5a577d42328b6adddc0c9a0eb42733ac640a5ba12dd7a0f8c97fd51c1d320f4b07444ef98d81
@@ -0,0 +1,5 @@
1
+ require_relative 'update'
2
+ require_relative 'create'
3
+ require_relative 'delete'
4
+ require_relative 'crud_handler'
5
+ require_relative 'runner'
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ class Application
4
+ module Commands
5
+ class Create
6
+ attr_accessor :args, :id, :errors, :repository, :domain_module
7
+
8
+ def initialize(args:, repository:, domain_module: )
9
+ @repository = repository
10
+ @args = args
11
+ @errors = {}
12
+ @validator = Hecks::Adapters::Validator
13
+ @domain_module = domain_module
14
+ end
15
+
16
+ def call
17
+ validate
18
+ create
19
+ self
20
+ end
21
+
22
+ def to_h
23
+ { errors: errors, id: repository_result, args: args }
24
+ end
25
+
26
+ def name
27
+ self.class.to_s.split('::').last.underscore
28
+ end
29
+
30
+ def result
31
+ { id: id, success: !id.nil?, errors: errors, args: args }
32
+ end
33
+
34
+ private
35
+
36
+ attr_reader :repository_result
37
+
38
+ def create
39
+ return if @errors.count.positive?
40
+ @id = @repository_result = repository.create(args).id
41
+ end
42
+
43
+ def validate
44
+ return if @validator.nil?
45
+ @errors = @validator.new(command: self).call.errors
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,46 @@
1
+ module Hecks
2
+ class Application
3
+ module Commands
4
+ class CRUDHandler
5
+ attr_reader :module_name, :application
6
+
7
+ def initialize(module_name:, application:)
8
+ @module_name = module_name
9
+ @application = application
10
+ end
11
+
12
+ def create(attributes)
13
+ application.call(
14
+ module_name: module_name,
15
+ command_name: :create,
16
+ args: attributes
17
+ )
18
+ end
19
+
20
+ def read(id)
21
+ application.query(
22
+ module_name: module_name,
23
+ query_name: :find_by_id,
24
+ args: { id: id }
25
+ )
26
+ end
27
+
28
+ def update(id, attributes)
29
+ application.call(
30
+ module_name: module_name,
31
+ command_name: :update,
32
+ args: attributes.merge(id: id)
33
+ )
34
+ end
35
+
36
+ def delete(id)
37
+ application.call(
38
+ module_name: module_name,
39
+ command_name: :delete,
40
+ args: { id: id }
41
+ )
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ class Application
4
+ module Commands
5
+ class Delete
6
+ attr_accessor :args, :errors, :repository
7
+
8
+ def initialize(args: nil, repository:, domain_module:)
9
+ @args = args || chained_command.args
10
+ @repository = repository
11
+ @errors = { base: [] }
12
+ end
13
+
14
+ def call
15
+ delete
16
+ self
17
+ end
18
+
19
+ def name
20
+ self.class.to_s.split('::').last.underscore
21
+ end
22
+
23
+ def to_h
24
+ { errors: errors, args: args }
25
+ end
26
+
27
+ private
28
+
29
+ attr_accessor :command_result, :repository
30
+
31
+ def delete
32
+ @result = repository.delete(args[:id])
33
+ @errors[:base] << "cound not find #{args[:id]}" unless @result
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,46 @@
1
+ module Hecks
2
+ class Application
3
+ class Runner
4
+ attr_reader :module_name, :command
5
+
6
+ def initialize(command_name:, module_name:, args:, application:)
7
+ @command_name = command_name
8
+ @module_name = module_name
9
+ @args = args
10
+ @application = application
11
+ @domain_spec = application.domain_spec
12
+ end
13
+
14
+ def call()
15
+ fetch_command
16
+ run_command
17
+ broadcast
18
+ command
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :command_name, :args, :application, :domain_spec
24
+
25
+ def broadcast
26
+ application.events_port.send(command: command, module_name: module_name)
27
+ end
28
+
29
+ def fetch_command
30
+ @command = Commands.const_get(command_name.to_s.camelcase).new(
31
+ repository: application.database[module_name],
32
+ args: args,
33
+ domain_module: fetch_module
34
+ )
35
+ end
36
+
37
+ def fetch_module
38
+ domain_spec.domain_modules[module_name.to_s.camelize.to_sym]
39
+ end
40
+
41
+ def run_command
42
+ @command = command.call
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ class Application
4
+ module Commands
5
+ class Update
6
+ attr_accessor :args, :errors, :id, :repository
7
+
8
+ def initialize(args: nil, repository: Repository, domain_module:)
9
+ @repository = repository
10
+ @args = args
11
+ @errors = []
12
+ @id = @args.delete(:id)
13
+ end
14
+
15
+ def name
16
+ self.class.to_s.split('::').last.underscore
17
+ end
18
+
19
+ def call
20
+ update
21
+ self
22
+ end
23
+
24
+ def to_h
25
+ { id: id, args: args }
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :repository_result
31
+
32
+ def update
33
+ return if @errors.count.positive?
34
+ @repository_result = repository.update(id, args)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,43 @@
1
+ require 'hecks'# frozen_string_literal: true
2
+ require_relative 'commands/commands'
3
+ require_relative 'queries/queries'
4
+
5
+ module Hecks
6
+ class Application
7
+ attr_reader :database, :domain_spec, :events_port
8
+ def initialize(database: nil, listeners: [], domain:)
9
+ load(domain.spec_path)
10
+ @domain = domain
11
+ @database = database
12
+ @events_port = Adapters::Events.new(listeners: listeners)
13
+ @domain_spec = DOMAIN
14
+ end
15
+
16
+ def call(command_name:, module_name:, args: {})
17
+ Runner.new(
18
+ command_name: command_name,
19
+ module_name: module_name,
20
+ args: args,
21
+ application: self
22
+ ).call
23
+ end
24
+
25
+ def [](module_name)
26
+ Commands::CRUDHandler.new(module_name: module_name, application: self)
27
+ end
28
+
29
+ def query(query_name:, module_name:, args: {})
30
+ QueryRunner.new(
31
+ module_name: module_name,
32
+ query_name: query_name,
33
+ args: args,
34
+ application: self
35
+ ).call
36
+ end
37
+
38
+ def database
39
+ return @database.new(domain: @domain) if @database
40
+ return Hecks::Adapters::MemoryDatabase.new(domain: @domain)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module Hecks
3
+ class Application
4
+ module Queries
5
+ class FindById
6
+ def initialize(repository:)
7
+ @repository = repository
8
+ end
9
+
10
+ def call(params)
11
+ return unless params.keys == [:id]
12
+ @repository.read(params[:id])
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'find_by_id'
2
+ require_relative 'query_runner'
@@ -0,0 +1,26 @@
1
+ module Hecks
2
+ class Application
3
+ class QueryRunner
4
+ def initialize(query_name:, application:, module_name:, args:)
5
+ @query_name = query_name
6
+ @application = application
7
+ @module_name = module_name
8
+ @args = args
9
+ end
10
+
11
+ def call()
12
+ fetch.new(repository: repository).call(@args)
13
+ end
14
+
15
+ private
16
+
17
+ def fetch
18
+ Queries.const_get(@query_name.to_s.camelcase)
19
+ end
20
+
21
+ def repository
22
+ @application.database[@module_name]
23
+ end
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hecks-application
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/commands/commands.rb
20
+ - lib/commands/create.rb
21
+ - lib/commands/crud_handler.rb
22
+ - lib/commands/delete.rb
23
+ - lib/commands/runner.rb
24
+ - lib/commands/update.rb
25
+ - lib/hecks-application.rb
26
+ - lib/queries/find_by_id.rb
27
+ - lib/queries/queries.rb
28
+ - lib/queries/query_runner.rb
29
+ homepage: https://github.com/chrisyoung/hecks-application
30
+ licenses:
31
+ - MIT
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.6.10
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: DDD and Hexagonal Code Generators
53
+ test_files: []