tdl-client-ruby 0.5.7 → 0.6.0

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: 5f26c749800235135540aa9dbd89683d51c7acc2
4
- data.tar.gz: 50a2516af1455cfca7428985e3f187ec281d33c4
3
+ metadata.gz: 0e206393d58ca00c7f4560f88677b76e9d165985
4
+ data.tar.gz: d2b95e230be6006c59a106ef0493e298780e3d9a
5
5
  SHA512:
6
- metadata.gz: c65df7f640fcb09cd9aa9ff8e5dc79febc92d1d8a706c73b5ecf58b487aa7f22eb163a7cc35cb73bd85a11deb4b093cd600516a3e15ea5a0538212225303822f
7
- data.tar.gz: ff0f24af5b8a58132d6e142f4c3b11c7033fbbd5b6560cd3b2a69566262f0aa7cbca9a227259f8a1bec53a2766d80aec00d53558529813c4781fad82b301d291
6
+ metadata.gz: 8e4b1cfbf040a3507b7783c641dd0b53a1969f8a55d791213e8345a887771e5fbe232fbc4e79d2d618a43907008872851ff371ab585e5202ff4a67a3b5b3d489
7
+ data.tar.gz: 1635f6f159525ecac124a8d95e612120e9e76a4945f01dab084b07a5d84cecb9dfe88aceea4f30693e6b62fadac0f06220acba9f27bcedc82a191f69369fcdd9
data/Rakefile CHANGED
@@ -37,12 +37,12 @@ end
37
37
 
38
38
  #~~~~~~~~ Deploy
39
39
 
40
- require 'tdl/version'
40
+ require 'tdl/previous_version'
41
41
 
42
42
  task :build do
43
43
  system 'gem build tdl-client-ruby.gemspec'
44
44
  end
45
45
 
46
46
  task :release => :build do
47
- system "gem push tdl-client-ruby-*.gem"
47
+ system 'gem push tdl-client-ruby-*.gem'
48
48
  end
data/lib/tdl.rb CHANGED
@@ -1,6 +1,5 @@
1
1
 
2
2
  require 'tdl/client'
3
- require 'tdl/version'
4
3
 
5
4
  module TDL
6
5
  end
@@ -0,0 +1,18 @@
1
+ require 'tdl/actions/stop_action'
2
+
3
+ module TDL
4
+ class FatalErrorResponse
5
+
6
+ def initialize(message)
7
+ @message = message
8
+ end
9
+
10
+ def client_action
11
+ StopAction.new
12
+ end
13
+
14
+ def audit_text
15
+ "error = #{@message}"
16
+ end
17
+ end
18
+ end
@@ -1,10 +1,11 @@
1
1
  module TDL
2
- class Response
3
- attr_reader :result, :id
2
+ class ValidResponse
3
+ attr_reader :result, :id, :client_action
4
4
 
5
- def initialize(id, result)
5
+ def initialize(id, result, client_action)
6
6
  @id = id
7
7
  @result = result
8
+ @client_action = client_action
8
9
  end
9
10
 
10
11
  def to_h
data/lib/tdl/client.rb CHANGED
@@ -2,7 +2,7 @@ require 'stomp'
2
2
  require 'logging'
3
3
 
4
4
  require 'tdl/transport/remote_broker'
5
- require 'tdl/abstractions/processing_rules'
5
+ require 'tdl/processing_rules'
6
6
  require 'tdl/actions/stop_action'
7
7
 
8
8
  require 'tdl/serialization/json_rpc_serialization_provider'
@@ -29,8 +29,8 @@ module TDL
29
29
  @logger.info 'Stopping client.'
30
30
  remote_broker.close
31
31
  rescue Exception => e
32
- @logger.error "Problem communicating with the broker. #{e.message}"
33
- raise $! if ENV['RUBY_ENV'] == 'test'
32
+ @logger.error "There was a problem processing messages. #{e.message}"
33
+ @logger.error e.backtrace.join("\n")
34
34
  end
35
35
  end
36
36
 
@@ -50,12 +50,11 @@ module TDL
50
50
  @audit.log(request)
51
51
 
52
52
  # Obtain response from user
53
- processing_rule = @processing_rules.get_rule_for(request)
54
- response = get_response_for(processing_rule, request)
55
- @audit.log(response ? response : Response.new('','empty'))
53
+ response = @processing_rules.get_response_for(request)
54
+ @audit.log(response)
56
55
 
57
56
  # Obtain action
58
- client_action = response ? processing_rule.client_action : StopAction.new
57
+ client_action = response.client_action
59
58
 
60
59
  # Act
61
60
  client_action.after_response(remote_broker, request, response)
@@ -64,19 +63,6 @@ module TDL
64
63
  client_action.prepare_for_next_request(remote_broker)
65
64
  end
66
65
 
67
- def get_response_for(processing_rule, request)
68
- begin
69
- user_implementation = processing_rule.user_implementation
70
- result = user_implementation.call(*request.params)
71
-
72
- response = Response.new(request.id, result)
73
- rescue Exception => e
74
- response = nil
75
- @logger.info "The user implementation has thrown exception. #{e.message}"
76
- end
77
- response
78
- end
79
-
80
66
  end
81
67
  end
82
68
 
@@ -0,0 +1,3 @@
1
+ module TDL
2
+ PREVIOUS_VERSION = '0.5.7'
3
+ end
@@ -1,4 +1,6 @@
1
1
  require 'tdl/abstractions/processing_rule'
2
+ require 'tdl/abstractions/response/fatal_error_response'
3
+ require 'tdl/abstractions/response/valid_response'
2
4
  require 'tdl/actions/client_actions'
3
5
 
4
6
  module TDL
@@ -6,6 +8,7 @@ module TDL
6
8
 
7
9
  def initialize
8
10
  @rules = Hash.new
11
+ @logger = Logging.logger[self]
9
12
  end
10
13
 
11
14
  # ~~~~ Builders
@@ -18,7 +21,6 @@ module TDL
18
21
  ProcessingRuleBuilder.new(self, method_name)
19
22
  end
20
23
 
21
-
22
24
  class ProcessingRuleBuilder
23
25
 
24
26
  def initialize(instance, method_name)
@@ -37,14 +39,27 @@ module TDL
37
39
  end
38
40
 
39
41
 
40
-
41
42
  # ~~~~ Accessors
42
43
 
43
- def get_rule_for(request)
44
+ def get_response_for(request)
44
45
  if @rules.has_key?(request.method)
45
- @rules[request.method]
46
+ processing_rule = @rules[request.method]
46
47
  else
47
- raise NameError.new("Method #{request.method} did not match any processing rule.")
48
+ message = "method \"#{request.method}\" did not match any processing rule"
49
+ @logger.warn(message)
50
+ return FatalErrorResponse.new(message)
51
+ end
52
+
53
+ begin
54
+ user_implementation = processing_rule.user_implementation
55
+ result = user_implementation.call(*request.params)
56
+
57
+ return ValidResponse.new(request.id, result, processing_rule.client_action)
58
+ rescue Exception => e
59
+ message = 'user implementation raised exception'
60
+ @logger.warn("#{message}, #{e.message}")
61
+ @logger.warn e.backtrace.join("\n")
62
+ return FatalErrorResponse.new(message)
48
63
  end
49
64
  end
50
65
 
@@ -0,0 +1,3 @@
1
+
2
+ class DeserializationException < StandardError
3
+ end
@@ -1,6 +1,6 @@
1
1
  require 'json'
2
2
  require 'tdl/abstractions/request'
3
- require 'tdl/abstractions/response'
3
+ require 'tdl/serialization/deserialization_exception'
4
4
 
5
5
  module TDL
6
6
  class JSONRPCSerializationProvider
@@ -9,8 +9,12 @@ module TDL
9
9
  end
10
10
 
11
11
  def deserialize(msg)
12
- request_data = JSON.parse(msg.body)
13
- Request.new(msg, request_data)
12
+ begin
13
+ request_data = JSON.parse(msg.body)
14
+ Request.new(msg, request_data)
15
+ rescue Exception => e
16
+ raise DeserializationException,'Invalid message format', e.backtrace
17
+ end
14
18
  end
15
19
 
16
20
  def serialize(response)
@@ -19,10 +19,6 @@ module TDL
19
19
  @stomp_client.acknowledge(request.original_message)
20
20
  end
21
21
 
22
- def publish(response)
23
- @stomp_client.publish("/queue/#{@username}.resp", response)
24
- end
25
-
26
22
  def join(limit = nil)
27
23
  @stomp_client.join(limit)
28
24
  end
data/release.sh CHANGED
@@ -2,27 +2,26 @@
2
2
 
3
3
  SCRIPT_FOLDER="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4
4
  VERSION_FILE="${SCRIPT_FOLDER}/lib/tdl/version.rb"
5
- SPEC_FOLDER="${SCRIPT_FOLDER}/features/spec/"
5
+ TMP_VERSION_FILE="${SCRIPT_FOLDER}/out/versions.txt"
6
6
 
7
- function get_version_from_tag() {
8
- local target_folder=$1
9
- git --git-dir ${target_folder}/.git describe --all | cut -d "/" -f 2 | tr -d "v"
10
- }
11
7
 
12
- function get_property() {
8
+ function gemspec_property() {
13
9
  local property=$1
14
- cat ${VERSION_FILE} | grep "${property}" | cut -d "=" -f2 | tr -d " '"
10
+ cat ${TMP_VERSION_FILE} | grep ${property} | cut -d "=" -f2 | tr -d " "
15
11
  }
16
12
 
17
- # Current
18
- CURRENT_MAJOR_MINOR_VERSION=`get_version_from_tag ${SPEC_FOLDER}`
19
- CURRENT_PATCH_VERSION=`get_property "CURRENT_PATCH_VERSION"`
20
- CURRENT_VERSION="${CURRENT_MAJOR_MINOR_VERSION}.${CURRENT_PATCH_VERSION}"
13
+ echo "Reading gemspec properties. This might take some time."
21
14
 
22
15
  # Previous
23
- PREVIOUS_MAJOR_MINOR_VERSION=`get_property "PREVIOUS_VERSION" | cut -d "." -f 1,2`
24
- PREVIOUS_PATCH_VERSION=`get_property "PREVIOUS_VERSION" | cut -d "." -f 2`
25
- PREVIOUS_VERSION=`get_property "PREVIOUS_VERSION"`
16
+ ruby <<-EOS | tee ${TMP_VERSION_FILE}
17
+ require "rubygems"
18
+ spec = Gem::Specification::load("tdl-client-ruby.gemspec")
19
+ puts "PREVIOUS_VERSION = #{spec.metadata['previous_version']}"
20
+ puts "CURRENT_VERSION = #{spec.version}"
21
+ EOS
22
+ PREVIOUS_VERSION=`gemspec_property PREVIOUS_VERSION`
23
+ CURRENT_VERSION=`gemspec_property CURRENT_VERSION`
24
+
26
25
 
27
26
  # Prompt for version confirmation
28
27
  read -p "Going to release version ${CURRENT_VERSION} (previous ${PREVIOUS_VERSION}). Proceed ? [y/n] "
@@ -37,24 +36,9 @@ git tag -a "v${CURRENT_VERSION}" -m "Release ${CURRENT_VERSION}"
37
36
  git push origin "v${CURRENT_VERSION}"
38
37
  echo "Pushed tag to Git origin. It will now trigger the deployment pipeline."
39
38
 
40
- # Increment version
41
- next_patch_version() {
42
- if [ "$CURRENT_MAJOR_MINOR_VERSION" == "$PREVIOUS_MAJOR_MINOR_VERSION" ]; then
43
- patch=$((CURRENT_PATCH_VERSION+1))
44
- else
45
- patch="0"
46
- fi
47
- echo ${patch}
48
- }
49
-
50
- # Switch to next version
51
- NEXT_PATCH_VERSION=`next_patch_version`
52
- echo "Next patch version is: $NEXT_PATCH_VERSION"
53
-
54
39
  cat > "${VERSION_FILE}" <<-EOF
55
40
  module TDL
56
41
  PREVIOUS_VERSION = '$CURRENT_VERSION'
57
42
  # the current MAJOR.MINOR version is dynamically computed from the version of the Spec
58
- CURRENT_PATCH_VERSION = '$NEXT_PATCH_VERSION'
59
43
  end
60
44
  EOF
@@ -1,18 +1,44 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'tdl/version'
4
+ require 'tdl/previous_version'
5
5
 
6
- # DEBT: The patch version is not resetting correctly
6
+ #~~~~~~ Compute version
7
7
 
8
- SPEC_FOLDER = File.expand_path('../features/spec',__FILE__).to_s
9
- puts "Spec folder is: #{SPEC_FOLDER}"
10
- MAJOR_MINOR_VERSION = `git --git-dir #{SPEC_FOLDER}/.git describe --all | cut -d '/' -f 2 | tr -d 'v'`.strip
11
- VERSION = "#{MAJOR_MINOR_VERSION}.#{TDL::CURRENT_PATCH_VERSION}"
8
+ # Add increment to Version class
9
+ class ComparableVersion < Gem::Version
10
+ def increment
11
+ segments = self.segments.dup
12
+ segments[-1] = segments[-1].succ
13
+
14
+ self.class.new segments.join('.')
15
+ end
16
+ end
17
+
18
+ # Get Spec version from Git
19
+ spec_folder = File.expand_path('../features/spec',__FILE__).to_s
20
+ major_minor_version = `git --git-dir #{spec_folder}/.git describe --all | cut -d '/' -f 2 | tr -d 'v'`.strip
21
+
22
+ # Compute next version
23
+ previous_version = ComparableVersion.new(TDL::PREVIOUS_VERSION)
24
+ new_spec_version = ComparableVersion.new(major_minor_version+'.0')
25
+ if new_spec_version > previous_version
26
+ current_version = new_spec_version
27
+ else
28
+ current_version = previous_version.increment
29
+ end
30
+ # puts "previous_version = #{previous_version}"
31
+ # puts "current_version = #{current_version}"
32
+
33
+ VERSION = "#{current_version}"
34
+
35
+
36
+ #~~~~~ Create gemspec
12
37
 
13
38
  Gem::Specification.new do |spec|
14
39
  spec.name = 'tdl-client-ruby'
15
40
  spec.version = VERSION
41
+ spec.metadata = { 'previous_version' => TDL::PREVIOUS_VERSION }
16
42
  spec.authors = ['Julian Ghionoiu']
17
43
  spec.email = ['iulian.ghionoiu@gmail.com']
18
44
 
data/tdl-client-ruby.iml CHANGED
@@ -40,6 +40,7 @@
40
40
  <orderEntry type="library" scope="PROVIDED" name="multi_json (v1.11.2, rbenv: 2.2.2) [gem]" level="application" />
41
41
  <orderEntry type="library" scope="PROVIDED" name="multi_test (v0.1.2, rbenv: 2.2.2) [gem]" level="application" />
42
42
  <orderEntry type="library" scope="PROVIDED" name="netrc (v0.10.3, rbenv: 2.2.2) [gem]" level="application" />
43
+ <orderEntry type="library" scope="PROVIDED" name="rake (v10.4.2, rbenv: 2.2.2) [gem]" level="application" />
43
44
  <orderEntry type="library" scope="PROVIDED" name="rest-client (v1.8.0, rbenv: 2.2.2) [gem]" level="application" />
44
45
  <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.7.5, rbenv: 2.2.2) [gem]" level="application" />
45
46
  <orderEntry type="library" scope="PROVIDED" name="simplecov (v0.10.0, rbenv: 2.2.2) [gem]" level="application" />
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tdl-client-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Ghionoiu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-15 00:00:00.000000000 Z
11
+ date: 2016-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stomp
@@ -199,24 +199,27 @@ files:
199
199
  - examples/add_numbers.rb
200
200
  - lib/tdl.rb
201
201
  - lib/tdl/abstractions/processing_rule.rb
202
- - lib/tdl/abstractions/processing_rules.rb
203
202
  - lib/tdl/abstractions/request.rb
204
- - lib/tdl/abstractions/response.rb
203
+ - lib/tdl/abstractions/response/fatal_error_response.rb
204
+ - lib/tdl/abstractions/response/valid_response.rb
205
205
  - lib/tdl/actions/client_actions.rb
206
206
  - lib/tdl/actions/publish_action.rb
207
207
  - lib/tdl/actions/publish_and_stop_action.rb
208
208
  - lib/tdl/actions/stop_action.rb
209
209
  - lib/tdl/client.rb
210
+ - lib/tdl/previous_version.rb
211
+ - lib/tdl/processing_rules.rb
212
+ - lib/tdl/serialization/deserialization_exception.rb
210
213
  - lib/tdl/serialization/json_rpc_serialization_provider.rb
211
214
  - lib/tdl/transport/remote_broker.rb
212
- - lib/tdl/version.rb
213
215
  - release.sh
214
216
  - tdl-client-ruby.gemspec
215
217
  - tdl-client-ruby.iml
216
218
  homepage: https://github.com/julianghionoiu/tdl-client-ruby
217
219
  licenses:
218
220
  - GPL-3.0
219
- metadata: {}
221
+ metadata:
222
+ previous_version: 0.5.7
220
223
  post_install_message:
221
224
  rdoc_options: []
222
225
  require_paths:
data/lib/tdl/version.rb DELETED
@@ -1,5 +0,0 @@
1
- module TDL
2
- PREVIOUS_VERSION = '0.3.6'
3
- # the current MAJOR.MINOR version is dynamically computed from the version of the Spec
4
- CURRENT_PATCH_VERSION = '7'
5
- end