dsl_compose 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +300 -3
- data/lib/dsl_compose/composer.rb +74 -0
- data/lib/dsl_compose/dsl/dsl_method/argument/equal_to_validation.rb +25 -0
- data/lib/dsl_compose/dsl/dsl_method/argument/format_validation.rb +25 -0
- data/lib/dsl_compose/dsl/dsl_method/argument/greater_than_or_equal_to_validation.rb +35 -0
- data/lib/dsl_compose/dsl/dsl_method/argument/greater_than_validation.rb +35 -0
- data/lib/dsl_compose/dsl/dsl_method/argument/in_validation.rb +35 -0
- data/lib/dsl_compose/dsl/dsl_method/argument/interpreter.rb +86 -0
- data/lib/dsl_compose/dsl/dsl_method/argument/length_validation.rb +42 -0
- data/lib/dsl_compose/dsl/dsl_method/argument/less_than_or_equal_to_validation.rb +35 -0
- data/lib/dsl_compose/dsl/dsl_method/argument/less_than_validation.rb +35 -0
- data/lib/dsl_compose/dsl/dsl_method/argument/not_in_validation.rb +35 -0
- data/lib/dsl_compose/dsl/dsl_method/argument.rb +299 -0
- data/lib/dsl_compose/dsl/dsl_method/interpreter.rb +57 -0
- data/lib/dsl_compose/dsl/dsl_method.rb +213 -0
- data/lib/dsl_compose/dsl/interpreter.rb +52 -0
- data/lib/dsl_compose/dsl.rb +148 -0
- data/lib/dsl_compose/dsls.rb +80 -0
- data/lib/dsl_compose/interpreter/execution/method_calls/method_call.rb +155 -0
- data/lib/dsl_compose/interpreter/execution/method_calls.rb +25 -0
- data/lib/dsl_compose/interpreter/execution.rb +60 -0
- data/lib/dsl_compose/interpreter.rb +43 -0
- data/lib/dsl_compose/version.rb +2 -2
- data/lib/dsl_compose.rb +32 -4
- metadata +24 -3
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DSLCompose
|
4
|
+
class Interpreter
|
5
|
+
class Execution
|
6
|
+
class MethodIsUniqueError < StandardError
|
7
|
+
def message
|
8
|
+
"This method is unique and can only be called once within this DSL"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class RequiredMethodNotCalledError < StandardError
|
13
|
+
def message
|
14
|
+
"This method is required, but was not called within this DSL"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :dsl
|
19
|
+
attr_reader :method_calls
|
20
|
+
|
21
|
+
# execute/process a dynamically defined DSL
|
22
|
+
def initialize dsl, &block
|
23
|
+
@dsl = dsl
|
24
|
+
@method_calls = MethodCalls.new
|
25
|
+
|
26
|
+
# dynamically process the DSL by calling the provided block
|
27
|
+
# all methods executions will be caught and processed by the method_missing method below
|
28
|
+
if block
|
29
|
+
instance_eval(&block)
|
30
|
+
end
|
31
|
+
|
32
|
+
# assert that all required methods have been called at least once
|
33
|
+
dsl.required_dsl_methods.each do |dsl_method|
|
34
|
+
unless @method_calls.method_called? dsl_method.name
|
35
|
+
raise RequiredMethodNotCalledError
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
# catch and process any method calls within the DSL block
|
43
|
+
def method_missing method_name, *args, &block
|
44
|
+
# if the method does not exist, then this will raise a MethodDoesNotExistError
|
45
|
+
dsl_method = @dsl.dsl_method method_name
|
46
|
+
|
47
|
+
# if the method is unique, then it can only be called once per DSL
|
48
|
+
if dsl_method.unique? && @method_calls.method_called?(method_name)
|
49
|
+
raise MethodIsUniqueError
|
50
|
+
end
|
51
|
+
|
52
|
+
@method_calls.add_method_call dsl_method, *args, &block
|
53
|
+
end
|
54
|
+
|
55
|
+
def respond_to_missing?(method_name, *args)
|
56
|
+
@dsl.has_dsl_method? method_name
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DSLCompose
|
4
|
+
# The class is reponsible for parsing and executing a dynamic DSL (dynamic DSLs are
|
5
|
+
# created using the DSLCompose::DSL class).
|
6
|
+
class Interpreter
|
7
|
+
# A dynamic DSL can be used multiple times on the same class, each time the DSL is used
|
8
|
+
# a corresponding execution will be created. The execution contains the resulting configuration
|
9
|
+
# from that particular use of the DSL.
|
10
|
+
attr_reader :executions
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@executions = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
# Execute/process a dynamically defined DSL on a class.
|
17
|
+
# `klass` is the class in which the DSL is being used, not
|
18
|
+
# the class in which the DSL was defined.
|
19
|
+
def execute_dsl klass, dsl, &block
|
20
|
+
@executions[klass] ||= []
|
21
|
+
execution = Execution.new(dsl, &block)
|
22
|
+
@executions[klass] << execution
|
23
|
+
execution
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns an array of all executions for a given class.
|
27
|
+
def class_executions klass
|
28
|
+
@executions[klass] || []
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_h klass
|
32
|
+
h = {}
|
33
|
+
class_executions(klass).each do |execution|
|
34
|
+
h[execution.dsl.name] ||= {}
|
35
|
+
execution.method_calls.method_calls.each do |method_call|
|
36
|
+
h[execution.dsl.name][method_call.method_name] ||= []
|
37
|
+
h[execution.dsl.name][method_call.method_name] << method_call.to_h
|
38
|
+
end
|
39
|
+
end
|
40
|
+
h
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/dsl_compose/version.rb
CHANGED
data/lib/dsl_compose.rb
CHANGED
@@ -1,8 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "dsl_compose/version"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
require "dsl_compose/dsl/dsl_method/argument/equal_to_validation"
|
6
|
+
require "dsl_compose/dsl/dsl_method/argument/format_validation"
|
7
|
+
require "dsl_compose/dsl/dsl_method/argument/greater_than_or_equal_to_validation"
|
8
|
+
require "dsl_compose/dsl/dsl_method/argument/greater_than_validation"
|
9
|
+
require "dsl_compose/dsl/dsl_method/argument/in_validation"
|
10
|
+
require "dsl_compose/dsl/dsl_method/argument/length_validation"
|
11
|
+
require "dsl_compose/dsl/dsl_method/argument/less_than_or_equal_to_validation"
|
12
|
+
require "dsl_compose/dsl/dsl_method/argument/less_than_validation"
|
13
|
+
require "dsl_compose/dsl/dsl_method/argument/not_in_validation"
|
14
|
+
|
15
|
+
require "dsl_compose/dsl/dsl_method/argument/interpreter"
|
16
|
+
require "dsl_compose/dsl/dsl_method/argument"
|
17
|
+
require "dsl_compose/dsl/dsl_method/interpreter"
|
18
|
+
require "dsl_compose/dsl/dsl_method"
|
19
|
+
|
20
|
+
require "dsl_compose/dsl/interpreter"
|
21
|
+
|
22
|
+
require "dsl_compose/dsl"
|
23
|
+
|
24
|
+
require "dsl_compose/interpreter/execution/method_calls/method_call"
|
25
|
+
require "dsl_compose/interpreter/execution/method_calls"
|
26
|
+
require "dsl_compose/interpreter/execution"
|
27
|
+
require "dsl_compose/interpreter"
|
28
|
+
|
29
|
+
require "dsl_compose/composer"
|
30
|
+
|
31
|
+
require "dsl_compose/dsls"
|
32
|
+
|
33
|
+
module DSLCompose
|
34
|
+
class Error < StandardError
|
35
|
+
end
|
8
36
|
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: 1.
|
4
|
+
version: 1.1.0
|
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-06-
|
11
|
+
date: 2023-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby gem to add dynamic DSLs to classes. DSLs are added to classes by
|
14
14
|
including the DSLCompose module, and then calling the add_dsl singleton method within
|
@@ -24,6 +24,27 @@ files:
|
|
24
24
|
- LICENSE.txt
|
25
25
|
- README.md
|
26
26
|
- lib/dsl_compose.rb
|
27
|
+
- lib/dsl_compose/composer.rb
|
28
|
+
- lib/dsl_compose/dsl.rb
|
29
|
+
- lib/dsl_compose/dsl/dsl_method.rb
|
30
|
+
- lib/dsl_compose/dsl/dsl_method/argument.rb
|
31
|
+
- lib/dsl_compose/dsl/dsl_method/argument/equal_to_validation.rb
|
32
|
+
- lib/dsl_compose/dsl/dsl_method/argument/format_validation.rb
|
33
|
+
- lib/dsl_compose/dsl/dsl_method/argument/greater_than_or_equal_to_validation.rb
|
34
|
+
- lib/dsl_compose/dsl/dsl_method/argument/greater_than_validation.rb
|
35
|
+
- lib/dsl_compose/dsl/dsl_method/argument/in_validation.rb
|
36
|
+
- lib/dsl_compose/dsl/dsl_method/argument/interpreter.rb
|
37
|
+
- lib/dsl_compose/dsl/dsl_method/argument/length_validation.rb
|
38
|
+
- lib/dsl_compose/dsl/dsl_method/argument/less_than_or_equal_to_validation.rb
|
39
|
+
- lib/dsl_compose/dsl/dsl_method/argument/less_than_validation.rb
|
40
|
+
- lib/dsl_compose/dsl/dsl_method/argument/not_in_validation.rb
|
41
|
+
- lib/dsl_compose/dsl/dsl_method/interpreter.rb
|
42
|
+
- lib/dsl_compose/dsl/interpreter.rb
|
43
|
+
- lib/dsl_compose/dsls.rb
|
44
|
+
- lib/dsl_compose/interpreter.rb
|
45
|
+
- lib/dsl_compose/interpreter/execution.rb
|
46
|
+
- lib/dsl_compose/interpreter/execution/method_calls.rb
|
47
|
+
- lib/dsl_compose/interpreter/execution/method_calls/method_call.rb
|
27
48
|
- lib/dsl_compose/version.rb
|
28
49
|
homepage:
|
29
50
|
licenses:
|
@@ -39,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
60
|
requirements:
|
40
61
|
- - ">="
|
41
62
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
63
|
+
version: 3.0.0
|
43
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
65
|
requirements:
|
45
66
|
- - ">="
|