dslblend 0.0.1

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 (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/dslblend/base.rb +34 -0
  3. data/lib/dslblend.rb +3 -0
  4. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0f8db1ece35e0f96e0a9355492e873a2fdb0ea98062145c5ce2d2f32392c14f7
4
+ data.tar.gz: e778123e58e4f9c74db96875343171bb0eab4a3992d506684efe61700161b324
5
+ SHA512:
6
+ metadata.gz: 381149a2035a255f142467e2a3644eb285dc908cd48678611f158e513f82bb128045621a5d7a86daa4b9296246f306693274fe5eb96b2d37be583b24b9c728f4
7
+ data.tar.gz: 559c120d3290496ae63bbafa66d34825ddec9fba46d524f63f9a949cf242e6379c19697c3e7a1f523de7b42d679b5a10fa92c5d84b81c94dff2e4ea77de74b0e
@@ -0,0 +1,34 @@
1
+ module Dslblend
2
+ # Make your DSL class inherit from this. It will be the first provider to receive method calls.
3
+ class Base
4
+ def initialize(*additional_providers, main_provider: nil)
5
+ @_main_provider = main_provider
6
+ @_additional_providers = additional_providers
7
+ end
8
+
9
+ def evaluate(&block)
10
+ @_main_provider ||= eval 'self', block.binding, __FILE__, __LINE__
11
+ @_main_provider.instance_variables.each do |instance_variable|
12
+ next if instance_variable.to_s.start_with?('@_')
13
+ instance_variable_set(instance_variable, @_main_provider.instance_variable_get(instance_variable))
14
+ end
15
+ instance_eval(&block)
16
+ end
17
+
18
+ def method_missing(method, *args, &block)
19
+ @_additional_providers.each do |additional_provider|
20
+ if additional_provider.respond_to?(method)
21
+ return additional_provider.send(method, *args, &block)
22
+ end
23
+ end
24
+ @_main_provider.send method, *args, &block
25
+ end
26
+
27
+ def respond_to_missing?(method, include_all)
28
+ return true if super
29
+ @_additional_providers.each { |additional_provider| return true if additional_provider.respond_to?(method, include_all) }
30
+ return true if @_main_provider.respond_to?(method, include_all)
31
+ return false
32
+ end
33
+ end
34
+ end
data/lib/dslblend.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Dslblend; end
2
+
3
+ require 'dslblend/base'
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dslblend
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sandro Kalbermatter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-08-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Please refer to https://github.com/kalsan/dslblend/blob/main/README.md
14
+ email: kalsan@users.noreply.github.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/dslblend.rb
20
+ - lib/dslblend/base.rb
21
+ homepage: https://github.com/kalsan/dslblend
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.5.1
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.2.33
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: This gem allows to build an instance_eval based DSL without losing access
44
+ to the object calling the block.
45
+ test_files: []