foobara 0.0.56 → 0.0.58

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.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -1
  3. data/projects/command/lib/foobara/command.rb +3 -0
  4. data/projects/command/src/command/concerns/shortcut_for_run.rb +62 -0
  5. data/projects/command/src/command.rb +3 -36
  6. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/callbacks.rb +3 -1
  7. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/description.rb +1 -1
  8. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/domain_mappers.rb +1 -1
  9. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/entities.rb +1 -1
  10. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/errors.rb +3 -2
  11. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/errors_type.rb +1 -1
  12. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/inputs.rb +7 -2
  13. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/inputs_type.rb +1 -1
  14. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/namespace.rb +1 -1
  15. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/reflection.rb +1 -1
  16. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/result.rb +1 -1
  17. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/result_type.rb +1 -1
  18. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/runtime.rb +1 -39
  19. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/state_machine.rb +1 -1
  20. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/subcommands.rb +1 -1
  21. data/projects/command/src/{concerns → command_pattern_implementation/concerns}/transactions.rb +1 -1
  22. data/projects/command/src/command_pattern_implementation.rb +38 -0
  23. data/projects/domain_mapper/src/domain_mapper.rb +3 -3
  24. data/projects/enumerated/src/enumerated.rb +9 -0
  25. data/projects/enumerated/src/values.rb +21 -0
  26. metadata +21 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc60d4f3abb03f4cb398aca513da228aaaf2359941a9d6873d970004b8faf1a8
4
- data.tar.gz: d94f3b0f676dcf2a69ae1acdbad58efa0dc0ff8626f77de6219ca55b23ac7e41
3
+ metadata.gz: 73dea1ae2bd36b295db67678c8d5717458a386b0a1bd11fbf5fffd4adf117a6a
4
+ data.tar.gz: 1b99f0f9e5294302d13061240696c05d7c6542291aaaec8f6049c8f5eef69800
5
5
  SHA512:
6
- metadata.gz: 6348c488613dfb77695af95e1951a0e373787a8277bcee39e26495ee5b1c66f46e8f30a46c24ae7db4050bade755a0fbf181a2618de0f149308c752660fe7352
7
- data.tar.gz: 6fe896d06734768e017dfc21753d7de90da00fdde88a5822900876f2030e84c04539fddc0ecc9bf7eb638b4ef9e745c9aafd8afa0826c97dc115ce9029cce46b
6
+ metadata.gz: b03089aee29a4d85bebc9dccbe8bfe32b3891fa81689fda604f28ab0d3c9909f516b34f73c6370bea9c3b4da3a49569cd9da57319245b482ada56142b0b8bf05
7
+ data.tar.gz: 931145ba8982bb71388135b95262b321f9b0ac3f1b9dc77ee8cd64e5f701083e0f46fb0332bb5844fb642ddfcebe268c3e6e12888a67f08f82fa574788b00a18
data/CHANGELOG.md CHANGED
@@ -1,7 +1,15 @@
1
+ ## [0.0.58] - 2025-02-20
2
+
3
+ - DomainMapper no longer inherits from Command. Instead, both include CommandPatternImplementation mixin
4
+
5
+ ## [0.0.57] - 2025-02-18
6
+
7
+ - Add Enumerated.make_module helper
8
+
1
9
  ## [0.0.56] - 2025-02-16
2
10
 
3
11
  - Bump Ruby to 3.4.2
4
- - Add a ignore_unexpected_attributes option to Model#initialize
12
+ - Add an ignore_unexpected_attributes option to Model#initialize
5
13
 
6
14
  ## [0.0.55] - 2025-02-01
7
15
 
@@ -1,4 +1,7 @@
1
1
  module Foobara
2
+ # TODO: Make some kind of module to house these methods instead of the Command class
3
+ class Service; end
4
+
2
5
  class Command
3
6
  class << self
4
7
  def install!
@@ -0,0 +1,62 @@
1
+ module Foobara
2
+ class Command
3
+ module Concerns
4
+ module ShortcutForRun
5
+ include Concern
6
+
7
+ on_include do
8
+ Command.after_subclass_defined do |subclass|
9
+ Command.all << subclass
10
+ # This results in being able to use the command class name instead of .run! if you want.
11
+ # So instead of DoIt.run!(inputs) you can just do DoIt(inputs)
12
+ # TODO: can we kill this? I don't think anything uses this nor would really need to.
13
+ # Calling code could define such helper methods if desired but could be a bad idea since it is nice for
14
+ # command calls to stick out as command calls which would be less obvious if they just looked like random
15
+ # method calls (except that they are class case instead of underscore case)
16
+ subclass.define_command_named_function
17
+ end
18
+ end
19
+
20
+ module ClassMethods
21
+ def define_command_named_function
22
+ command_class = self
23
+ convenience_method_name = Foobara::Util.non_full_name(command_class)
24
+ containing_module = Foobara::Util.module_for(command_class) || Object
25
+
26
+ if containing_module.is_a?(::Class)
27
+ containing_module.singleton_class.define_method convenience_method_name do |*args, **opts, &block|
28
+ command_class.run!(*args, **opts, &block)
29
+ end
30
+
31
+ containing_module.define_method convenience_method_name do |*args, **opts, &block|
32
+ command_class.run!(*args, **opts, &block)
33
+ end
34
+ else
35
+ containing_module.module_eval do
36
+ module_function
37
+
38
+ define_method convenience_method_name do |*args, **opts, &block|
39
+ command_class.run!(*args, **opts, &block)
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ def undefine_command_named_function
46
+ command_class = self
47
+ convenience_method_name = Foobara::Util.non_full_name(command_class)
48
+ containing_module = Foobara::Util.module_for(command_class) || Object
49
+
50
+ return unless containing_module.respond_to?(convenience_method_name)
51
+
52
+ containing_module.singleton_class.undef_method convenience_method_name
53
+
54
+ if containing_module.is_a?(::Class)
55
+ containing_module.undef_method convenience_method_name
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,40 +1,7 @@
1
1
  module Foobara
2
2
  class Command
3
- include TruncatedInspect
4
-
5
- include Concerns::Description
6
- include Concerns::Namespace
7
-
8
- include Concerns::InputsType
9
- include Concerns::ErrorsType
10
- include Concerns::ResultType
11
-
12
- include Concerns::Inputs
13
- include Concerns::Errors
14
- include Concerns::Result
15
-
16
- include Concerns::Runtime
17
- include Concerns::Callbacks
18
- include Concerns::StateMachine
19
- include Concerns::Transactions
20
- include Concerns::Entities
21
- include Concerns::Subcommands
22
- include Concerns::DomainMappers
23
- include Concerns::Reflection
24
-
25
- # TODO: this feels like a hack and shouldn't be necessary. Let's try to fix Concern class inheritance, instead.
26
- self.subclass_defined_callbacks ||= Foobara::Callback::Registry::SingleAction.new
27
-
28
- attr_reader :raw_inputs
29
-
30
- def initialize(inputs = {})
31
- @raw_inputs = inputs
32
- super()
33
- end
34
- end
35
-
36
- Command.after_subclass_defined do |subclass|
37
- Command.all << subclass
38
- subclass.define_command_named_function
3
+ include CommandPatternImplementation
4
+ # Maybe make ShortcutForRun optional and maybe even move it to a different repository?
5
+ include Concerns::ShortcutForRun
39
6
  end
40
7
  end
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module Callbacks
5
5
  include Concern
@@ -25,6 +25,8 @@ module Foobara
25
25
  end
26
26
 
27
27
  on_include do
28
+ self.subclass_defined_callbacks ||= Foobara::Callback::Registry::SingleAction.new
29
+
28
30
  [self, singleton_class].each do |target|
29
31
  %i[before after].each do |type|
30
32
  target.define_method "#{type}_any_transition" do |&block|
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module Description
5
5
  include Concern
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module DomainMappers
5
5
  class ForgotToDependOnDomainMapperError < Foobara::RuntimeError
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module Entities
5
5
  include Concern
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module Errors
5
5
  include Concern
@@ -46,8 +46,9 @@ module Foobara
46
46
 
47
47
  attr_reader :error_collection
48
48
 
49
- def initialize
49
+ def initialize(...)
50
50
  @error_collection = ErrorCollection.new
51
+ super
51
52
  end
52
53
 
53
54
  foobara_delegate :has_errors?, to: :error_collection
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module ErrorsType
5
5
  include Concern
@@ -1,12 +1,17 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module Inputs
5
5
  class UnexpectedInputValidationError < StandardError; end
6
6
 
7
7
  include Concern
8
8
 
9
- attr_reader :inputs
9
+ attr_reader :inputs, :raw_inputs
10
+
11
+ def initialize(inputs = {})
12
+ @raw_inputs = inputs
13
+ super()
14
+ end
10
15
 
11
16
  def method_missing(method_name, *args, &)
12
17
  if respond_to_missing_for_inputs?(method_name)
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module InputsType
5
5
  include Concern
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module Namespace
5
5
  include Concern
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module Reflection
5
5
  include Concern
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module Result
5
5
  include Concern
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module ResultType
5
5
  include Concern
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module Runtime
5
5
  include Concern
@@ -15,44 +15,6 @@ module Foobara
15
15
  def run!(...)
16
16
  new(...).run!
17
17
  end
18
-
19
- def define_command_named_function
20
- command_class = self
21
- convenience_method_name = Foobara::Util.non_full_name(command_class)
22
- containing_module = Foobara::Util.module_for(command_class) || Object
23
-
24
- if containing_module.is_a?(::Class)
25
- containing_module.singleton_class.define_method convenience_method_name do |*args, **opts, &block|
26
- command_class.run!(*args, **opts, &block)
27
- end
28
-
29
- containing_module.define_method convenience_method_name do |*args, **opts, &block|
30
- command_class.run!(*args, **opts, &block)
31
- end
32
- else
33
- containing_module.module_eval do
34
- module_function
35
-
36
- define_method convenience_method_name do |*args, **opts, &block|
37
- command_class.run!(*args, **opts, &block)
38
- end
39
- end
40
- end
41
- end
42
-
43
- def undefine_command_named_function
44
- command_class = self
45
- convenience_method_name = Foobara::Util.non_full_name(command_class)
46
- containing_module = Foobara::Util.module_for(command_class) || Object
47
-
48
- return unless containing_module.respond_to?(convenience_method_name)
49
-
50
- containing_module.singleton_class.undef_method convenience_method_name
51
-
52
- if containing_module.is_a?(::Class)
53
- containing_module.undef_method convenience_method_name
54
- end
55
- end
56
18
  end
57
19
 
58
20
  attr_reader :outcome, :exception
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module StateMachine
5
5
  def state_machine
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module Subcommands
5
5
  include Concern
@@ -1,5 +1,5 @@
1
1
  module Foobara
2
- class Command
2
+ module CommandPatternImplementation
3
3
  module Concerns
4
4
  module Transactions
5
5
  include Concern
@@ -0,0 +1,38 @@
1
+ module Foobara
2
+ # We distinguish between "Foobara Command" and the "command pattern".
3
+ #
4
+ # A "Foobara Command" encapsulates a high-level business operation and serves as the public interface to its domain.
5
+ #
6
+ # The "command pattern" encapsulates an operation behind an interface that supports .new(inputs), #run which returns
7
+ # an outcome which implements #success?, #result, and #errors.
8
+ #
9
+ # All "Foobara Command"s implement the "command pattern" but not all implementations of the "command pattern"
10
+ # are "Foobara Command"s. An example is DomainMappers. They happen to use the "command pattern" since it is a good
11
+ # fit but has nothing to do with a public interface high-level business operation encapsulation like a
12
+ # "Foobara Command" does.
13
+ module CommandPatternImplementation
14
+ include Concern
15
+
16
+ include TruncatedInspect
17
+
18
+ include CommandPatternImplementation::Concerns::Description
19
+ include CommandPatternImplementation::Concerns::Namespace
20
+
21
+ include CommandPatternImplementation::Concerns::InputsType
22
+ include CommandPatternImplementation::Concerns::ErrorsType
23
+ include CommandPatternImplementation::Concerns::ResultType
24
+
25
+ include CommandPatternImplementation::Concerns::Inputs
26
+ include CommandPatternImplementation::Concerns::Errors
27
+ include CommandPatternImplementation::Concerns::Result
28
+
29
+ include CommandPatternImplementation::Concerns::Runtime
30
+ include CommandPatternImplementation::Concerns::Callbacks
31
+ include CommandPatternImplementation::Concerns::StateMachine
32
+ include CommandPatternImplementation::Concerns::Transactions
33
+ include CommandPatternImplementation::Concerns::Entities
34
+ include CommandPatternImplementation::Concerns::Subcommands
35
+ include CommandPatternImplementation::Concerns::DomainMappers
36
+ include CommandPatternImplementation::Concerns::Reflection
37
+ end
38
+ end
@@ -1,7 +1,7 @@
1
1
  module Foobara
2
- # TODO: would be nice to inherit from something other than Command. Can we hoist a bunch of common behavior up
3
- # out of Command into some other class maybe called Service or Runnable or something?
4
- class DomainMapper < Foobara::Command
2
+ class DomainMapper
3
+ include CommandPatternImplementation
4
+
5
5
  class << self
6
6
  def map(value)
7
7
  new(from: value).run
@@ -0,0 +1,9 @@
1
+ module Foobara
2
+ module Enumerated
3
+ class << self
4
+ def make_module(...)
5
+ Values.new(...).make_module
6
+ end
7
+ end
8
+ end
9
+ end
@@ -116,6 +116,27 @@ module Foobara
116
116
  def respond_to_missing?(name, _include_private = false)
117
117
  @symbol_map.key?(name)
118
118
  end
119
+
120
+ def value?(value)
121
+ @symbol_map.values.include?(value.to_sym)
122
+ end
123
+
124
+ def make_module
125
+ mod = Module.new
126
+ enumerated = self
127
+
128
+ %i[all all_names all_values].each do |method_name|
129
+ mod.singleton_class.define_method method_name do |*args, **opts, &block|
130
+ enumerated.send(method_name, *args, **opts, &block)
131
+ end
132
+ end
133
+
134
+ @symbol_map.each_pair do |name, value|
135
+ mod.const_set(name, value)
136
+ end
137
+
138
+ mod
139
+ end
119
140
  end
120
141
  end
121
142
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.56
4
+ version: 0.0.58
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-17 00:00:00.000000000 Z
10
+ date: 2025-02-20 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bigdecimal
@@ -131,22 +131,24 @@ files:
131
131
  - projects/callback/src/set.rb
132
132
  - projects/command/lib/foobara/command.rb
133
133
  - projects/command/src/command.rb
134
- - projects/command/src/concerns/callbacks.rb
135
- - projects/command/src/concerns/description.rb
136
- - projects/command/src/concerns/domain_mappers.rb
137
- - projects/command/src/concerns/entities.rb
138
- - projects/command/src/concerns/errors.rb
139
- - projects/command/src/concerns/errors_type.rb
140
- - projects/command/src/concerns/inputs.rb
141
- - projects/command/src/concerns/inputs_type.rb
142
- - projects/command/src/concerns/namespace.rb
143
- - projects/command/src/concerns/reflection.rb
144
- - projects/command/src/concerns/result.rb
145
- - projects/command/src/concerns/result_type.rb
146
- - projects/command/src/concerns/runtime.rb
147
- - projects/command/src/concerns/state_machine.rb
148
- - projects/command/src/concerns/subcommands.rb
149
- - projects/command/src/concerns/transactions.rb
134
+ - projects/command/src/command/concerns/shortcut_for_run.rb
135
+ - projects/command/src/command_pattern_implementation.rb
136
+ - projects/command/src/command_pattern_implementation/concerns/callbacks.rb
137
+ - projects/command/src/command_pattern_implementation/concerns/description.rb
138
+ - projects/command/src/command_pattern_implementation/concerns/domain_mappers.rb
139
+ - projects/command/src/command_pattern_implementation/concerns/entities.rb
140
+ - projects/command/src/command_pattern_implementation/concerns/errors.rb
141
+ - projects/command/src/command_pattern_implementation/concerns/errors_type.rb
142
+ - projects/command/src/command_pattern_implementation/concerns/inputs.rb
143
+ - projects/command/src/command_pattern_implementation/concerns/inputs_type.rb
144
+ - projects/command/src/command_pattern_implementation/concerns/namespace.rb
145
+ - projects/command/src/command_pattern_implementation/concerns/reflection.rb
146
+ - projects/command/src/command_pattern_implementation/concerns/result.rb
147
+ - projects/command/src/command_pattern_implementation/concerns/result_type.rb
148
+ - projects/command/src/command_pattern_implementation/concerns/runtime.rb
149
+ - projects/command/src/command_pattern_implementation/concerns/state_machine.rb
150
+ - projects/command/src/command_pattern_implementation/concerns/subcommands.rb
151
+ - projects/command/src/command_pattern_implementation/concerns/transactions.rb
150
152
  - projects/command/src/state_machine.rb
151
153
  - projects/command/src/transformed_command.rb
152
154
  - projects/command_connectors/lib/foobara/command_connectors.rb
@@ -249,6 +251,7 @@ files:
249
251
  - projects/entity/src/not_found_error.rb
250
252
  - projects/enumerated/lib/foobara/enumerated.rb
251
253
  - projects/enumerated/src/accessors.rb
254
+ - projects/enumerated/src/enumerated.rb
252
255
  - projects/enumerated/src/values.rb
253
256
  - projects/foobara/lib/foobara.rb
254
257
  - projects/foobara/lib/foobara/all.rb