domainic-attributer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +14 -0
- data/LICENSE +21 -0
- data/README.md +396 -0
- data/lib/domainic/attributer/attribute/callback.rb +68 -0
- data/lib/domainic/attributer/attribute/coercer.rb +93 -0
- data/lib/domainic/attributer/attribute/mixin/belongs_to_attribute.rb +68 -0
- data/lib/domainic/attributer/attribute/signature.rb +338 -0
- data/lib/domainic/attributer/attribute/validator.rb +128 -0
- data/lib/domainic/attributer/attribute.rb +256 -0
- data/lib/domainic/attributer/attribute_set.rb +208 -0
- data/lib/domainic/attributer/class_methods.rb +247 -0
- data/lib/domainic/attributer/dsl/attribute_builder/option_parser.rb +247 -0
- data/lib/domainic/attributer/dsl/attribute_builder.rb +233 -0
- data/lib/domainic/attributer/dsl/initializer.rb +130 -0
- data/lib/domainic/attributer/dsl/method_injector.rb +97 -0
- data/lib/domainic/attributer/dsl.rb +5 -0
- data/lib/domainic/attributer/instance_methods.rb +65 -0
- data/lib/domainic/attributer/undefined.rb +44 -0
- data/lib/domainic/attributer.rb +114 -0
- data/lib/domainic-attributer.rb +3 -0
- data/sig/domainic/attributer/attribute/callback.rbs +48 -0
- data/sig/domainic/attributer/attribute/coercer.rbs +59 -0
- data/sig/domainic/attributer/attribute/mixin/belongs_to_attribute.rbs +46 -0
- data/sig/domainic/attributer/attribute/signature.rbs +223 -0
- data/sig/domainic/attributer/attribute/validator.rbs +83 -0
- data/sig/domainic/attributer/attribute.rbs +150 -0
- data/sig/domainic/attributer/attribute_set.rbs +134 -0
- data/sig/domainic/attributer/class_methods.rbs +151 -0
- data/sig/domainic/attributer/dsl/attribute_builder/option_parser.rbs +130 -0
- data/sig/domainic/attributer/dsl/attribute_builder.rbs +156 -0
- data/sig/domainic/attributer/dsl/initializer.rbs +91 -0
- data/sig/domainic/attributer/dsl/method_injector.rbs +66 -0
- data/sig/domainic/attributer/dsl.rbs +1 -0
- data/sig/domainic/attributer/instance_methods.rbs +53 -0
- data/sig/domainic/attributer/undefined.rbs +14 -0
- data/sig/domainic/attributer.rbs +69 -0
- data/sig/domainic-attributer.rbs +1 -0
- data/sig/manifest.yaml +2 -0
- metadata +89 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
module Domainic
|
2
|
+
module Attributer
|
3
|
+
module DSL
|
4
|
+
# A class responsible for injecting attribute methods into classes.
|
5
|
+
#
|
6
|
+
# This class handles the creation of reader and writer methods for attributes,
|
7
|
+
# ensuring they are injected safely without overwriting existing methods. It
|
8
|
+
# respects visibility settings and properly handles value assignment through
|
9
|
+
# the attribute system.
|
10
|
+
#
|
11
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
12
|
+
# @since 0.1.0
|
13
|
+
class MethodInjector
|
14
|
+
@attribute: Attribute
|
15
|
+
|
16
|
+
@base: __todo__
|
17
|
+
|
18
|
+
# Inject methods for an attribute into a class.
|
19
|
+
#
|
20
|
+
# @param base [Class, Module] the class to inject methods into
|
21
|
+
# @param attribute [Attribute] the attribute to create methods for
|
22
|
+
#
|
23
|
+
# @return [void]
|
24
|
+
def self.inject!: (__todo__ base, Attribute attribute) -> void
|
25
|
+
|
26
|
+
# Initialize a new MethodInjector.
|
27
|
+
#
|
28
|
+
# @param base [Class, Module] the class to inject methods into
|
29
|
+
# @param attribute [Attribute] the attribute to create methods for
|
30
|
+
#
|
31
|
+
# @return [void]
|
32
|
+
def initialize: (__todo__ base, Attribute attribute) -> void
|
33
|
+
|
34
|
+
# Inject reader and writer methods.
|
35
|
+
#
|
36
|
+
# @return [void]
|
37
|
+
def inject!: () -> void
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Define a method if it doesn't already exist.
|
42
|
+
#
|
43
|
+
# @param method_name [Symbol] the name of the method to define
|
44
|
+
# @yield the method body to define
|
45
|
+
#
|
46
|
+
# @return [void]
|
47
|
+
def define_safe_method: (Symbol method_name) { (?) [self: untyped] -> void } -> void
|
48
|
+
|
49
|
+
# Inject the attribute reader method.
|
50
|
+
#
|
51
|
+
# Creates a reader method with the configured visibility.
|
52
|
+
#
|
53
|
+
# @return [void]
|
54
|
+
def inject_reader!: () -> void
|
55
|
+
|
56
|
+
# Inject the attribute writer method.
|
57
|
+
#
|
58
|
+
# Creates a writer method that processes values through the attribute
|
59
|
+
# system before assignment. Sets the configured visibility.
|
60
|
+
#
|
61
|
+
# @return [void]
|
62
|
+
def inject_writer!: () -> void
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Domainic
|
2
|
+
module Attributer
|
3
|
+
# A module providing instance-level attribute functionality.
|
4
|
+
#
|
5
|
+
# This module defines instance methods for objects that include Domainic::Attributer.
|
6
|
+
# It provides initialization handling and attribute serialization capabilities, making
|
7
|
+
# it easy to work with attribute values in a consistent way.
|
8
|
+
#
|
9
|
+
# @example Basic usage
|
10
|
+
# class Person
|
11
|
+
# include Domainic::Attributer
|
12
|
+
#
|
13
|
+
# argument :name
|
14
|
+
# option :age, default: nil
|
15
|
+
# option :role, default: 'user', private_read: true
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# person = Person.new('Alice', age: 30)
|
19
|
+
# person.to_h # => { name: 'Alice', age: 30 } # role is private, not included
|
20
|
+
#
|
21
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
22
|
+
# @since 0.1.0
|
23
|
+
module InstanceMethods
|
24
|
+
# Initialize a new instance with attribute values.
|
25
|
+
#
|
26
|
+
# Handles both positional arguments and keyword options, applying them to their
|
27
|
+
# corresponding attributes. This process includes:
|
28
|
+
# 1. Validating required arguments
|
29
|
+
# 2. Applying default values
|
30
|
+
# 3. Type validation and coercion
|
31
|
+
# 4. Change notifications
|
32
|
+
#
|
33
|
+
# @raise [ArgumentError] if required arguments are missing
|
34
|
+
# @return [void]
|
35
|
+
def initialize: (*untyped arguments, **untyped keyword_arguments) -> void
|
36
|
+
|
37
|
+
# Convert public attribute values to a hash.
|
38
|
+
#
|
39
|
+
# Creates a hash containing all public readable attributes and their current values.
|
40
|
+
# Any attributes marked as private or protected for reading are excluded from
|
41
|
+
# the result.
|
42
|
+
#
|
43
|
+
# @example Basic conversion
|
44
|
+
# person = Person.new('Alice', age: 30)
|
45
|
+
# person.to_h # => { name: 'Alice', age: 30 }
|
46
|
+
#
|
47
|
+
# @return [Hash{Symbol => Object}] hash of attribute names to values
|
48
|
+
def to_hash: () -> Hash[Symbol, untyped]
|
49
|
+
|
50
|
+
alias to_h to_hash
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Domainic
|
2
|
+
module Attributer
|
3
|
+
# A singleton object representing an undefined value.
|
4
|
+
#
|
5
|
+
# This object is used throughout Domainic::Attributer to represent values that
|
6
|
+
# are explicitly undefined, as opposed to nil which represents the absence of
|
7
|
+
# a value. It is immutable and implements custom string representations for
|
8
|
+
# debugging purposes.
|
9
|
+
#
|
10
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
11
|
+
# @since 0.1.0
|
12
|
+
Undefined: Object
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Domainic
|
2
|
+
# Core functionality for defining and managing Ruby class attributes.
|
3
|
+
#
|
4
|
+
# This module provides a flexible attribute system for Ruby classes that supports
|
5
|
+
# positional arguments and keyword options with features like type validation,
|
6
|
+
# coercion, and visibility control.
|
7
|
+
#
|
8
|
+
# Can be included directly with default method names or customized via {Domainic.Attributer}.
|
9
|
+
#
|
10
|
+
# @example Basic usage with default method names
|
11
|
+
# class Person
|
12
|
+
# include Domainic::Attributer
|
13
|
+
#
|
14
|
+
# argument :name
|
15
|
+
# option :age
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# @example Custom method names
|
19
|
+
# class Person
|
20
|
+
# include Domainic.Attributer(argument: :param, option: :opt)
|
21
|
+
#
|
22
|
+
# param :name
|
23
|
+
# opt :age
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
27
|
+
# @since 0.1.0
|
28
|
+
module Attributer
|
29
|
+
# Create a customized Attributer module.
|
30
|
+
#
|
31
|
+
# @param argument [Symbol, String] custom name for the argument method
|
32
|
+
# @param option [Symbol, String] custom name for the option method
|
33
|
+
# @return [Module] configured Attributer module
|
34
|
+
def self.call: (?argument: (String | Symbol)?, ?option: (String | Symbol)?) -> Module
|
35
|
+
|
36
|
+
# Handle direct module inclusion.
|
37
|
+
#
|
38
|
+
# @param base [Class, Module] the including class/module
|
39
|
+
# @return [void]
|
40
|
+
def self.included: (untyped base) -> void
|
41
|
+
|
42
|
+
# Configure base class with Attributer functionality.
|
43
|
+
#
|
44
|
+
# @param base [Class, Module] the target class/module
|
45
|
+
# @param options [Hash] method name customization options
|
46
|
+
# @return [void]
|
47
|
+
private def self.include_attributer: (untyped base, ?argument: (String | Symbol)?, ?option: (String | Symbol)?) -> void
|
48
|
+
|
49
|
+
# Set up custom method names.
|
50
|
+
#
|
51
|
+
# @param base [Class, Module] the target class/module
|
52
|
+
# @param options [Hash] method name customization options
|
53
|
+
# @return [void]
|
54
|
+
private def self.inject_custom_methods!: (untyped base, ?argument: (String | Symbol)?, ?option: (String | Symbol)?) -> void
|
55
|
+
end
|
56
|
+
|
57
|
+
# Create a customized Attributer module.
|
58
|
+
#
|
59
|
+
# Provides a convenient way to include Attributer with customized method names.
|
60
|
+
#
|
61
|
+
# @example
|
62
|
+
# class Person
|
63
|
+
# include Domainic.Attributer(argument: :param, option: :opt)
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# @param options [Hash] method name customization options
|
67
|
+
# @return [Module] configured Attributer module
|
68
|
+
def self.Attributer: (?argument: (String | Symbol)?, ?option: (String | Symbol)?) -> Module
|
69
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
|
data/sig/manifest.yaml
ADDED
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: domainic-attributer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Allen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-12-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Your domain objects deserve better than plain old attributes. Level up
|
14
|
+
your DDD game with powerful, configurable, and well-documented class attributes
|
15
|
+
that actually know what they want in life!
|
16
|
+
email:
|
17
|
+
- hello@aaronmallen.me
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- CHANGELOG.md
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- lib/domainic-attributer.rb
|
26
|
+
- lib/domainic/attributer.rb
|
27
|
+
- lib/domainic/attributer/attribute.rb
|
28
|
+
- lib/domainic/attributer/attribute/callback.rb
|
29
|
+
- lib/domainic/attributer/attribute/coercer.rb
|
30
|
+
- lib/domainic/attributer/attribute/mixin/belongs_to_attribute.rb
|
31
|
+
- lib/domainic/attributer/attribute/signature.rb
|
32
|
+
- lib/domainic/attributer/attribute/validator.rb
|
33
|
+
- lib/domainic/attributer/attribute_set.rb
|
34
|
+
- lib/domainic/attributer/class_methods.rb
|
35
|
+
- lib/domainic/attributer/dsl.rb
|
36
|
+
- lib/domainic/attributer/dsl/attribute_builder.rb
|
37
|
+
- lib/domainic/attributer/dsl/attribute_builder/option_parser.rb
|
38
|
+
- lib/domainic/attributer/dsl/initializer.rb
|
39
|
+
- lib/domainic/attributer/dsl/method_injector.rb
|
40
|
+
- lib/domainic/attributer/instance_methods.rb
|
41
|
+
- lib/domainic/attributer/undefined.rb
|
42
|
+
- sig/domainic-attributer.rbs
|
43
|
+
- sig/domainic/attributer.rbs
|
44
|
+
- sig/domainic/attributer/attribute.rbs
|
45
|
+
- sig/domainic/attributer/attribute/callback.rbs
|
46
|
+
- sig/domainic/attributer/attribute/coercer.rbs
|
47
|
+
- sig/domainic/attributer/attribute/mixin/belongs_to_attribute.rbs
|
48
|
+
- sig/domainic/attributer/attribute/signature.rbs
|
49
|
+
- sig/domainic/attributer/attribute/validator.rbs
|
50
|
+
- sig/domainic/attributer/attribute_set.rbs
|
51
|
+
- sig/domainic/attributer/class_methods.rbs
|
52
|
+
- sig/domainic/attributer/dsl.rbs
|
53
|
+
- sig/domainic/attributer/dsl/attribute_builder.rbs
|
54
|
+
- sig/domainic/attributer/dsl/attribute_builder/option_parser.rbs
|
55
|
+
- sig/domainic/attributer/dsl/initializer.rbs
|
56
|
+
- sig/domainic/attributer/dsl/method_injector.rbs
|
57
|
+
- sig/domainic/attributer/instance_methods.rbs
|
58
|
+
- sig/domainic/attributer/undefined.rbs
|
59
|
+
- sig/manifest.yaml
|
60
|
+
homepage: https://github.com/domainic/domainic/tree/domainic-attributer-v0.1.0/domainic-attributer
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata:
|
64
|
+
bug_tracker_uri: https://github.com/domainic/domainic/issues
|
65
|
+
changelog_uri: https://github.com/domainic/domainic/releases/tag/domainic-attributer-v0.1.0
|
66
|
+
homepage_uri: https://github.com/domainic/domainic/tree/domainic-attributer-v0.1.0/domainic-attributer
|
67
|
+
rubygems_mfa_required: 'true'
|
68
|
+
source_code_uri: https://github.com/domainic/domainic/tree/domainic-attributer-v0.1.0/domainic-attributer
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.1'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubygems_version: 3.3.27
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: A toolkit for creating self-documenting, type-safe class attributes with
|
88
|
+
built-in validation, coercion, and default values.
|
89
|
+
test_files: []
|