domakase 0.0.1
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 +7 -0
- data/CHANGELOG.md +0 -0
- data/LICENSE +21 -0
- data/README.md +3 -0
- data/domakase.gemspec +24 -0
- data/lib/domakase/controller.rb +15 -0
- data/lib/domakase/record.rb +22 -0
- data/lib/domakase/version.rb +5 -0
- data/lib/domakase.rb +44 -0
- data/lib/generators/domakase/domain/actions.rb +41 -0
- data/lib/generators/domakase/domain/controller_generator.rb +29 -0
- data/lib/generators/domakase/domain/model_generator.rb +34 -0
- data/lib/generators/domakase/domain/templates/controller.rb.erb +6 -0
- data/lib/generators/domakase/domain/templates/model.rb.erb +6 -0
- data/lib/generators/domakase/domain_generator.rb +12 -0
- metadata +60 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9cd8b8459568576f370b30611411ed1c9acd6ed8db5882717ff10401c902ad9a
|
|
4
|
+
data.tar.gz: 3b6cc8e1e4bbe9d47101aa766c37970c0219e3d373b812331b4e9856f0082fc3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 7bc2ee7db4e791a4b61b20247e659480c33fd75971aa3feb31d9cceb5e20a870980b6e6a986a4940a4625015bc5f6c70cdc22cd8a3393ebeb9a3824c297f2d23
|
|
7
|
+
data.tar.gz: a16be9829edbabcc985a6ec40b3447ac1e39b8be2c02480fa882fba51285a91a1d5969169fac2dd0086caeff1e1381cb86e12384ed835280094840d5ff17347d
|
data/CHANGELOG.md
ADDED
|
File without changes
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Patrick McDonald
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/domakase.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require_relative "lib/domakase/version"
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |gem|
|
|
4
|
+
gem.authors = ["Patrick McDonald"]
|
|
5
|
+
gem.email = ["patrick@mcdonald.fyi"]
|
|
6
|
+
gem.summary = "Domain-driven design for Ruby on Rails"
|
|
7
|
+
gem.description = "Domain-driven design for Ruby on Rails"
|
|
8
|
+
gem.homepage = "https://github.com/grapadacious/domakase"
|
|
9
|
+
gem.license = "MIT"
|
|
10
|
+
|
|
11
|
+
gem.files = %w[domakase.gemspec README.md CHANGELOG.md LICENSE] + `git ls-files | grep -E '^lib'`.split("\n")
|
|
12
|
+
gem.name = "domakase"
|
|
13
|
+
gem.version = Domakase::VERSION
|
|
14
|
+
gem.required_ruby_version = ">= 3.3.0"
|
|
15
|
+
|
|
16
|
+
gem.metadata = {
|
|
17
|
+
"homepage_uri" => "https://github.com/grapadacious/domakase",
|
|
18
|
+
"bug_tracker_uri" => "https://github.com/grapadacious/domakase/issues",
|
|
19
|
+
"documentation_uri" => "https://github.com/grapadacious/domakase/wiki",
|
|
20
|
+
"changelog_uri" => "https://github.com/grapadacious/domakase/blob/main/CHANGELOG.md",
|
|
21
|
+
"source_code_uri" => "https://github.com/grapadacious/domakase",
|
|
22
|
+
"rubygems_mfa_required" => "true"
|
|
23
|
+
}
|
|
24
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Domakase
|
|
4
|
+
class Controller < ActionController::Base
|
|
5
|
+
prepend_before_action do
|
|
6
|
+
lookup_context.prefixes.prepend(controller_name.underscore)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
prepend_before_action do
|
|
10
|
+
domain, *module_path, _ = controller_path.split("/")
|
|
11
|
+
prepend_view_path ::Rails.root.join("app", "domains", domain, "views")
|
|
12
|
+
prepend_view_path ::Rails.root.join("app", "domains", domain, "views", module_path.join("/"))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Domakase
|
|
4
|
+
# Configure domain models to follow domain-namespaced table naming conventions.
|
|
5
|
+
#
|
|
6
|
+
# Given a domain model with the path <tt>app/domains/staff/models/user.rb</tt>, the table name will be <tt>staff_users</tt>.
|
|
7
|
+
#
|
|
8
|
+
# This also extends to nested models. So if you have a domain model with the path <tt>app/domains/staff/models/user/session.rb</tt>,
|
|
9
|
+
# the table name will be <tt>staff_user_sessions</tt>.
|
|
10
|
+
#
|
|
11
|
+
# If you would like to provide a custom name for your table instead, you can set your own table name
|
|
12
|
+
# in the domain definition like you normally would.
|
|
13
|
+
class Record < ActiveRecord::Base
|
|
14
|
+
def self.table_name
|
|
15
|
+
@table_name || model_name.plural
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.table_name=(table_name)
|
|
19
|
+
@table_name = table_name
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/domakase.rb
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Domakase
|
|
4
|
+
class InvalidDomainPath < StandardError; end
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
def register_all!
|
|
8
|
+
::Rails.root.join("app/domains").children.each do |entry|
|
|
9
|
+
next unless entry.directory?
|
|
10
|
+
|
|
11
|
+
register!(entry.split.last)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def register!(name)
|
|
16
|
+
path = ::Rails.root.join("app/domains/#{name}")
|
|
17
|
+
|
|
18
|
+
raise InvalidDomainPath, path unless Dir.exist?(path)
|
|
19
|
+
|
|
20
|
+
domain_module = initialize_module(name)
|
|
21
|
+
|
|
22
|
+
register("#{path}/controllers", domain_module)
|
|
23
|
+
register("#{path}/controllers/concerns", domain_module)
|
|
24
|
+
register("#{path}/jobs", domain_module)
|
|
25
|
+
register("#{path}/models", domain_module)
|
|
26
|
+
register("#{path}/models/concerns", domain_module)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def initialize_module(name)
|
|
32
|
+
name = name.to_s.camelize
|
|
33
|
+
|
|
34
|
+
Object.const_set(name, Module.new) unless Object.const_defined?(name)
|
|
35
|
+
|
|
36
|
+
name.constantize
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def register(path, namespace)
|
|
40
|
+
::Rails.autoloaders.main.push_dir(path, namespace:) if Dir.exist?(path)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Domakase
|
|
4
|
+
module Generators
|
|
5
|
+
module Domain
|
|
6
|
+
module Actions
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
def module_namespacing(&block)
|
|
10
|
+
*modules, _ = @name.split(":").map(&:camelize)
|
|
11
|
+
|
|
12
|
+
content = modules.reverse.reduce(capture(&block)) do |content, m|
|
|
13
|
+
"module #{m}\n#{indent(content).chomp}\nend"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
concat(content)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def class_name
|
|
20
|
+
"#{file_name.camelize}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def directory_name
|
|
24
|
+
""
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def file_name
|
|
28
|
+
@name.split(":").last
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def file_path
|
|
32
|
+
domain_name, *submodules, _ = @name.split(":")
|
|
33
|
+
|
|
34
|
+
subpath = [directory_name, *submodules, "#{file_name}.rb"].compact_blank.join("/")
|
|
35
|
+
|
|
36
|
+
::Rails.root.join("app/domains/#{domain_name}/#{subpath}")
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "actions"
|
|
4
|
+
|
|
5
|
+
module Domakase
|
|
6
|
+
module Generators
|
|
7
|
+
module Domain
|
|
8
|
+
class ControllerGenerator < ::Rails::Generators::NamedBase
|
|
9
|
+
include Actions
|
|
10
|
+
|
|
11
|
+
source_root File.expand_path("templates", __dir__)
|
|
12
|
+
|
|
13
|
+
def create_controller_file
|
|
14
|
+
template("controller.rb.erb", file_path)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def file_name
|
|
20
|
+
"#{super}_controller"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def directory_name
|
|
24
|
+
"controllers"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
|
|
5
|
+
require_relative "actions"
|
|
6
|
+
|
|
7
|
+
module Domakase
|
|
8
|
+
module Generators
|
|
9
|
+
module Domain
|
|
10
|
+
class ModelGenerator < ::Rails::Generators::NamedBase
|
|
11
|
+
include Actions
|
|
12
|
+
|
|
13
|
+
source_root File.expand_path("templates", __dir__)
|
|
14
|
+
|
|
15
|
+
def create_model_file
|
|
16
|
+
template("model.rb.erb", file_path)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def create_migration_file
|
|
20
|
+
*prefixes, model_name = name.split(":")
|
|
21
|
+
|
|
22
|
+
generate(:migration, "create_#{[*prefixes, model_name.pluralize].join("_")}", inline: true)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def directory_name
|
|
28
|
+
"models"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Domakase
|
|
4
|
+
module Generators
|
|
5
|
+
class DomainGenerator < ::Rails::Generators::NamedBase
|
|
6
|
+
def create_domain_files
|
|
7
|
+
create_file ::Rails.root.join("app/domains/#{file_name}/controllers/concerns/.keep"), ""
|
|
8
|
+
create_file ::Rails.root.join("app/domains/#{file_name}/models/concerns/.keep"), ""
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: domakase
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Patrick McDonald
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Domain-driven design for Ruby on Rails
|
|
13
|
+
email:
|
|
14
|
+
- patrick@mcdonald.fyi
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- CHANGELOG.md
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.md
|
|
22
|
+
- domakase.gemspec
|
|
23
|
+
- lib/domakase.rb
|
|
24
|
+
- lib/domakase/controller.rb
|
|
25
|
+
- lib/domakase/record.rb
|
|
26
|
+
- lib/domakase/version.rb
|
|
27
|
+
- lib/generators/domakase/domain/actions.rb
|
|
28
|
+
- lib/generators/domakase/domain/controller_generator.rb
|
|
29
|
+
- lib/generators/domakase/domain/model_generator.rb
|
|
30
|
+
- lib/generators/domakase/domain/templates/controller.rb.erb
|
|
31
|
+
- lib/generators/domakase/domain/templates/model.rb.erb
|
|
32
|
+
- lib/generators/domakase/domain_generator.rb
|
|
33
|
+
homepage: https://github.com/grapadacious/domakase
|
|
34
|
+
licenses:
|
|
35
|
+
- MIT
|
|
36
|
+
metadata:
|
|
37
|
+
homepage_uri: https://github.com/grapadacious/domakase
|
|
38
|
+
bug_tracker_uri: https://github.com/grapadacious/domakase/issues
|
|
39
|
+
documentation_uri: https://github.com/grapadacious/domakase/wiki
|
|
40
|
+
changelog_uri: https://github.com/grapadacious/domakase/blob/main/CHANGELOG.md
|
|
41
|
+
source_code_uri: https://github.com/grapadacious/domakase
|
|
42
|
+
rubygems_mfa_required: 'true'
|
|
43
|
+
rdoc_options: []
|
|
44
|
+
require_paths:
|
|
45
|
+
- lib
|
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: 3.3.0
|
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '0'
|
|
56
|
+
requirements: []
|
|
57
|
+
rubygems_version: 4.0.10
|
|
58
|
+
specification_version: 4
|
|
59
|
+
summary: Domain-driven design for Ruby on Rails
|
|
60
|
+
test_files: []
|