hecks-domain 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/hecks/domain/commands/generate.rb +98 -0
- data/lib/hecks/domain/commands.rb +1 -0
- data/lib/hecks/domain/generators/domain.rb +21 -0
- data/lib/hecks/domain/generators/domain_files.rb +28 -0
- data/lib/hecks/domain/generators/entity.rb +30 -0
- data/lib/hecks/domain/generators/operation.rb +32 -0
- data/lib/hecks/domain/generators/root.rb +30 -0
- data/lib/hecks/domain/generators/spec.rb +30 -0
- data/lib/hecks/domain/generators/value_object.rb +30 -0
- data/lib/hecks/domain/generators.rb +7 -0
- data/lib/hecks/domain/parser/aggregate.rb +44 -0
- data/lib/hecks/domain/parser/domain_object.rb +123 -0
- data/lib/hecks/domain/parser/entity_field.rb +55 -0
- data/lib/hecks/domain/parser/fields.rb +16 -0
- data/lib/hecks/domain/parser/list_field.rb +13 -0
- data/lib/hecks/domain/parser/operation.rb +15 -0
- data/lib/hecks/domain/parser/reference_field.rb +12 -0
- data/lib/hecks/domain/parser/spec_helper.rb +0 -0
- data/lib/hecks/domain/parser/value_field.rb +48 -0
- data/lib/hecks/domain/parser.rb +95 -0
- data/lib/hecks/domain/support/string.rb +9 -0
- data/lib/hecks/domain/support.rb +1 -0
- data/lib/hecks/domain/templates/%domain_name%.gemspec.tt +12 -0
- data/lib/hecks/domain/templates/%folder_name%/Domainfile.tt +9 -0
- data/lib/hecks/domain/templates/%folder_name%/events/command_will_run.rb.tt +11 -0
- data/lib/hecks/domain/templates/%folder_name%/spec/spec_helper.rb.tt +1 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/commands.rb.tt +11 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/events.rb.tt +11 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/factories/build.rb.tt +37 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/factories.rb.tt +11 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/invariants.rb.tt +11 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/queries.rb.tt +11 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/repository.rb.tt +68 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%/subscribers.rb.tt +11 -0
- data/lib/hecks/domain/templates/entity/%aggregate_name%/%domain_object_name%.rb.tt +34 -0
- data/lib/hecks/domain/templates/lib/%domain_name%.rb.tt +9 -0
- data/lib/hecks/domain/templates/lib/support/commands/command_loader.rb +18 -0
- data/lib/hecks/domain/templates/lib/support/commands/command_runner.rb +17 -0
- data/lib/hecks/domain/templates/lib/support/commands.rb +2 -0
- data/lib/hecks/domain/templates/lib/support/domain_object.rb +25 -0
- data/lib/hecks/domain/templates/lib/support/events/domain_event.rb +14 -0
- data/lib/hecks/domain/templates/lib/support/events/domain_event_publisher.rb +34 -0
- data/lib/hecks/domain/templates/lib/support/events.rb +14 -0
- data/lib/hecks/domain/templates/lib/support/factories/factory_loader.rb +21 -0
- data/lib/hecks/domain/templates/lib/support/factories.rb +1 -0
- data/lib/hecks/domain/templates/lib/support/invariants/invariant_loader.rb +24 -0
- data/lib/hecks/domain/templates/lib/support/queries/query_loader.rb +18 -0
- data/lib/hecks/domain/templates/lib/support/queries.rb +1 -0
- data/lib/hecks/domain/templates/lib/support/repositories/repository_loader.rb +32 -0
- data/lib/hecks/domain/templates/lib/support/root.rb +27 -0
- data/lib/hecks/domain/templates/lib/support/support/string.rb +9 -0
- data/lib/hecks/domain/templates/lib/support.rb +11 -0
- data/lib/hecks/domain/templates/operation/%aggregate_name%/%domain_object_name%/commands/%operation_name%.rb.tt +21 -0
- data/lib/hecks/domain/templates/root/%aggregate_name%/root.rb.tt +14 -0
- data/lib/hecks/domain/templates/spec/%aggregate_name%/%root_name%_spec.rb.tt +12 -0
- data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%/factories/build.rb.tt +37 -0
- data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%/factories.rb.tt +11 -0
- data/lib/hecks/domain/templates/value_object/%aggregate_name%/%domain_object_name%.rb.tt +34 -0
- data/lib/hecks/domain/top_level_methods.rb +3 -0
- data/lib/hecks/domain.rb +22 -0
- metadata +101 -59
- data/lib/adapters/adapters.rb +0 -2
- data/lib/adapters/resource_server/cli/cli.rb +0 -1
- data/lib/adapters/resource_server/cli/generate_resource_server.rb +0 -25
- data/lib/adapters/resource_server/cli/templates/resource_server/config.ru.tt +0 -8
- data/lib/adapters/resource_server/resource_server.rb +0 -1
- data/lib/adapters/sql_database/cli/cli.rb +0 -3
- data/lib/adapters/sql_database/cli/generate_domain_migrations.rb +0 -33
- data/lib/adapters/sql_database/cli/generate_sql_database.rb +0 -35
- data/lib/adapters/sql_database/cli/migration_builder.rb +0 -51
- data/lib/adapters/sql_database/cli/templates/migration.rb.tt +0 -14
- data/lib/adapters/sql_database/cli/templates/repository.rb.tt +0 -24
- data/lib/adapters/sql_database/cli/templates/sql_database/Gemfile +0 -10
- data/lib/adapters/sql_database/cli/templates/sql_database/Rakefile +0 -15
- data/lib/adapters/sql_database/commands/read/fetch_references.rb +0 -58
- data/lib/adapters/sql_database/commands/update/delete_references.rb +0 -45
- data/lib/adapters/sql_database/commands/update/link_to_references.rb +0 -45
- data/lib/adapters/sql_database/sql_database.rb +0 -1
- data/lib/cli/builder/aggregate_command_line_builder.rb +0 -22
- data/lib/cli/builder/builder.rb +0 -3
- data/lib/cli/builder/reference_command_line_builder.rb +0 -23
- data/lib/cli/builder/value_object_command_line_builder.rb +0 -23
- data/lib/cli/cli.rb +0 -8
- data/lib/cli/command_builder.rb +0 -59
- data/lib/cli/domain_object/assignment_template.rb +0 -43
- data/lib/cli/domain_object/option_formatter.rb +0 -36
- data/lib/cli/generate_domain_object.rb +0 -71
- data/lib/cli/new.rb +0 -50
- data/lib/cli/templates/aggregate/lib/domain/%name%/%head_name%.rb.tt +0 -16
- data/lib/cli/templates/aggregate/lib/domain/%name%/%name%.rb.tt +0 -9
- data/lib/cli/templates/aggregate/lib/domain/%name%/repository.rb.tt +0 -41
- data/lib/cli/templates/domain/%name%.gemspec.tt +0 -12
- data/lib/cli/templates/domain/Version +0 -1
- data/lib/cli/templates/domain/lib/%name%.rb.tt +0 -21
- data/lib/cli/templates/domain/spec/spec_helper.rb.tt +0 -4
- data/lib/cli/templates/reference/lib/domain/%module_name%/%file_name%.rb.tt +0 -25
- data/lib/cli/templates/value_object/lib/domain/%module_name%/%name%.rb.tt +0 -24
- data/lib/domain_builder/attribute.rb +0 -60
- data/lib/domain_builder/domain.rb +0 -19
- data/lib/domain_builder/domain_builder.rb +0 -37
- data/lib/domain_builder/domain_module.rb +0 -28
- data/lib/domain_builder/domain_object.rb +0 -43
- data/lib/domain_builder/head.rb +0 -8
- data/lib/domain_builder/reference.rb +0 -19
- data/lib/domain_builder/value.rb +0 -8
- data/lib/hecks-domain.rb +0 -7
@@ -1,45 +0,0 @@
|
|
1
|
-
module Hecks
|
2
|
-
module Domain
|
3
|
-
module Adapters
|
4
|
-
class SQLDatabase
|
5
|
-
module Commands
|
6
|
-
class Update
|
7
|
-
class DeleteReferences
|
8
|
-
attr_reader :attributes
|
9
|
-
|
10
|
-
def initialize(table:, attributes:, reference:)
|
11
|
-
@table = table
|
12
|
-
@attributes = attributes
|
13
|
-
@reference = reference
|
14
|
-
@where_clause = {}
|
15
|
-
@dataset = DB[JoinTable.new(@table, @reference).name.to_sym]
|
16
|
-
end
|
17
|
-
|
18
|
-
def call
|
19
|
-
build_where_clause
|
20
|
-
delete_references
|
21
|
-
remove_references_from_attributes
|
22
|
-
self
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def build_where_clause
|
28
|
-
DB[JoinTable.new(@table, @reference).name.to_sym]
|
29
|
-
end
|
30
|
-
|
31
|
-
def remove_references_from_attributes
|
32
|
-
@attributes.delete(@reference.name.to_sym)
|
33
|
-
end
|
34
|
-
|
35
|
-
def delete_references
|
36
|
-
return unless @reference.list?
|
37
|
-
@dataset.where(@where_clause).delete
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module Hecks
|
2
|
-
module Domain
|
3
|
-
module Adapters
|
4
|
-
class SQLDatabase
|
5
|
-
module Commands
|
6
|
-
class Update
|
7
|
-
class LinkToReferences
|
8
|
-
attr_reader :reference_ids
|
9
|
-
def initialize(reference:, table:, reference_ids:, attributes:)
|
10
|
-
@reference = reference
|
11
|
-
@reference_ids = reference_ids
|
12
|
-
@table = table
|
13
|
-
@attributes = attributes
|
14
|
-
@column = Column.factory(@reference)
|
15
|
-
@record = {}
|
16
|
-
end
|
17
|
-
|
18
|
-
def call
|
19
|
-
make_linking_records
|
20
|
-
make_foreign_keys
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def make_linking_records
|
27
|
-
return unless @reference.list?
|
28
|
-
@reference_ids[@reference.name.to_sym].each do |value|
|
29
|
-
@record[@column.to_foreign_key] = value
|
30
|
-
@record[@table.to_foreign_key] = @attributes[:id]
|
31
|
-
DB[JoinTable.new(@table, @reference).name.to_sym].insert(@record)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def make_foreign_keys
|
36
|
-
return if @reference.list?
|
37
|
-
@attributes[@column.to_foreign_key] = @reference_ids[@reference.name]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require_relative 'cli/cli'
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Hecks
|
2
|
-
module Domain
|
3
|
-
module CLI
|
4
|
-
class CommandBuilder
|
5
|
-
module AggregateCommandLineBuilder
|
6
|
-
def self.build(domain, runner)
|
7
|
-
domain.domain_modules.values.each do |domain_module|
|
8
|
-
runner.call(
|
9
|
-
[
|
10
|
-
'generate domain_object',
|
11
|
-
'-t', 'aggregate',
|
12
|
-
'-n', domain_module.name,
|
13
|
-
'--head_name', domain_module.head.name,
|
14
|
-
'-a', domain_module.head.attribute_string
|
15
|
-
])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/lib/cli/builder/builder.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Hecks
|
2
|
-
module Domain
|
3
|
-
module CLI
|
4
|
-
class CommandBuilder
|
5
|
-
module ReferenceCommandLineBuilder
|
6
|
-
def self.build(domain, runner)
|
7
|
-
domain.domain_modules.values.each do |domain_module|
|
8
|
-
domain_module.references.each do |reference|
|
9
|
-
runner.call([
|
10
|
-
'generate domain_object',
|
11
|
-
'-t', 'reference',
|
12
|
-
'-n', reference.name,
|
13
|
-
'-m', domain_module.name,
|
14
|
-
'-r', reference.referenced_entity
|
15
|
-
])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Hecks
|
2
|
-
module Domain
|
3
|
-
module CLI
|
4
|
-
class CommandBuilder
|
5
|
-
module ValueObjectCommandLineBuilder
|
6
|
-
def self.build(domain, runner)
|
7
|
-
domain.domain_modules.values.each do |domain_module|
|
8
|
-
(domain_module.objects - [domain_module.head]).each do |value_object|
|
9
|
-
runner.call([
|
10
|
-
'generate domain_object',
|
11
|
-
'-t', 'value_object',
|
12
|
-
'-n', value_object.name,
|
13
|
-
'-m', domain_module.name,
|
14
|
-
'-a', value_object.attribute_string
|
15
|
-
])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/cli/cli.rb
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
require_relative 'generate_domain_object'
|
4
|
-
require_relative 'new'
|
5
|
-
require_relative 'builder/builder'
|
6
|
-
require_relative 'command_builder'
|
7
|
-
require_relative "domain_object/assignment_template"
|
8
|
-
require_relative "domain_object/option_formatter"
|
data/lib/cli/command_builder.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Hecks
|
4
|
-
module Domain
|
5
|
-
module CLI
|
6
|
-
class CommandBuilder
|
7
|
-
def initialize(name:, dry_run: false)
|
8
|
-
@name = name
|
9
|
-
@domain = DOMAIN
|
10
|
-
@dry_run = dry_run
|
11
|
-
@runner = CommandRunner.new(domain, name, dry_run)
|
12
|
-
end
|
13
|
-
|
14
|
-
def call
|
15
|
-
delete_tmpfile
|
16
|
-
puts "\n"
|
17
|
-
generate :domain
|
18
|
-
generate :modules
|
19
|
-
generate :value_objects
|
20
|
-
generate :references
|
21
|
-
execute_tmpfile && return unless @dry_run
|
22
|
-
print_tmpfile
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
attr_reader :runner, :name, :domain
|
28
|
-
|
29
|
-
def print_tmpfile
|
30
|
-
puts File.read('tmp/hecks')
|
31
|
-
end
|
32
|
-
|
33
|
-
def delete_tmpfile
|
34
|
-
return unless Pathname('tmp/hecks').exist?
|
35
|
-
FileUtils.rm('tmp/hecks')
|
36
|
-
end
|
37
|
-
|
38
|
-
def execute_tmpfile
|
39
|
-
exec('bash -x tmp/hecks')
|
40
|
-
end
|
41
|
-
|
42
|
-
def generate(command)
|
43
|
-
case command
|
44
|
-
when :references
|
45
|
-
ReferenceCommandLineBuilder.build(domain, runner)
|
46
|
-
when :domain
|
47
|
-
runner.call(['new', '-n', name])
|
48
|
-
when :modules
|
49
|
-
AggregateCommandLineBuilder.build(domain, runner)
|
50
|
-
when :value_objects
|
51
|
-
ValueObjectCommandLineBuilder.build(domain, runner)
|
52
|
-
else
|
53
|
-
raise "unrecognized command: #{command}"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Hecks
|
2
|
-
module Domain
|
3
|
-
module CLI
|
4
|
-
class GenerateDomainObject
|
5
|
-
class AssignmentTemplate
|
6
|
-
def initialize(attributes)
|
7
|
-
@attributes = attributes
|
8
|
-
end
|
9
|
-
|
10
|
-
def render
|
11
|
-
attributes.map do |attribute|
|
12
|
-
@attribute = Hecks::Domain::DomainBuilder::Attribute.new(attribute)
|
13
|
-
do_assignment
|
14
|
-
end.join("\n")
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
attr_reader :attributes, :attribute
|
20
|
-
|
21
|
-
def do_assignment
|
22
|
-
return value_assignment if Hecks::Domain::DomainBuilder::Types.values.include?(@attribute.type)
|
23
|
-
return value_assignment if @attribute.type == 'Value'
|
24
|
-
return reference_factory_assignment if attribute.domain_module
|
25
|
-
return factory_assignment
|
26
|
-
end
|
27
|
-
|
28
|
-
def reference_factory_assignment
|
29
|
-
"@#{attribute.name} = #{attribute.type}Reference.factory(#{attribute.name})"
|
30
|
-
end
|
31
|
-
|
32
|
-
def factory_assignment
|
33
|
-
"@#{attribute.name} = #{attribute.type}.factory(#{attribute.name})"
|
34
|
-
end
|
35
|
-
|
36
|
-
def value_assignment
|
37
|
-
"@#{attribute.name} = #{attribute.name}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Hecks
|
2
|
-
module Domain
|
3
|
-
module CLI
|
4
|
-
class GenerateDomainObject
|
5
|
-
class OptionFormatter
|
6
|
-
def initialize(attributes)
|
7
|
-
@attributes = attributes.map do |attribute|
|
8
|
-
Hecks::Domain::DomainBuilder::Attribute.new(attribute)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def call(format, include_id: false)
|
13
|
-
case format
|
14
|
-
when 'keys_and_values'
|
15
|
-
attributes(include_id).map { |attribute| (attribute.name + ': ' + attribute.name) }.join(', ')
|
16
|
-
when 'attribute_string'
|
17
|
-
attributes(include_id).map { |attribute| ':' + attribute.name }.join ', '
|
18
|
-
when 'param_names'
|
19
|
-
attributes(include_id).map { |attribute| attribute.name + ':' }.join ', '
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def attributes(include_id)
|
26
|
-
if include_id
|
27
|
-
@attributes + [Hecks::Domain::DomainBuilder::Attribute.new('id:value')]
|
28
|
-
else
|
29
|
-
@attributes
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module Hecks
|
3
|
-
module Domain
|
4
|
-
module CLI
|
5
|
-
class GenerateDomainObject < Thor::Group
|
6
|
-
include Thor::Actions
|
7
|
-
|
8
|
-
class_option :head_name, aliases: '-h', desc: 'the name of the aggregate head'
|
9
|
-
class_option :attributes, aliases: '-a', type: :array, desc: 'attributes for the aggregate head'
|
10
|
-
class_option :name, aliases: '-n', desc: 'attributes for the aggregate head'
|
11
|
-
class_option :type, aliases: '-t', desc: 'The type of domain object you want to create'
|
12
|
-
class_option :module_name, aliases: '-m', desc: 'Domain Module'
|
13
|
-
class_option :referenced_entity, aliases: '-r', desc: 'Referenced Entity'
|
14
|
-
|
15
|
-
def self.source_root
|
16
|
-
File.dirname(__FILE__) + '/templates'
|
17
|
-
end
|
18
|
-
|
19
|
-
def create_aggregate_folder
|
20
|
-
directory(options[:type].to_s, '.')
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def assignment_template(attributes)
|
26
|
-
AssignmentTemplate.new(attributes).render
|
27
|
-
end
|
28
|
-
|
29
|
-
def option_format(format, include_id: false)
|
30
|
-
OptionFormatter.new(options[:attributes]).call(format, include_id: include_id)
|
31
|
-
end
|
32
|
-
|
33
|
-
def head_name
|
34
|
-
options[:head_name]
|
35
|
-
end
|
36
|
-
|
37
|
-
def name
|
38
|
-
options[:name]
|
39
|
-
end
|
40
|
-
|
41
|
-
def file_name
|
42
|
-
name.underscore
|
43
|
-
end
|
44
|
-
|
45
|
-
def attribute_names_without_id
|
46
|
-
attributes_without_id.map(&:name)
|
47
|
-
end
|
48
|
-
|
49
|
-
def module_name
|
50
|
-
options[:module_name]
|
51
|
-
end
|
52
|
-
|
53
|
-
def domain_name
|
54
|
-
Dir.pwd.split('/').last
|
55
|
-
end
|
56
|
-
|
57
|
-
def attributes_without_id_as_string
|
58
|
-
attributes_without_id.map { |attribute| ':' + Hecks::Domain::DomainBuilder::Attribute.new(attribute).name }.join ', '
|
59
|
-
end
|
60
|
-
|
61
|
-
def attributes
|
62
|
-
options[:attributes] + ['id:integer']
|
63
|
-
end
|
64
|
-
|
65
|
-
def attributes_without_id
|
66
|
-
options[:attributes]
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
data/lib/cli/new.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
load('Domain') if File.exist?('Domain')
|
3
|
-
module Hecks
|
4
|
-
module Domain
|
5
|
-
module CLI
|
6
|
-
class New < Thor::Group
|
7
|
-
namespace :hecks
|
8
|
-
include Thor::Actions
|
9
|
-
|
10
|
-
class_option :nobuilder, aliases: '-n', desc: 'load schema from builder'
|
11
|
-
class_option :dry_run, aliases: '-d', desc: 'Use when specifying a schema file to output the commands, without running them'
|
12
|
-
|
13
|
-
def self.source_root
|
14
|
-
File.dirname(__FILE__)
|
15
|
-
end
|
16
|
-
|
17
|
-
def load_from_builder
|
18
|
-
return if options[:nobuilder]
|
19
|
-
CommandBuilder.new(
|
20
|
-
name: File.basename(Dir.getwd),
|
21
|
-
dry_run: !options[:dry_run].nil?
|
22
|
-
).call
|
23
|
-
end
|
24
|
-
|
25
|
-
def create_hexagon_folder
|
26
|
-
return unless options[:nobuilder]
|
27
|
-
directory('templates/domain', ".")
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def name
|
33
|
-
File.basename(Dir.getwd)
|
34
|
-
end
|
35
|
-
|
36
|
-
def module_name
|
37
|
-
name.camelize
|
38
|
-
end
|
39
|
-
|
40
|
-
def domain_module_name
|
41
|
-
domain_name.camelize
|
42
|
-
end
|
43
|
-
|
44
|
-
def condensed_module_name
|
45
|
-
name.delete('_')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module <%= domain_name.camelize %>
|
2
|
-
module Domain
|
3
|
-
module <%= name.camelize %>
|
4
|
-
class <%= options[:head_name].camelize %>
|
5
|
-
attr_accessor <%= option_format('attribute_string', include_id: true) %>
|
6
|
-
def initialize(<%= option_format('param_names', include_id: true) %>)
|
7
|
-
<%= assignment_template(attributes) %>
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_json
|
11
|
-
JSON.generate(<%= option_format('keys_and_values', include_id: true) %>)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module <%= domain_name.camelize %>
|
2
|
-
module Domain
|
3
|
-
module <%= name.camelize %>
|
4
|
-
class Repository
|
5
|
-
@collection = {}
|
6
|
-
@last_id = 0
|
7
|
-
|
8
|
-
def self.create attributes={}
|
9
|
-
id = @last_id + 1
|
10
|
-
@collection[id] = <%= options[:head_name].camelize %>.new(attributes.merge(id: id))
|
11
|
-
@last_id = id
|
12
|
-
Struct.new(:id).new(id)
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.update id, attributes
|
16
|
-
entity = read id
|
17
|
-
|
18
|
-
return unless entity
|
19
|
-
attributes.each do |field, value|
|
20
|
-
entity.send("#{field}=", value)
|
21
|
-
end
|
22
|
-
|
23
|
-
entity
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.read id
|
27
|
-
@collection[id]
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.delete(id)
|
31
|
-
@collection.delete(id)
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.delete_all
|
35
|
-
@collection = {}
|
36
|
-
@last_id = 0
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = '<%= name %>'
|
3
|
-
s.homepage = ""
|
4
|
-
s.version = File.read('Version').gsub("\n", '')
|
5
|
-
s.date = '2016-09-12'
|
6
|
-
s.summary = "Summary"
|
7
|
-
s.description = "Description"
|
8
|
-
s.authors = ["Author"]
|
9
|
-
s.email = 'email@example.com'
|
10
|
-
s.files = Dir["lib/**/*"]
|
11
|
-
s.license = 'MIT'
|
12
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
0.0.0
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module <%= module_name %>
|
2
|
-
Dir[File.dirname(__FILE__) + "/domain/**/*.rb"].each {|file| require file}
|
3
|
-
|
4
|
-
def self.domain_modules
|
5
|
-
Domain.constants.map { |name| Domain.const_get(name)}
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.repositories
|
9
|
-
domain_modules.map do |domain_module|
|
10
|
-
[module_name(domain_module), domain_module.const_get(:Repository)]
|
11
|
-
end.to_h
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.module_name(domain_module)
|
15
|
-
domain_module.to_s.downcase.split("::").last.to_sym
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.spec_path
|
19
|
-
File.dirname(__FILE__) + '/../Domain'
|
20
|
-
end
|
21
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module <%= domain_name.camelize %>
|
2
|
-
module Domain
|
3
|
-
module <%= module_name.camelize %>
|
4
|
-
class <%= name.camelize %>
|
5
|
-
attr_accessor :id, :referenced_entity
|
6
|
-
|
7
|
-
def self.factory(group_attributes)
|
8
|
-
return <%= name.camelize %>.new(group_attributes) unless group_attributes.is_a?(Array)
|
9
|
-
group_attributes.map do |attributes|
|
10
|
-
<%= name.camelize %>.new(attributes)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(id:)
|
15
|
-
@id = id
|
16
|
-
@referenced_entity = <%= options[:referenced_entity] %>
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_json(config)
|
20
|
-
JSON.generate({id: @id, referenced_entity: @referenced_entity})
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module <%= domain_name.camelize %>
|
2
|
-
module Domain
|
3
|
-
module <%= module_name.camelize %>
|
4
|
-
class <%= name.camelize %>
|
5
|
-
attr_accessor <%= attributes_without_id_as_string %>
|
6
|
-
|
7
|
-
def self.factory(group_attributes)
|
8
|
-
return <%= name.camelize %>.new(group_attributes) unless group_attributes.is_a?(Array)
|
9
|
-
group_attributes.map do |attributes|
|
10
|
-
<%= name.camelize %>.new(attributes)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(<%= option_format('param_names') %>)
|
15
|
-
<%= assignment_template(attributes_without_id) %>
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_json(config)
|
19
|
-
JSON.generate(<%= option_format('keys_and_values') %>)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
module Hecks
|
2
|
-
module Domain
|
3
|
-
class DomainBuilder
|
4
|
-
class Attribute
|
5
|
-
attr_writer :type
|
6
|
-
attr_reader :object_name
|
7
|
-
|
8
|
-
def initialize(string)
|
9
|
-
@string = string
|
10
|
-
@object_name = object_name
|
11
|
-
end
|
12
|
-
|
13
|
-
def list?
|
14
|
-
@string.include?("[")
|
15
|
-
end
|
16
|
-
|
17
|
-
def name
|
18
|
-
@string.split(":").first
|
19
|
-
end
|
20
|
-
|
21
|
-
def type
|
22
|
-
return @type if @type
|
23
|
-
@string.split(":").last.delete("[").delete("]").camelize
|
24
|
-
end
|
25
|
-
|
26
|
-
def domain_module
|
27
|
-
return unless @string.include?("::")
|
28
|
-
@string.split("::").first.split(":").last.camelize
|
29
|
-
end
|
30
|
-
|
31
|
-
def copy(new_values={})
|
32
|
-
result = self.class.new(@string)
|
33
|
-
result.type = new_values[:type] if new_values[:type]
|
34
|
-
result
|
35
|
-
end
|
36
|
-
|
37
|
-
def reference?
|
38
|
-
!primitive? && !list?
|
39
|
-
end
|
40
|
-
|
41
|
-
def referenced_object
|
42
|
-
return unless reference?
|
43
|
-
return @string.split("::").last if @string.include?("::")
|
44
|
-
@string.split(":").last
|
45
|
-
end
|
46
|
-
|
47
|
-
def primitive?
|
48
|
-
['String', 'Integer', 'Currency'].include?(type)
|
49
|
-
end
|
50
|
-
|
51
|
-
def ==(other)
|
52
|
-
return false if other.name != name
|
53
|
-
return false if other.type != type
|
54
|
-
return false if other.domain_module != domain_module
|
55
|
-
return true
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|