dsl_companion 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/dsl_companion.rb +0 -1
- data/lib/dsl_companion/features/basic.rb +19 -2
- data/lib/dsl_companion/version.rb +1 -1
- data/spec/interpreter_spec.rb +25 -0
- metadata +1 -2
- data/lib/dsl_companion/helpers/context_helper.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a771786f0b6091fa9cf21cc3c3f0c938c9749d33
|
4
|
+
data.tar.gz: 9ece4271be1ef921319f8caaff12a441f2349695
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47b386ac4117767be63f3c311acbb809161d1f17d6703ff9dcec086ca22deb8d91a20d92a54c8369e8808a31b5794fc5dd23938a9b3db15bf84e64fed9354741
|
7
|
+
data.tar.gz: c407a5193ffa37f8979367ba99b26f91bb9ed7d3ecfbb421c6275c957ba3fafd0125d81e2f02517c8f0511d54f58ea881d74deac85b941cf225f756915a977cd
|
data/README.md
CHANGED
data/lib/dsl_companion.rb
CHANGED
@@ -9,14 +9,30 @@ module DSLCompanion
|
|
9
9
|
# generic syntax of define(:something, *args)
|
10
10
|
# @param [Object[]] args
|
11
11
|
# @param [Proc] block
|
12
|
-
# @return [Anything returned by
|
12
|
+
# @return [Anything returned by the method]
|
13
13
|
def define *args, &block
|
14
14
|
extra = args.shift
|
15
15
|
method_name = "define_#{extra}"
|
16
16
|
if respond_to? method_name.to_sym
|
17
17
|
block_given? ? self.send(method_name, *args, &block) : self.send(method_name, *args)
|
18
18
|
else
|
19
|
-
block_given? ? method_missing(method_name.to_sym, *args, &
|
19
|
+
block_given? ? method_missing(method_name.to_sym, *args, &block) : method_missing(method_name.to_sym, *args)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute_within_context(context=@context, &block)
|
24
|
+
# Execute the block if any
|
25
|
+
if block_given?
|
26
|
+
last_saved_context = @context
|
27
|
+
@context = context
|
28
|
+
begin
|
29
|
+
logger "Switching to context: #{@context} (from #{last_saved_context})"
|
30
|
+
@context.send :instance_variable_set, '@interpreter', @interpreter
|
31
|
+
@context.instance_eval(&block)
|
32
|
+
ensure
|
33
|
+
@context = last_saved_context
|
34
|
+
logger "Back to context: #{@context}"
|
35
|
+
end
|
20
36
|
end
|
21
37
|
end
|
22
38
|
|
@@ -37,6 +53,7 @@ module DSLCompanion
|
|
37
53
|
end
|
38
54
|
|
39
55
|
|
56
|
+
|
40
57
|
end
|
41
58
|
|
42
59
|
end
|
data/spec/interpreter_spec.rb
CHANGED
@@ -34,6 +34,31 @@ describe DSLCompanion::Interpreter do
|
|
34
34
|
expect(interpreter.respond_to? :interpreter?).to be_truthy
|
35
35
|
end
|
36
36
|
|
37
|
+
it 'should give the same result for define_<something>(*args) and define(:something, *args)' do
|
38
|
+
|
39
|
+
module ExtraFeatureModule
|
40
|
+
def define_stuff stuff_name, value
|
41
|
+
interpreter.inject_variable stuff_name, value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
interpreter = subject.new :strict
|
45
|
+
interpreter.add_feature ExtraFeatureModule
|
46
|
+
a,b = nil,nil
|
47
|
+
|
48
|
+
interpreter.run do
|
49
|
+
define_stuff :foo, 'Foo Bar'
|
50
|
+
a = foo
|
51
|
+
define :stuff, :bar, 'Foo Bar'
|
52
|
+
b = bar
|
53
|
+
end
|
54
|
+
|
55
|
+
expect(a == b).to be_truthy
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
37
62
|
it 'should be able to inject new variables in interpreter' do
|
38
63
|
|
39
64
|
module ExtraFeatureModule
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dsl_companion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Laurent B.
|
@@ -69,7 +69,6 @@ files:
|
|
69
69
|
- lib/dsl_companion.rb
|
70
70
|
- lib/dsl_companion/features/basic.rb
|
71
71
|
- lib/dsl_companion/helpers/active_record.rb
|
72
|
-
- lib/dsl_companion/helpers/context_helper.rb
|
73
72
|
- lib/dsl_companion/interpreter.rb
|
74
73
|
- lib/dsl_companion/meta_helper.rb
|
75
74
|
- lib/dsl_companion/version.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module DSLCompanion
|
2
|
-
|
3
|
-
module ContextHelper
|
4
|
-
|
5
|
-
def execute_within_context(context=@context, &block)
|
6
|
-
# Execute the block if any
|
7
|
-
if block_given?
|
8
|
-
last_saved_context = @context
|
9
|
-
@context = context
|
10
|
-
begin
|
11
|
-
# puts ">>>> Switching to context: #{@context} (from #{last_saved_context})"
|
12
|
-
@context.send :instance_variable_set, '@interpreter', @interpreter
|
13
|
-
@context.instance_eval(&block)
|
14
|
-
ensure
|
15
|
-
@context = last_saved_context
|
16
|
-
# puts "<<<< Back to context: #{@context}"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|