foobara 0.0.32 → 0.0.33

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c792e842511e06c18b7104b2d417b4ba93275266f94257207176f9c6eed4265f
4
- data.tar.gz: 4ce865c5dd74d839710bdb4a766e47e645ab07e4a484cf32ede9ed839e3d75a9
3
+ metadata.gz: e0fa3ca995bce92b12bb618474cd34f96c6620c110cc73e02cd4b66f2a572fab
4
+ data.tar.gz: e1155dc5793d694c039fc0e7ab5f4d4112c60b8bc3be6eb24d68cb4d277fb2ae
5
5
  SHA512:
6
- metadata.gz: 5d0d59e0a8bd59703873c845a06a9afb756c8326700f8858eeeff476cde1ad3b20386037008211db6878727eb6585d9d7cd4b8e4892e784d65028c9d19060db1
7
- data.tar.gz: a45f976f9a90d78a1f6e4ae2077da4846565a89c2092a0cf7da92ab068dda6ef25b2ec1f8700824ff29c3dc58b53f4ebc0bdf35984b865c6cb91c63136327204
6
+ metadata.gz: 102f6110c8cbef54564e34309da3c61a7d4f97fe67dd8def94b15523b466979c12f8bffe1e7343b08fde95269645d40a6f140cf117514bab92da406fd2a8edff
7
+ data.tar.gz: 99dc5ad01438bb404ea4da952423d3e414d2526647aa682c10bb3333c0833904de27b29eed1b15c22741d72317103875eed001a56eb2aa8ffd72c7230f30c459
data/CHANGELOG.md CHANGED
@@ -1,7 +1,8 @@
1
- ## [0.0.32] - 2024-12-09
1
+ ## [0.0.33] - 2024-12-09
2
2
 
3
3
  - Introduce a DetachedEntity concept that sits between Model and Entity
4
4
  - Add a detached_to_primary_key flag to EntitiesToPrimaryKeysSerializer
5
+ - Create command-named convenience functions for .run! calls
5
6
 
6
7
  ## [0.0.30] - 2024-12-07
7
8
 
@@ -4,6 +4,30 @@ module Foobara
4
4
  def install!
5
5
  Namespace.global.foobara_add_category_for_subclass_of(:command, self)
6
6
  end
7
+
8
+ def reset_all
9
+ to_delete = []
10
+
11
+ all.each do |command_class|
12
+ if command_class.name.include?("::")
13
+ parent_name = Util.parent_module_name_for(command_class.name)
14
+
15
+ if Object.const_defined?(parent_name)
16
+ command_class.undefine_command_named_function
17
+ else
18
+ to_delete << command_class
19
+ end
20
+ else
21
+ command_class.undefine_command_named_function
22
+ end
23
+ end
24
+
25
+ to_delete.each do |command_class|
26
+ all.delete(command_class)
27
+ end
28
+
29
+ super
30
+ end
7
31
  end
8
32
  end
9
33
  end
@@ -32,5 +32,6 @@ module Foobara
32
32
 
33
33
  Command.after_subclass_defined do |subclass|
34
34
  Command.all << subclass
35
+ subclass.define_command_named_function
35
36
  end
36
37
  end
@@ -15,6 +15,44 @@ 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
18
56
  end
19
57
 
20
58
  attr_reader :outcome, :exception
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.32
4
+ version: 0.0.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi