gauge-ruby 0.0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e2188a5e620b9ea6f96412402b3da4ea7dd152a
4
+ data.tar.gz: eda8692a31244882c0a50a8395124270ae689216
5
+ SHA512:
6
+ metadata.gz: dcca9d23502d72a8a98071255853ac8ee9b213bfdd58506351c1df3cca4d47eb064b058e5c053cf40ea66cd2aa89ba231523f9d4c545b295a125c1ace3dcf558
7
+ data.tar.gz: cc7dcd0093d0c10357839a5a16d68591659ba3a8e0ad0d5720e1dbf1b55d89f43f3efbcfae62ff1cdae00646b10c75058fb07641dec5158967a2ffdd5ee6b38d
@@ -0,0 +1,211 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright 2015 ThoughtWorks, Inc.
4
+
5
+ # This file is part of Gauge-Ruby.
6
+
7
+ # Gauge-Ruby is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # Gauge-Ruby is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with Gauge-Ruby. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
21
+
22
+ require 'protocol_buffers'
23
+
24
+ begin; require 'spec.pb'; rescue LoadError; end
25
+
26
+ module Gauge
27
+ # @api private
28
+ module Messages
29
+ # forward declarations
30
+ class GetProjectRootRequest < ::ProtocolBuffers::Message; end
31
+ class GetProjectRootResponse < ::ProtocolBuffers::Message; end
32
+ class GetInstallationRootRequest < ::ProtocolBuffers::Message; end
33
+ class GetInstallationRootResponse < ::ProtocolBuffers::Message; end
34
+ class GetAllStepsRequest < ::ProtocolBuffers::Message; end
35
+ class GetAllStepsResponse < ::ProtocolBuffers::Message; end
36
+ class GetAllSpecsRequest < ::ProtocolBuffers::Message; end
37
+ class GetAllSpecsResponse < ::ProtocolBuffers::Message; end
38
+ class GetAllConceptsRequest < ::ProtocolBuffers::Message; end
39
+ class GetAllConceptsResponse < ::ProtocolBuffers::Message; end
40
+ class ConceptInfo < ::ProtocolBuffers::Message; end
41
+ class GetStepValueRequest < ::ProtocolBuffers::Message; end
42
+ class GetStepValueResponse < ::ProtocolBuffers::Message; end
43
+ class GetLanguagePluginLibPathRequest < ::ProtocolBuffers::Message; end
44
+ class GetLanguagePluginLibPathResponse < ::ProtocolBuffers::Message; end
45
+ class ErrorResponse < ::ProtocolBuffers::Message; end
46
+ class PerformRefactoringRequest < ::ProtocolBuffers::Message; end
47
+ class PerformRefactoringResponse < ::ProtocolBuffers::Message; end
48
+ class APIMessage < ::ProtocolBuffers::Message; end
49
+
50
+ class GetProjectRootRequest < ::ProtocolBuffers::Message
51
+ set_fully_qualified_name "gauge.messages.GetProjectRootRequest"
52
+
53
+ end
54
+
55
+ class GetProjectRootResponse < ::ProtocolBuffers::Message
56
+ set_fully_qualified_name "gauge.messages.GetProjectRootResponse"
57
+
58
+ required :string, :projectRoot, 1
59
+ end
60
+
61
+ class GetInstallationRootRequest < ::ProtocolBuffers::Message
62
+ set_fully_qualified_name "gauge.messages.GetInstallationRootRequest"
63
+
64
+ end
65
+
66
+ class GetInstallationRootResponse < ::ProtocolBuffers::Message
67
+ set_fully_qualified_name "gauge.messages.GetInstallationRootResponse"
68
+
69
+ required :string, :installationRoot, 1
70
+ end
71
+
72
+ class GetAllStepsRequest < ::ProtocolBuffers::Message
73
+ set_fully_qualified_name "gauge.messages.GetAllStepsRequest"
74
+
75
+ end
76
+
77
+ class GetAllStepsResponse < ::ProtocolBuffers::Message
78
+ set_fully_qualified_name "gauge.messages.GetAllStepsResponse"
79
+
80
+ repeated ::Gauge::Messages::ProtoStepValue, :allSteps, 1
81
+ end
82
+
83
+ class GetAllSpecsRequest < ::ProtocolBuffers::Message
84
+ set_fully_qualified_name "gauge.messages.GetAllSpecsRequest"
85
+
86
+ end
87
+
88
+ class GetAllSpecsResponse < ::ProtocolBuffers::Message
89
+ set_fully_qualified_name "gauge.messages.GetAllSpecsResponse"
90
+
91
+ repeated ::Gauge::Messages::ProtoSpec, :specs, 1
92
+ end
93
+
94
+ class GetAllConceptsRequest < ::ProtocolBuffers::Message
95
+ set_fully_qualified_name "gauge.messages.GetAllConceptsRequest"
96
+
97
+ end
98
+
99
+ class GetAllConceptsResponse < ::ProtocolBuffers::Message
100
+ set_fully_qualified_name "gauge.messages.GetAllConceptsResponse"
101
+
102
+ repeated ::Gauge::Messages::ConceptInfo, :concepts, 1
103
+ end
104
+
105
+ class ConceptInfo < ::ProtocolBuffers::Message
106
+ set_fully_qualified_name "gauge.messages.ConceptInfo"
107
+
108
+ required ::Gauge::Messages::ProtoStepValue, :stepValue, 1
109
+ required :string, :filepath, 2
110
+ required :int32, :lineNumber, 3
111
+ end
112
+
113
+ class GetStepValueRequest < ::ProtocolBuffers::Message
114
+ set_fully_qualified_name "gauge.messages.GetStepValueRequest"
115
+
116
+ required :string, :stepText, 1
117
+ optional :bool, :hasInlineTable, 2
118
+ end
119
+
120
+ class GetStepValueResponse < ::ProtocolBuffers::Message
121
+ set_fully_qualified_name "gauge.messages.GetStepValueResponse"
122
+
123
+ required ::Gauge::Messages::ProtoStepValue, :stepValue, 1
124
+ end
125
+
126
+ class GetLanguagePluginLibPathRequest < ::ProtocolBuffers::Message
127
+ set_fully_qualified_name "gauge.messages.GetLanguagePluginLibPathRequest"
128
+
129
+ required :string, :language, 1
130
+ end
131
+
132
+ class GetLanguagePluginLibPathResponse < ::ProtocolBuffers::Message
133
+ set_fully_qualified_name "gauge.messages.GetLanguagePluginLibPathResponse"
134
+
135
+ required :string, :path, 1
136
+ end
137
+
138
+ class ErrorResponse < ::ProtocolBuffers::Message
139
+ set_fully_qualified_name "gauge.messages.ErrorResponse"
140
+
141
+ required :string, :error, 1
142
+ end
143
+
144
+ class PerformRefactoringRequest < ::ProtocolBuffers::Message
145
+ set_fully_qualified_name "gauge.messages.PerformRefactoringRequest"
146
+
147
+ required :string, :oldStep, 1
148
+ required :string, :newStep, 2
149
+ end
150
+
151
+ class PerformRefactoringResponse < ::ProtocolBuffers::Message
152
+ set_fully_qualified_name "gauge.messages.PerformRefactoringResponse"
153
+
154
+ required :bool, :success, 1
155
+ repeated :string, :errors, 2
156
+ repeated :string, :filesChanged, 3
157
+ end
158
+
159
+ class APIMessage < ::ProtocolBuffers::Message
160
+ # forward declarations
161
+
162
+ # enums
163
+ module APIMessageType
164
+ include ::ProtocolBuffers::Enum
165
+
166
+ set_fully_qualified_name "gauge.messages.APIMessage.APIMessageType"
167
+
168
+ GetProjectRootRequest = 1
169
+ GetProjectRootResponse = 2
170
+ GetInstallationRootRequest = 3
171
+ GetInstallationRootResponse = 4
172
+ GetAllStepsRequest = 5
173
+ GetAllStepResponse = 6
174
+ GetAllSpecsRequest = 7
175
+ GetAllSpecsResponse = 8
176
+ GetStepValueRequest = 9
177
+ GetStepValueResponse = 10
178
+ GetLanguagePluginLibPathRequest = 11
179
+ GetLanguagePluginLibPathResponse = 12
180
+ ErrorResponse = 13
181
+ GetAllConceptsRequest = 14
182
+ GetAllConceptsResponse = 15
183
+ PerformRefactoringRequest = 16
184
+ PerformRefactoringResponse = 17
185
+ end
186
+
187
+ set_fully_qualified_name "gauge.messages.APIMessage"
188
+
189
+ required ::Gauge::Messages::APIMessage::APIMessageType, :messageType, 1
190
+ required :int64, :messageId, 2
191
+ optional ::Gauge::Messages::GetProjectRootRequest, :projectRootRequest, 3
192
+ optional ::Gauge::Messages::GetProjectRootResponse, :projectRootResponse, 4
193
+ optional ::Gauge::Messages::GetInstallationRootRequest, :installationRootRequest, 5
194
+ optional ::Gauge::Messages::GetInstallationRootResponse, :installationRootResponse, 6
195
+ optional ::Gauge::Messages::GetAllStepsRequest, :allStepsRequest, 7
196
+ optional ::Gauge::Messages::GetAllStepsResponse, :allStepsResponse, 8
197
+ optional ::Gauge::Messages::GetAllSpecsRequest, :allSpecsRequest, 9
198
+ optional ::Gauge::Messages::GetAllSpecsResponse, :allSpecsResponse, 10
199
+ optional ::Gauge::Messages::GetStepValueRequest, :stepValueRequest, 11
200
+ optional ::Gauge::Messages::GetStepValueResponse, :stepValueResponse, 12
201
+ optional ::Gauge::Messages::GetLanguagePluginLibPathRequest, :libPathRequest, 13
202
+ optional ::Gauge::Messages::GetLanguagePluginLibPathResponse, :libPathResponse, 14
203
+ optional ::Gauge::Messages::ErrorResponse, :error, 15
204
+ optional ::Gauge::Messages::GetAllConceptsRequest, :allConceptsRequest, 16
205
+ optional ::Gauge::Messages::GetAllConceptsResponse, :allConceptsResponse, 17
206
+ optional ::Gauge::Messages::PerformRefactoringRequest, :performRefactoringRequest, 18
207
+ optional ::Gauge::Messages::PerformRefactoringResponse, :performRefactoringResponse, 19
208
+ end
209
+
210
+ end
211
+ end
@@ -0,0 +1,84 @@
1
+ # Copyright 2015 ThoughtWorks, Inc.
2
+ #
3
+ # This file is part of Gauge-Ruby.
4
+ #
5
+ # Gauge-Ruby is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Gauge-Ruby is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Gauge-Ruby. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require 'parser/current'
19
+ require 'method_source'
20
+ require 'fileutils'
21
+ require 'tempfile'
22
+
23
+ module Gauge
24
+ # @api private
25
+ class CodeParser
26
+ def self.step_args_from_code(code)
27
+ ast=code_to_ast(code)
28
+ arg_node = ast.children[1]
29
+ arg_node.children
30
+ end
31
+
32
+ def self.refactor_args(code, param_positions, new_param_values, new_step_text)
33
+ new_params = []
34
+ args = step_args_from_code code
35
+ param_positions.sort_by!(&:newPosition).each { |e|
36
+ if e.oldPosition == -1
37
+ new_params[e.newPosition] = new_param_values[e.newPosition]
38
+ else
39
+ new_params[e.newPosition] = args[e.oldPosition].children[0]
40
+ end
41
+ }
42
+ buffer = Parser::Source::Buffer.new '(rewriter)'
43
+ buffer.source=code
44
+
45
+ ast = code_to_ast(code)
46
+ new_params_string = "|#{new_params.join(', ')}|".gsub("||", "") # no params = empty string
47
+
48
+ rewriter = Parser::Source::Rewriter.new(buffer)
49
+ .replace(ast.children[0].location.expression, "step '#{new_step_text}'")
50
+
51
+ # hack, could not find an easy way to manipulate the ast to include arguments, when none existed originally.
52
+ # it's just easy to add arguments via string substitution.
53
+ return include_args(rewriter.process, new_params_string) if ast.children[1].location.expression.nil?
54
+
55
+ #insert new arguments
56
+ rewriter.replace(ast.children[1].location.expression, new_params_string).process
57
+ end
58
+
59
+ def self.refactor(code, param_positions, new_param_values, new_step_text)
60
+ source_code=code.source
61
+ ast = code_to_ast source_code
62
+ file, line = code.source_location
63
+ refactored_code=refactor_args(source_code, param_positions, new_param_values, new_step_text)
64
+ tmp_file = Tempfile.new File.basename(file, ".rb")
65
+ tmp_file.write(File.open(file, "r") { |f| f.read.gsub(source_code, refactored_code)})
66
+ tmp_file.close
67
+ FileUtils.mv tmp_file.path, file
68
+ end
69
+
70
+ private
71
+
72
+ def self.code_to_ast(code)
73
+ buffer = Parser::Source::Buffer.new '(string)'
74
+ buffer.source = code
75
+
76
+ parser = Parser::CurrentRuby.new
77
+ parser.parse(buffer)
78
+ end
79
+
80
+ def self.include_args(code_string, params)
81
+ code_string.gsub("do", "do #{params}")
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,71 @@
1
+ # Copyright 2015 ThoughtWorks, Inc.
2
+
3
+ # This file is part of Gauge-Ruby.
4
+ #
5
+ # Gauge-Ruby is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Gauge-Ruby is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Gauge-Ruby. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ # @api public
19
+ module Gauge
20
+ # @api public
21
+ class << self
22
+ # @!macro [attach] self.configure
23
+ # @method configure(&block)
24
+ # @api public
25
+ # Custom configuration for Gauge
26
+ # Lets you configure modules that need to be included at runtime.
27
+ #
28
+ # @example
29
+ # # Given there are two modules defined
30
+ # module Foo
31
+ # end
32
+ #
33
+ # module Bar
34
+ # end
35
+ #
36
+ # # Gauge can be configured to include these modules at runtime.
37
+ #
38
+ # Gauge.configure do |config|
39
+ # config.include Foo, Bar
40
+ # end
41
+ def configure(&block)
42
+ Configuration.instance.instance_eval &block
43
+ end
44
+ end
45
+
46
+ # @api private
47
+ class Configuration
48
+ def initialize
49
+ @includes=[]
50
+ end
51
+
52
+ def self.instance
53
+ @configuration ||= Configuration.new
54
+ end
55
+
56
+ def include(*includes)
57
+ @includes.push *includes
58
+ end
59
+
60
+ def includes
61
+ @includes
62
+ end
63
+
64
+ def self.include_configured_modules
65
+ # include all modules that have been configured
66
+ # TODO: move this feature to something more specific, ex look at supporting Sandboxed execution.
67
+ main=TOPLEVEL_BINDING.eval('self')
68
+ self.instance.includes.each &main.method(:include)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,73 @@
1
+ # Copyright 2015 ThoughtWorks, Inc.
2
+
3
+ # This file is part of Gauge-Ruby.
4
+
5
+ # Gauge-Ruby is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # Gauge-Ruby is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Gauge-Ruby. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require 'protocol_buffers'
19
+ require_relative 'api.pb'
20
+
21
+ module Gauge
22
+ # @api private
23
+ module Connector
24
+ GAUGE_PORT_ENV = "GAUGE_INTERNAL_PORT"
25
+ API_PORT_ENV = "GAUGE_API_PORT"
26
+ HOST_NAME = 'localhost'
27
+ @@executionSocket
28
+ @@apiSocket
29
+
30
+ def self.apiSocket
31
+ @@apiSocket
32
+ end
33
+
34
+ def self.executionSocket
35
+ @@executionSocket
36
+ end
37
+
38
+ def self.make_connections
39
+ @@executionSocket = TCPSocket.open(HOST_NAME, Runtime.portFromEnvVariable(GAUGE_PORT_ENV))
40
+ @@apiSocket = TCPSocket.open(HOST_NAME, Runtime.portFromEnvVariable(API_PORT_ENV))
41
+ end
42
+
43
+ def self.message_length(socket)
44
+ ProtocolBuffers::Varint.decode socket
45
+ end
46
+
47
+ def self.step_value text
48
+ stepValueRequest = Gauge::Messages::GetStepValueRequest.new(:stepText => text)
49
+ apiMessage = Gauge::Messages::APIMessage.new(:messageType => Gauge::Messages::APIMessage::APIMessageType::GetStepValueRequest, :stepValueRequest => stepValueRequest)
50
+ response = get_api_response(apiMessage)
51
+ if (response.messageType == Gauge::Messages::APIMessage::APIMessageType::ErrorResponse)
52
+ puts "[Error] Failed to load step implementation. #{response.error.error}: \"#{text}\""
53
+ return ''
54
+ end
55
+ return response.stepValueResponse.stepValue.stepValue
56
+ end
57
+
58
+ def self.get_api_response(apiMessage)
59
+ apiMessage.messageId = get_unique_id
60
+ dataLen = apiMessage.serialize_to_string.bytesize
61
+ ProtocolBuffers::Varint.encode @@apiSocket, dataLen
62
+ apiMessage.serialize(@@apiSocket)
63
+
64
+ responseLen = message_length(@@apiSocket)
65
+ data = @@apiSocket.read responseLen
66
+ message = Gauge::Messages::APIMessage.parse(data)
67
+ end
68
+
69
+ def self.get_unique_id
70
+ rand(2**63-1)
71
+ end
72
+ end
73
+ end