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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3fd835850cec2614e0af45d5ef719662d26b7939
4
- data.tar.gz: a1fc45e56860006570ffce9ff1feda47ed3db132
3
+ metadata.gz: a771786f0b6091fa9cf21cc3c3f0c938c9749d33
4
+ data.tar.gz: 9ece4271be1ef921319f8caaff12a441f2349695
5
5
  SHA512:
6
- metadata.gz: f37505af4d96812117db3e69c250e0fbebbf3c8e2bcc0d5fd1d9481579e6e2bd07bf8f20cecea0f80b7225416ba8ca4db0f6829ea5df3c4fa70dc8dba6f3e682
7
- data.tar.gz: 4664de8232f5e4801c1cdf792964a0ef5927fddc125c49dc47ca71f135f7573ba0cc8fda2b6dcf91c04e3d86985e4afb6ce90bd71803e380044af04f201e3bfb
6
+ metadata.gz: 47b386ac4117767be63f3c311acbb809161d1f17d6703ff9dcec086ca22deb8d91a20d92a54c8369e8808a31b5794fc5dd23938a9b3db15bf84e64fed9354741
7
+ data.tar.gz: c407a5193ffa37f8979367ba99b26f91bb9ed7d3ecfbb421c6275c957ba3fafd0125d81e2f02517c8f0511d54f58ea881d74deac85b941cf225f756915a977cd
data/README.md CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  TODO: Write a gem description
8
8
 
9
+ Still not ready for deployment. stay tuned.
10
+
9
11
  ## Installation
10
12
 
11
13
  Add this line to your application's Gemfile:
data/lib/dsl_companion.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'dsl_companion/version'
2
2
  require 'dsl_companion/meta_helper'
3
- require 'dsl_companion/helpers/context_helper'
4
3
  require 'dsl_companion/helpers/active_record'
5
4
 
6
5
  # Preloaded features
@@ -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 th emethod]
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, & block) : 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
@@ -1,3 +1,3 @@
1
1
  module DSLCompanion
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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.0
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