dsl_compose 2.15.4 → 2.15.5

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: 0c630022da7a35c7bb15fcb5847b3036dc21e45b0afd950edb4fa6bb205147f4
4
- data.tar.gz: ed8a49a2b1ec77a4a741a1eeaddd4fb52019ad307cf96c2d8f531f1df4d24a7f
3
+ metadata.gz: e0750c158e424591df6b08e2ac3786b689116b5850152b6f6fe51fc39092895a
4
+ data.tar.gz: 7e818d88dd0dde898b80faa4eb24f18eaa6ca8bd64a4c83fc974621ccee71e3e
5
5
  SHA512:
6
- metadata.gz: 96aa671032ce71ce1d7639ab8fbf25d7e3f17d58f3b822a1601b6af99808502083d284b4f6cbea7541dc271a8d1dcf0e005f98d066852d86a9b88d3e194125cb
7
- data.tar.gz: 5d17dfa43b30dae88aebdff5bc192d083fa3cf668e896a9fb71c314304b9b8320a4dfb6444b1055b8fde0d0da45d0285d38982ae7cbcf006d93f1c634d86ca38
6
+ metadata.gz: a374a44e85a232cc6681c98034a1196cc7ccc077689a3f9bb75354aa54e0e02be8758a527de68944af95c81f04157b07df4bcaccab20877cfee48f2164eddad2
7
+ data.tar.gz: 73fd1c43e1677b42c2389a4919e0ced10feda5e35ca564d1d025376fbb357282f5d8bf7411980d3d9d744c46b6d50cbc2fa370314ad0c4de58093eec569fc53d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.15.5](https://github.com/craigulliott/dsl_compose/compare/v2.15.4...v2.15.5) (2023-10-06)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * added a first_use_only option to the parser so that only the most recent execution of a DSL will be used ([717293d](https://github.com/craigulliott/dsl_compose/commit/717293d906a183d8a13ffa1c4ae47e901de428a0))
9
+ * specs and fixes for `first_use_only` option on parser ([a7dc087](https://github.com/craigulliott/dsl_compose/commit/a7dc0878ffef9a104c25d4f43d5796f939cb7567))
10
+
3
11
  ## [2.15.4](https://github.com/craigulliott/dsl_compose/compare/v2.15.3...v2.15.4) (2023-10-04)
4
12
 
5
13
 
@@ -66,8 +66,15 @@ module DSLCompose
66
66
 
67
67
  # Returns an array of all executions for a given name and class. This includes
68
68
  # any ancestors of the provided class
69
- def class_dsl_executions klass, dsl_name, on_current_class, on_ancestor_class
70
- @executions.filter { |e| e.dsl.name == dsl_name && ((on_current_class && e.klass == klass) || (on_ancestor_class && klass < e.klass)) }
69
+ def class_dsl_executions klass, dsl_name, on_current_class, on_ancestor_class, first_use_only
70
+ filtered_executions = @executions.filter { |e| e.dsl.name == dsl_name && ((on_current_class && e.klass == klass) || (on_ancestor_class && klass < e.klass)) }
71
+ # Because the classes were evaluated in order, we can just return the
72
+ # last execution
73
+ if first_use_only && filtered_executions.length > 0
74
+ [filtered_executions.last]
75
+ else
76
+ filtered_executions
77
+ end
71
78
  end
72
79
 
73
80
  # returns the most recent, closest single execution of a dsl with the
@@ -83,7 +90,7 @@ module DSLCompose
83
90
  # note that this method does not need to do any special sorting, the required
84
91
  # order for getting the most recent execution is already guaranteed because
85
92
  # parent classes in ruby always have to be evaluated before their descendants
86
- class_dsl_executions(klass, dsl_name, true, true).last
93
+ class_dsl_executions(klass, dsl_name, true, true, false).last
87
94
  end
88
95
 
89
96
  # removes all executions from the interpreter, and any parser_usage_notes
@@ -20,7 +20,7 @@ module DSLCompose
20
20
  # of the provided name is used by the child class.
21
21
  #
22
22
  # base_class and child_class are set from the ForChildrenOfParser
23
- def initialize base_class, child_class, dsl_names, on_current_class, on_ancestor_class, &block
23
+ def initialize base_class, child_class, dsl_names, on_current_class, on_ancestor_class, first_use_only, &block
24
24
  @base_class = base_class
25
25
  @child_class = child_class
26
26
  @dsl_names = dsl_names
@@ -62,7 +62,7 @@ module DSLCompose
62
62
  dsl_names.each do |dsl_name|
63
63
  # a dsl can be execued multiple times on a class, so we find all of the executions
64
64
  # here and then yield the block once for each execution
65
- base_class.dsls.class_dsl_executions(child_class, dsl_name, on_current_class, on_ancestor_class).each do |dsl_execution|
65
+ base_class.dsls.class_dsl_executions(child_class, dsl_name, on_current_class, on_ancestor_class, first_use_only).each do |dsl_execution|
66
66
  # we only provide the requested arguments to the block, this allows
67
67
  # us to use keyword arguments to force a naming convention on these arguments
68
68
  # and to validate their use
@@ -90,36 +90,42 @@ module DSLCompose
90
90
  # end
91
91
  #
92
92
  # If `on_current_class` is true, then the block will be yielded to for each DSL
93
- # which was used directly on the current class. If `oncurrent_class` is false,
94
- # then the block will not be yielded to for any DSL which was used directly on.
93
+ # which was used directly on the current class. If `on_current_class` is false,
94
+ # then the block will not be yielded to for any DSL which was used directly on it.
95
95
  # If `on_ancestor_class` is true, then the block will be yielded to for each DSL
96
96
  # which was used on any class in the current classes ancestry. If `on_ancestor_class`
97
97
  # is false, then the block will not be yielded to for any DSL which was used on
98
98
  # any class in the current classes ancestry.
99
- def for_dsl dsl_names, on_current_class: true, on_ancestor_class: false, &block
99
+ #
100
+ # If `first_use_only` is true, then this block will only yeild once for each subject class
101
+ # which directly uses or inherits use of the provided DSL. The DSL execution which occurs
102
+ # first in the class will be selected, and if the class does not use the DSL then each of
103
+ # the classes ancestors will be tested until an execution is found (only the current class
104
+ # will be tested if skip_inherited_dsls has been set to true).
105
+ def for_dsl dsl_names, on_current_class: true, on_ancestor_class: false, first_use_only: false, &block
100
106
  child_class = @child_class
101
107
 
102
108
  unless child_class
103
109
  raise NoChildClassError, "No child_class was found, please call this method from within a `for_children_of` block"
104
110
  end
105
111
 
106
- ForDSLParser.new(@base_class, child_class, dsl_names, on_current_class, on_ancestor_class, &block)
112
+ ForDSLParser.new(@base_class, child_class, dsl_names, on_current_class, on_ancestor_class, first_use_only, &block)
107
113
  end
108
114
 
109
115
  # this is a wrapper for the `for_dsl` method, but it provides a value of true
110
116
  # for the `on_ancestor_class` argument and a value of false for the `on_current_class`
111
117
  # argument. This will cause the parser to only yeild for dsls which were used on
112
118
  # a class which is in the current classes ancestry, but not on the current class
113
- def for_inherited_dsl dsl_names, &block
114
- for_dsl dsl_names, on_current_class: false, on_ancestor_class: true, &block
119
+ def for_inherited_dsl dsl_names, first_use_only: false, &block
120
+ for_dsl dsl_names, on_current_class: false, on_ancestor_class: true, first_use_only: first_use_only, &block
115
121
  end
116
122
 
117
123
  # this is a wrapper for the `for_dsl` method, but it provides a value of true
118
124
  # for the `on_ancestor_class` argument and a value of true for the `on_current_class`
119
125
  # argument. This will cause the parser to yeild for dsls which were used on either
120
126
  # the current class or any class in its ancestry
121
- def for_dsl_or_inherited_dsl dsl_names, &block
122
- for_dsl dsl_names, on_current_class: true, on_ancestor_class: true, &block
127
+ def for_dsl_or_inherited_dsl dsl_names, first_use_only: false, &block
128
+ for_dsl dsl_names, on_current_class: true, on_ancestor_class: true, first_use_only: first_use_only, &block
123
129
  end
124
130
 
125
131
  # takes a description of what this parser does and stores it against the DSL definition
@@ -89,7 +89,7 @@ module DSLCompose
89
89
  # Returns an array of ExecutionReaders to represent each time the DSL was used
90
90
  # on the provided class.
91
91
  def executions
92
- @dsl_defining_class.dsls.class_dsl_executions(@klass, @dsl_name, true, false).map do |execution|
92
+ @dsl_defining_class.dsls.class_dsl_executions(@klass, @dsl_name, true, false, false).map do |execution|
93
93
  ExecutionReader.new execution
94
94
  end
95
95
  end
@@ -100,7 +100,7 @@ module DSLCompose
100
100
  # earliest ancestor first and if the DSL was used more than once on a class then
101
101
  # the order they were used.
102
102
  def ancestor_executions
103
- @dsl_defining_class.dsls.class_dsl_executions(@klass, @dsl_name, false, true).map do |execution|
103
+ @dsl_defining_class.dsls.class_dsl_executions(@klass, @dsl_name, false, true, false).map do |execution|
104
104
  ExecutionReader.new execution
105
105
  end
106
106
  end
@@ -110,7 +110,7 @@ module DSLCompose
110
110
  # be returned in the order they were executed, which is the earliest ancestor first
111
111
  # and if the DSL was used more than once on a class then the order they were used.
112
112
  def all_executions
113
- @dsl_defining_class.dsls.class_dsl_executions(@klass, @dsl_name, true, true).map do |execution|
113
+ @dsl_defining_class.dsls.class_dsl_executions(@klass, @dsl_name, true, true, false).map do |execution|
114
114
  ExecutionReader.new execution
115
115
  end
116
116
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DSLCompose
4
- VERSION = "2.15.4"
4
+ VERSION = "2.15.5"
5
5
  end
@@ -8,7 +8,7 @@ module DSLCompose
8
8
  @dsl_names: Array[Symbol]
9
9
  @dsl_execution: Interpreter::Execution
10
10
 
11
- def initialize: (singleton(Object) base_class, singleton(Object) child_class, Array[Symbol] dsl_names, bool on_current_class, bool on_ancestor_class) -> void
11
+ def initialize: (singleton(Object) base_class, singleton(Object) child_class, Array[Symbol] dsl_names, bool on_current_class, bool on_ancestor_class, bool first_use_only) -> void
12
12
 
13
13
  # overriding this method because steep doesn't
14
14
  # correctly infer that a block is being passed to this method
@@ -14,10 +14,12 @@ module DSLCompose
14
14
  ) -> void
15
15
 
16
16
  private
17
- def for_dsl: (Array[Symbol] dsl_names, ?on_current_class: bool, ?on_ancestor_class: bool) -> untyped
17
+ def for_dsl: (Array[Symbol] dsl_names, ?on_current_class: bool, ?on_ancestor_class: bool, ?first_use_only: bool) -> untyped
18
+ def for_inherited_dsl: (Array[Symbol] dsl_names, ?first_use_only: bool) -> untyped
19
+ def for_dsl_or_inherited_dsl: (Array[Symbol] dsl_names, ?first_use_only: bool) -> untyped
18
20
 
19
21
  class AllBlockParametersMustBeKeywordParametersError < StandardError
20
- end
22
+ end
21
23
 
22
24
  class ClassDoesNotUseDSLComposeError < StandardError
23
25
  end
@@ -26,7 +28,7 @@ module DSLCompose
26
28
  end
27
29
 
28
30
  class NoChildClassError < StandardError
29
- end
31
+ end
30
32
  end
31
33
  end
32
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsl_compose
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.4
4
+ version: 2.15.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Ulliott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-04 00:00:00.000000000 Z
11
+ date: 2023-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: class_spec_helper