dsel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +0 -0
  3. data/Gemfile +15 -0
  4. data/LICENSE.md +23 -0
  5. data/README.md +113 -0
  6. data/Rakefile +6 -0
  7. data/dsel.gemspec +22 -0
  8. data/lib/dsel/api/generator.rb +285 -0
  9. data/lib/dsel/api/node.rb +241 -0
  10. data/lib/dsel/api.rb +8 -0
  11. data/lib/dsel/dsl/mixins/environment/ivar_explorer.rb +34 -0
  12. data/lib/dsel/dsl/nodes/api/environment.rb +49 -0
  13. data/lib/dsel/dsl/nodes/api.rb +18 -0
  14. data/lib/dsel/dsl/nodes/api_builder/environment.rb +56 -0
  15. data/lib/dsel/dsl/nodes/api_builder.rb +71 -0
  16. data/lib/dsel/dsl/nodes/base/environment.rb +50 -0
  17. data/lib/dsel/dsl/nodes/base.rb +110 -0
  18. data/lib/dsel/dsl/nodes/direct/environment.rb +14 -0
  19. data/lib/dsel/dsl/nodes/direct.rb +75 -0
  20. data/lib/dsel/dsl/nodes/proxy/environment.rb +41 -0
  21. data/lib/dsel/dsl/nodes/proxy.rb +20 -0
  22. data/lib/dsel/dsl.rb +10 -0
  23. data/lib/dsel/node.rb +42 -0
  24. data/lib/dsel/ruby/object.rb +53 -0
  25. data/lib/dsel/version.rb +3 -0
  26. data/lib/dsel.rb +10 -0
  27. data/spec/dsel/api/generator_spec.rb +402 -0
  28. data/spec/dsel/api/node_spec.rb +328 -0
  29. data/spec/dsel/dsel_spec.rb +63 -0
  30. data/spec/dsel/dsl/nodes/api/environment.rb +208 -0
  31. data/spec/dsel/dsl/nodes/api_builder/environment_spec.rb +91 -0
  32. data/spec/dsel/dsl/nodes/api_builder_spec.rb +148 -0
  33. data/spec/dsel/dsl/nodes/api_spec.rb +15 -0
  34. data/spec/dsel/dsl/nodes/direct/environment_spec.rb +14 -0
  35. data/spec/dsel/dsl/nodes/direct_spec.rb +43 -0
  36. data/spec/dsel/dsl/nodes/proxy/environment_spec.rb +56 -0
  37. data/spec/dsel/dsl/nodes/proxy_spec.rb +11 -0
  38. data/spec/spec_helper.rb +22 -0
  39. data/spec/support/factories/clean_api_spec.rb +6 -0
  40. data/spec/support/fixtures/mock_api.rb +4 -0
  41. data/spec/support/helpers/paths.rb +19 -0
  42. data/spec/support/lib/factory.rb +107 -0
  43. data/spec/support/shared/dsl/nodes/base/environment.rb +104 -0
  44. data/spec/support/shared/dsl/nodes/base.rb +171 -0
  45. data/spec/support/shared/node.rb +70 -0
  46. metadata +108 -0
@@ -0,0 +1,171 @@
1
+ require 'tempfile'
2
+
3
+ shared_examples_for DSeL::DSL::Nodes::Base do
4
+ include_examples DSeL::Node
5
+
6
+ subject { described_class.new( context, options ) }
7
+ let(:options) { {} }
8
+ let(:context) { '2' }
9
+
10
+ let(:other) { described_class.new( other_context, other_options ) }
11
+ let(:other_options) { {} }
12
+ let(:other_context) { '1' }
13
+
14
+ let(:other_dup) { described_class.new( other_context, other_options ) }
15
+
16
+ describe '#run' do
17
+ let(:script) do
18
+ <<RUBY
19
+ _dsel_self
20
+ RUBY
21
+ end
22
+ let(:file) do
23
+ f = Tempfile.new
24
+ f.write script
25
+ f.flush
26
+ f.path
27
+ end
28
+
29
+ it 'preserves the same environment between runs' do
30
+ subject.run{}
31
+
32
+ e = subject.environment
33
+ subject.run{}
34
+
35
+ expect(subject.environment).to be e
36
+ end
37
+
38
+ describe 'script' do
39
+ it 'runs the script within the context' do
40
+ expect(subject.run( file )).to be context
41
+ end
42
+ end
43
+
44
+ describe '&block' do
45
+ it 'runs the block within the context' do
46
+ expect(subject.run { _dsel_self }).to be context
47
+ end
48
+ end
49
+
50
+ context 'if both are given' do
51
+ it 'raises ArgumentError' do
52
+ expect do
53
+ subject.run( file ){}
54
+ end.to raise_error ArgumentError
55
+ end
56
+ end
57
+
58
+ context 'before running' do
59
+ it "sets ##{described_class::Environment::DSEL_NODE_ACCESSOR}" do
60
+ expect(subject.run { _dsel_node }).to be subject
61
+ end
62
+ end
63
+
64
+ context 'after running' do
65
+ it "removes ##{described_class::Environment::DSEL_NODE_ACCESSOR}" do
66
+ subject.run { _dsel_self }
67
+ expect(subject.environment.instance_variable_get(described_class::Environment::DSEL_NODE_IVAR)).to be_nil
68
+ end
69
+ end
70
+ end
71
+
72
+ describe '#shared_variables' do
73
+ let(:other_options) { { parent: subject } }
74
+
75
+ it 'provides shared access to a hash' do
76
+ other.shared_variables[1] = 2
77
+ expect(subject.shared_variables).to eq( 1 => 2 )
78
+
79
+ expect(subject.shared_variables).to be other.shared_variables
80
+ end
81
+ end
82
+
83
+ describe '#nodes' do
84
+ it 'includes self' do
85
+ expect(subject.nodes.values).to eq [subject]
86
+ end
87
+
88
+ context 'when #root?' do
89
+ let(:other_options) { { parent: subject } }
90
+
91
+ it 'provides access to all nodes' do
92
+ other
93
+ expect(subject.nodes.values).to eq [subject, other]
94
+ end
95
+ end
96
+
97
+ context 'when not #root?' do
98
+ let(:other_options) { { parent: subject } }
99
+
100
+ it "delegates to root's #nodes" do
101
+ expect(other.nodes).to be subject.nodes
102
+ end
103
+ end
104
+ end
105
+
106
+ describe '#cache_node' do
107
+ context 'when given a unique node' do
108
+ it 'pushes it to #nodes' do
109
+ expect(subject.nodes.values).to eq [subject]
110
+
111
+ subject.cache_node other
112
+ expect(subject.nodes.values).to eq [subject, other]
113
+ end
114
+
115
+ it 'returns it' do
116
+ expect(subject.cache_node(other )).to be other
117
+ end
118
+ end
119
+
120
+ context 'when given a duplicate node' do
121
+ it 'ignores it' do
122
+ expect(subject.nodes.values).to eq [subject]
123
+
124
+ subject.cache_node other
125
+ subject.cache_node other_dup
126
+
127
+ expect(subject.nodes.values).to eq [subject, other]
128
+ end
129
+
130
+ it 'returns the existing one' do
131
+ subject.cache_node other
132
+ expect(subject.cache_node(other_dup )).to be other
133
+ end
134
+ end
135
+ end
136
+
137
+ describe '#node_for' do
138
+ let(:node) { subject.node_for( other_context ) }
139
+
140
+ context 'when given a unique context' do
141
+ it 'returns a node' do
142
+ expect(node.subject).to be other_context
143
+ end
144
+
145
+ it 'stores it' do
146
+ node
147
+ expect(subject.nodes.values).to eq [subject, node]
148
+ end
149
+ end
150
+
151
+ context 'when given a duplicate context' do
152
+ it 'ignores it' do
153
+ expect(subject.nodes.values).to eq [subject]
154
+
155
+ subject.cache_node other
156
+ node
157
+
158
+ expect(subject.nodes.values).to eq [subject, other]
159
+ end
160
+
161
+ it 'returns the existing one' do
162
+ subject.cache_node other
163
+ expect(node).to be other
164
+ end
165
+
166
+ it 'sets self as #parent' do
167
+ expect(node.parent).to be subject
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,70 @@
1
+ shared_examples_for DSeL::Node do
2
+ subject { described_class.new( context, options ) }
3
+ let(:options) { {} }
4
+ let(:context) { '2' }
5
+
6
+ let(:other) { described_class.new( other_context, other_options ) }
7
+ let(:other_options) { {} }
8
+ let(:other_context) { '1' }
9
+
10
+ describe '#initialize' do
11
+ describe 'subject' do
12
+ it 'sets the DSL subject' do
13
+ expect(subject.subject).to be context
14
+ end
15
+ end
16
+
17
+ describe 'options' do
18
+ describe ':parent' do
19
+ let(:options) { { parent: other } }
20
+
21
+ it 'sets the parent' do
22
+ expect(subject.parent).to be other
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ describe '#root?' do
29
+ context 'when root' do
30
+ let(:other_options) { { parent: subject } }
31
+
32
+ it 'returns true' do
33
+ other
34
+ expect(subject).to be_root
35
+ end
36
+ end
37
+
38
+ context 'when not root' do
39
+ let(:other_options) { { parent: subject } }
40
+
41
+ it 'returns false' do
42
+ expect(other).to_not be_root
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#hash' do
48
+ it 'takes into account .class' do
49
+ h1 = subject.hash
50
+
51
+ expect(subject).to receive(:class).and_return( Object )
52
+
53
+ expect(h1).to_not eq subject.hash
54
+ end
55
+
56
+ it 'takes into account subject#object_id' do
57
+ h1 = subject.hash
58
+
59
+ expect(subject.subject).to receive(:object_id).and_return( 1 )
60
+
61
+ expect(h1).to_not eq subject.hash
62
+ end
63
+ end
64
+
65
+ describe '#_dsel_node' do
66
+ it 'returns self' do
67
+ expect(subject._dsel_node).to be subject
68
+ end
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dsel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tasos Laskos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-01-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: tasos.laskos@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files:
18
+ - README.md
19
+ - LICENSE.md
20
+ - CHANGELOG.md
21
+ files:
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - LICENSE.md
25
+ - README.md
26
+ - Rakefile
27
+ - dsel.gemspec
28
+ - lib/dsel.rb
29
+ - lib/dsel/api.rb
30
+ - lib/dsel/api/generator.rb
31
+ - lib/dsel/api/node.rb
32
+ - lib/dsel/dsl.rb
33
+ - lib/dsel/dsl/mixins/environment/ivar_explorer.rb
34
+ - lib/dsel/dsl/nodes/api.rb
35
+ - lib/dsel/dsl/nodes/api/environment.rb
36
+ - lib/dsel/dsl/nodes/api_builder.rb
37
+ - lib/dsel/dsl/nodes/api_builder/environment.rb
38
+ - lib/dsel/dsl/nodes/base.rb
39
+ - lib/dsel/dsl/nodes/base/environment.rb
40
+ - lib/dsel/dsl/nodes/direct.rb
41
+ - lib/dsel/dsl/nodes/direct/environment.rb
42
+ - lib/dsel/dsl/nodes/proxy.rb
43
+ - lib/dsel/dsl/nodes/proxy/environment.rb
44
+ - lib/dsel/node.rb
45
+ - lib/dsel/ruby/object.rb
46
+ - lib/dsel/version.rb
47
+ - spec/dsel/api/generator_spec.rb
48
+ - spec/dsel/api/node_spec.rb
49
+ - spec/dsel/dsel_spec.rb
50
+ - spec/dsel/dsl/nodes/api/environment.rb
51
+ - spec/dsel/dsl/nodes/api_builder/environment_spec.rb
52
+ - spec/dsel/dsl/nodes/api_builder_spec.rb
53
+ - spec/dsel/dsl/nodes/api_spec.rb
54
+ - spec/dsel/dsl/nodes/direct/environment_spec.rb
55
+ - spec/dsel/dsl/nodes/direct_spec.rb
56
+ - spec/dsel/dsl/nodes/proxy/environment_spec.rb
57
+ - spec/dsel/dsl/nodes/proxy_spec.rb
58
+ - spec/spec_helper.rb
59
+ - spec/support/factories/clean_api_spec.rb
60
+ - spec/support/fixtures/mock_api.rb
61
+ - spec/support/helpers/paths.rb
62
+ - spec/support/lib/factory.rb
63
+ - spec/support/shared/dsl/nodes/base.rb
64
+ - spec/support/shared/dsl/nodes/base/environment.rb
65
+ - spec/support/shared/node.rb
66
+ homepage: https://github.com/qadron/dsel
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.3.0.dev
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: DSL/API generator and runner.
89
+ test_files:
90
+ - spec/dsel/api/generator_spec.rb
91
+ - spec/dsel/api/node_spec.rb
92
+ - spec/dsel/dsel_spec.rb
93
+ - spec/dsel/dsl/nodes/api/environment.rb
94
+ - spec/dsel/dsl/nodes/api_builder/environment_spec.rb
95
+ - spec/dsel/dsl/nodes/api_builder_spec.rb
96
+ - spec/dsel/dsl/nodes/api_spec.rb
97
+ - spec/dsel/dsl/nodes/direct/environment_spec.rb
98
+ - spec/dsel/dsl/nodes/direct_spec.rb
99
+ - spec/dsel/dsl/nodes/proxy/environment_spec.rb
100
+ - spec/dsel/dsl/nodes/proxy_spec.rb
101
+ - spec/spec_helper.rb
102
+ - spec/support/factories/clean_api_spec.rb
103
+ - spec/support/fixtures/mock_api.rb
104
+ - spec/support/helpers/paths.rb
105
+ - spec/support/lib/factory.rb
106
+ - spec/support/shared/dsl/nodes/base/environment.rb
107
+ - spec/support/shared/dsl/nodes/base.rb
108
+ - spec/support/shared/node.rb