jstp 1.1.0 → 1.2.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.
@@ -8,7 +8,7 @@ module JSTP
8
8
  @logger = Logger.new $stdout
9
9
  @hostname = (`hostname`)[0..-2]
10
10
  @environment = :development
11
- @gateway = true
11
+ @gateway = SymbolMatrix :reverse => true, :forward => true, :local => true
12
12
  end
13
13
 
14
14
  def port argument = nil
@@ -48,7 +48,7 @@ module JSTP
48
48
  end
49
49
 
50
50
  def gateway argument = nil
51
- @gateway = argument unless argument.nil?
51
+ @gateway = SymbolMatrix argument unless argument.nil?
52
52
  @gateway
53
53
  end
54
54
 
data/lib/jstp/dispatch.rb CHANGED
@@ -102,5 +102,13 @@ module JSTP
102
102
  def body= the_body
103
103
  self["body"] = the_body
104
104
  end
105
+
106
+ def gateway
107
+ self["gateway"]
108
+ end
109
+
110
+ def gateway= the_gateway
111
+ self["gateway"] = the_gateway
112
+ end
105
113
  end
106
114
  end
data/lib/jstp/engine.rb CHANGED
@@ -10,18 +10,28 @@ module JSTP
10
10
  # Processes the dispatch in the new REST engine way
11
11
  def dispatch message, client
12
12
  host, the_class, query = discover_resource message["resource"].clone
13
- if @config.gateway && host != @config.hostname && host != 'localhost'
13
+ if @config.gateway.forward && host != @config.hostname && host != 'localhost'
14
14
  # May be we should gateway this message, if this wasn't aimed at us
15
15
  message.to.send @config.strategy.outbound
16
16
  else
17
- if the_class.ancestors.include? JSTP::Controller
18
- resource = the_class.new message, query, self, client
19
- resource.send message["method"].downcase.to_sym
17
+ # Is there a reverse gateway token there?
18
+ if @config.gateway.reverse && message.gateway == 'reverse'
19
+ if clients.has_key? message.token.first
20
+ clients[message.token.first].send message.to.json
21
+ @config.logger.debug message.to.string
22
+ else
23
+ raise ClientNotFoundError, "Client #{message.token.first} is not registered in this server"
24
+ end
20
25
  else
21
- if @config.environment == :development
22
- raise NotAControllerError, "The resource class #{the_class} for #{message["resource"].join("/")} was found, but is not a JSTP::Controller"
26
+ if the_class.ancestors.include? JSTP::Controller
27
+ resource = the_class.new message, query, self, client
28
+ resource.send message["method"].downcase.to_sym
23
29
  else
24
- raise NotPermittedError, "The selected resource is forbidden for this type of request"
30
+ if @config.environment == :development
31
+ raise NotAControllerError, "The resource class #{the_class} for #{message["resource"].join("/")} was found, but is not a JSTP::Controller"
32
+ else
33
+ raise NotPermittedError, "The selected resource is forbidden for this type of request"
34
+ end
25
35
  end
26
36
  end
27
37
  end
@@ -52,6 +62,7 @@ module JSTP
52
62
 
53
63
  class NotPermittedError < RuntimeError; end
54
64
  class NotAControllerError < RuntimeError; end
65
+ class ClientNotFoundError < RuntimeError; end
55
66
 
56
67
  # DSL for configuration
57
68
  def self.port argument = nil
data/lib/jstp/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module JSTP
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
@@ -59,7 +59,7 @@ module Reader
59
59
  def log_exception exception, message
60
60
  @config.logger.error "#{exception.class}: #{exception.message}"
61
61
  @config.logger.debug exception.backtrace.to_s
62
- @config.logger.debug Oj.dump message if message
62
+ @config.logger.debug ::JSTP::Dispatch.new(message).to.string if message
63
63
  end
64
64
  end
65
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jstp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: