ably-rest 0.8.6 → 0.8.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/SPEC.md +1049 -1001
- data/lib/submodules/ably-ruby/CHANGELOG.md +75 -3
- data/lib/submodules/ably-ruby/LICENSE +2 -2
- data/lib/submodules/ably-ruby/README.md +81 -20
- data/lib/submodules/ably-ruby/SPEC.md +1209 -693
- data/lib/submodules/ably-ruby/ably.gemspec +4 -4
- data/lib/submodules/ably-ruby/lib/ably/auth.rb +13 -4
- data/lib/submodules/ably-ruby/lib/ably/exceptions.rb +10 -1
- data/lib/submodules/ably-ruby/lib/ably/logger.rb +3 -1
- data/lib/submodules/ably-ruby/lib/ably/models/cipher_params.rb +114 -0
- data/lib/submodules/ably-ruby/lib/ably/models/connection_details.rb +10 -7
- data/lib/submodules/ably-ruby/lib/ably/models/error_info.rb +3 -3
- data/lib/submodules/ably-ruby/lib/ably/models/idiomatic_ruby_wrapper.rb +28 -21
- data/lib/submodules/ably-ruby/lib/ably/models/message.rb +19 -17
- data/lib/submodules/ably-ruby/lib/ably/models/message_encoders/cipher.rb +10 -9
- data/lib/submodules/ably-ruby/lib/ably/models/paginated_result.rb +27 -1
- data/lib/submodules/ably-ruby/lib/ably/models/presence_message.rb +20 -18
- data/lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb +26 -19
- data/lib/submodules/ably-ruby/lib/ably/models/{stat.rb → stats.rb} +21 -19
- data/lib/submodules/ably-ruby/lib/ably/models/token_details.rb +14 -12
- data/lib/submodules/ably-ruby/lib/ably/models/token_request.rb +16 -14
- data/lib/submodules/ably-ruby/lib/ably/modules/async_wrapper.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/modules/channels_collection.rb +11 -1
- data/lib/submodules/ably-ruby/lib/ably/modules/encodeable.rb +10 -10
- data/lib/submodules/ably-ruby/lib/ably/modules/enum.rb +18 -2
- data/lib/submodules/ably-ruby/lib/ably/modules/event_emitter.rb +3 -3
- data/lib/submodules/ably-ruby/lib/ably/modules/model_common.rb +13 -5
- data/lib/submodules/ably-ruby/lib/ably/modules/safe_deferrable.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/modules/safe_yield.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/modules/state_emitter.rb +8 -8
- data/lib/submodules/ably-ruby/lib/ably/modules/statesman_monkey_patch.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/modules/uses_state_machine.rb +4 -2
- data/lib/submodules/ably-ruby/lib/ably/realtime.rb +1 -0
- data/lib/submodules/ably-ruby/lib/ably/realtime/auth.rb +6 -2
- data/lib/submodules/ably-ruby/lib/ably/realtime/channel.rb +7 -6
- data/lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_manager.rb +7 -1
- data/lib/submodules/ably-ruby/lib/ably/realtime/client.rb +7 -12
- data/lib/submodules/ably-ruby/lib/ably/realtime/client/incoming_message_dispatcher.rb +9 -2
- data/lib/submodules/ably-ruby/lib/ably/realtime/client/outgoing_message_dispatcher.rb +7 -1
- data/lib/submodules/ably-ruby/lib/ably/realtime/connection.rb +19 -8
- data/lib/submodules/ably-ruby/lib/ably/realtime/connection/connection_manager.rb +16 -9
- data/lib/submodules/ably-ruby/lib/ably/realtime/connection/websocket_transport.rb +12 -3
- data/lib/submodules/ably-ruby/lib/ably/realtime/presence.rb +35 -64
- data/lib/submodules/ably-ruby/lib/ably/realtime/presence/members_map.rb +23 -9
- data/lib/submodules/ably-ruby/lib/ably/rest/channel.rb +9 -10
- data/lib/submodules/ably-ruby/lib/ably/rest/client.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/rest/middleware/exceptions.rb +16 -4
- data/lib/submodules/ably-ruby/lib/ably/rest/presence.rb +7 -5
- data/lib/submodules/ably-ruby/lib/ably/util/crypto.rb +50 -40
- data/lib/submodules/ably-ruby/lib/ably/version.rb +1 -1
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/channel_history_spec.rb +4 -4
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_failures_spec.rb +2 -4
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_spec.rb +46 -8
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/message_spec.rb +20 -20
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_history_spec.rb +7 -7
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_spec.rb +114 -111
- data/lib/submodules/ably-ruby/spec/acceptance/rest/auth_spec.rb +9 -9
- data/lib/submodules/ably-ruby/spec/acceptance/rest/base_spec.rb +5 -5
- data/lib/submodules/ably-ruby/spec/acceptance/rest/channel_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/acceptance/rest/client_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/acceptance/rest/encoders_spec.rb +4 -4
- data/lib/submodules/ably-ruby/spec/acceptance/rest/message_spec.rb +15 -15
- data/lib/submodules/ably-ruby/spec/acceptance/rest/presence_spec.rb +4 -4
- data/lib/submodules/ably-ruby/spec/shared/model_behaviour.rb +7 -7
- data/lib/submodules/ably-ruby/spec/shared/safe_deferrable_behaviour.rb +4 -4
- data/lib/submodules/ably-ruby/spec/unit/models/cipher_params_spec.rb +140 -0
- data/lib/submodules/ably-ruby/spec/unit/models/idiomatic_ruby_wrapper_spec.rb +15 -8
- data/lib/submodules/ably-ruby/spec/unit/models/message_encoders/cipher_spec.rb +28 -22
- data/lib/submodules/ably-ruby/spec/unit/models/message_encoders/json_spec.rb +24 -0
- data/lib/submodules/ably-ruby/spec/unit/models/protocol_message_spec.rb +3 -3
- data/lib/submodules/ably-ruby/spec/unit/models/token_details_spec.rb +20 -18
- data/lib/submodules/ably-ruby/spec/unit/modules/event_emitter_spec.rb +2 -2
- data/lib/submodules/ably-ruby/spec/unit/modules/state_emitter_spec.rb +6 -6
- data/lib/submodules/ably-ruby/spec/unit/realtime/channel_spec.rb +4 -4
- data/lib/submodules/ably-ruby/spec/unit/realtime/connection_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/unit/realtime/presence_spec.rb +5 -5
- data/lib/submodules/ably-ruby/spec/unit/util/crypto_spec.rb +50 -17
- metadata +5 -3
@@ -16,7 +16,7 @@ module Ably::Models
|
|
16
16
|
# TokenDetails is a class providing details of the token string and the token's associated metadata,
|
17
17
|
# constructed from the response from Ably when request in a token via the REST API.
|
18
18
|
#
|
19
|
-
# Ruby {Time} objects are supported in place of Ably ms since epoch time fields. However, if a numeric is provided
|
19
|
+
# Ruby {http://ruby-doc.org/core/Time.html Time} objects are supported in place of Ably ms since epoch time fields. However, if a numeric is provided
|
20
20
|
# it must always be expressed in milliseconds as the Ably API always uses milliseconds for time fields.
|
21
21
|
#
|
22
22
|
class TokenDetails
|
@@ -38,46 +38,48 @@ module Ably::Models
|
|
38
38
|
@hash_object = IdiomaticRubyWrapper(attributes.clone)
|
39
39
|
|
40
40
|
%w(issued expires).map(&:to_sym).each do |time_attribute|
|
41
|
-
|
41
|
+
if self.attributes[time_attribute].kind_of?(Time)
|
42
|
+
self.attributes[time_attribute] = (self.attributes[time_attribute].to_f * 1000).round
|
43
|
+
end
|
42
44
|
end
|
43
45
|
|
44
|
-
|
46
|
+
self.attributes.freeze
|
45
47
|
end
|
46
48
|
|
47
49
|
# @!attribute [r] token
|
48
50
|
# @return [String] Token used to authenticate requests
|
49
51
|
def token
|
50
|
-
|
52
|
+
attributes[:token]
|
51
53
|
end
|
52
54
|
|
53
55
|
# @!attribute [r] key_name
|
54
56
|
# @return [String] API key name used to create this token. An API key is made up of an API key name and secret delimited by a +:+
|
55
57
|
def key_name
|
56
|
-
|
58
|
+
attributes[:key_name]
|
57
59
|
end
|
58
60
|
|
59
61
|
# @!attribute [r] issued
|
60
62
|
# @return [Time] Time the token was issued
|
61
63
|
def issued
|
62
|
-
as_time_from_epoch(
|
64
|
+
as_time_from_epoch(attributes[:issued], granularity: :ms, allow_nil: :true)
|
63
65
|
end
|
64
66
|
|
65
67
|
# @!attribute [r] expires
|
66
68
|
# @return [Time] Time the token expires
|
67
69
|
def expires
|
68
|
-
as_time_from_epoch(
|
70
|
+
as_time_from_epoch(attributes[:expires], granularity: :ms, allow_nil: :true)
|
69
71
|
end
|
70
72
|
|
71
73
|
# @!attribute [r] capability
|
72
74
|
# @return [Hash] Capabilities assigned to this token
|
73
75
|
def capability
|
74
|
-
JSON.parse(
|
76
|
+
JSON.parse(attributes.fetch(:capability)) if attributes.has_key?(:capability)
|
75
77
|
end
|
76
78
|
|
77
79
|
# @!attribute [r] client_id
|
78
80
|
# @return [String] Optional client ID assigned to this token
|
79
81
|
def client_id
|
80
|
-
|
82
|
+
attributes[:client_id]
|
81
83
|
end
|
82
84
|
|
83
85
|
# Returns true if token is expired or about to expire
|
@@ -93,12 +95,12 @@ module Ably::Models
|
|
93
95
|
# @return [Boolean]
|
94
96
|
# @api private
|
95
97
|
def from_token_string?
|
96
|
-
|
98
|
+
attributes.keys == [:token]
|
97
99
|
end
|
98
100
|
|
99
|
-
# @!attribute [r]
|
101
|
+
# @!attribute [r] attributes
|
100
102
|
# @return [Hash] Access the token details Hash object ruby'fied to use symbolized keys
|
101
|
-
def
|
103
|
+
def attributes
|
102
104
|
@hash_object
|
103
105
|
end
|
104
106
|
|
@@ -16,7 +16,7 @@ module Ably::Models
|
|
16
16
|
|
17
17
|
# TokenRequest is a class that stores the attributes of a token request
|
18
18
|
#
|
19
|
-
# Ruby {Time} objects are supported in place of Ably ms since epoch time fields. However, if a numeric is provided
|
19
|
+
# Ruby {http://ruby-doc.org/core/Time.html Time} objects are supported in place of Ably ms since epoch time fields. However, if a numeric is provided
|
20
20
|
# it must always be expressed in milliseconds as the Ably API always uses milliseconds for time fields.
|
21
21
|
#
|
22
22
|
class TokenRequest
|
@@ -24,7 +24,7 @@ module Ably::Models
|
|
24
24
|
|
25
25
|
# @param attributes
|
26
26
|
# @option attributes [Integer] :ttl requested time to live for the token in milliseconds
|
27
|
-
# @option attributes [Time,Integer] :timestamp the timestamp of this request in milliseconds or as a {Time}
|
27
|
+
# @option attributes [Time,Integer] :timestamp the timestamp of this request in milliseconds or as a {http://ruby-doc.org/core/Time.html Time}
|
28
28
|
# @option attributes [String] :key_name API key name of the key against which this request is made
|
29
29
|
# @option attributes [String] :capability JSON stringified capability of the token
|
30
30
|
# @option attributes [String] :client_id client ID to associate with this token
|
@@ -33,14 +33,16 @@ module Ably::Models
|
|
33
33
|
#
|
34
34
|
def initialize(attributes = {})
|
35
35
|
@hash_object = IdiomaticRubyWrapper(attributes.clone)
|
36
|
-
|
37
|
-
|
36
|
+
if self.attributes[:timestamp].kind_of?(Time)
|
37
|
+
self.attributes[:timestamp] = (self.attributes[:timestamp].to_f * 1000).round
|
38
|
+
end
|
39
|
+
self.attributes.freeze
|
38
40
|
end
|
39
41
|
|
40
42
|
# @!attribute [r] key_name
|
41
43
|
# @return [String] API key name of the key against which this request is made. An API key is made up of an API key name and secret delimited by a +:+
|
42
44
|
def key_name
|
43
|
-
|
45
|
+
attributes.fetch(:key_name)
|
44
46
|
end
|
45
47
|
|
46
48
|
# @!attribute [r] ttl
|
@@ -49,7 +51,7 @@ module Ably::Models
|
|
49
51
|
# settings and the attributes of the issuing key.
|
50
52
|
# TTL when sent to Ably is in milliseconds.
|
51
53
|
def ttl
|
52
|
-
|
54
|
+
attributes.fetch(:ttl) / 1000
|
53
55
|
end
|
54
56
|
|
55
57
|
# @!attribute [r] capability
|
@@ -57,14 +59,14 @@ module Ably::Models
|
|
57
59
|
# the capability of the returned token will be the intersection of
|
58
60
|
# this capability with the capability of the issuing key.
|
59
61
|
def capability
|
60
|
-
JSON.parse(
|
62
|
+
JSON.parse(attributes.fetch(:capability))
|
61
63
|
end
|
62
64
|
|
63
65
|
# @!attribute [r] client_id
|
64
66
|
# @return [String] the client ID to associate with this token. The generated token
|
65
67
|
# may be used to authenticate as this clientId.
|
66
68
|
def client_id
|
67
|
-
|
69
|
+
attributes[:client_id]
|
68
70
|
end
|
69
71
|
|
70
72
|
# @!attribute [r] timestamp
|
@@ -73,7 +75,7 @@ module Ably::Models
|
|
73
75
|
# token requests from being replayed.
|
74
76
|
# Timestamp when sent to Ably is in milliseconds.
|
75
77
|
def timestamp
|
76
|
-
as_time_from_epoch(
|
78
|
+
as_time_from_epoch(attributes.fetch(:timestamp), granularity: :ms)
|
77
79
|
end
|
78
80
|
|
79
81
|
# @!attribute [r] nonce
|
@@ -81,26 +83,26 @@ module Ably::Models
|
|
81
83
|
# uniqueness of this request. Any subsequent request using the
|
82
84
|
# same nonce will be rejected.
|
83
85
|
def nonce
|
84
|
-
|
86
|
+
attributes.fetch(:nonce)
|
85
87
|
end
|
86
88
|
|
87
89
|
# @!attribute [r] mac
|
88
90
|
# @return [String] the Message Authentication Code for this request. See the
|
89
91
|
# {https://www.ably.io/documentation Ably Authentication documentation} for more details.
|
90
92
|
def mac
|
91
|
-
|
93
|
+
attributes.fetch(:mac)
|
92
94
|
end
|
93
95
|
|
94
96
|
# Requests that the token is always persisted
|
95
97
|
# @api private
|
96
98
|
#
|
97
99
|
def persisted
|
98
|
-
|
100
|
+
attributes.fetch(:persisted)
|
99
101
|
end
|
100
102
|
|
101
|
-
# @!attribute [r]
|
103
|
+
# @!attribute [r] attributes
|
102
104
|
# @return [Hash] the token request Hash object ruby'fied to use symbolized keys
|
103
|
-
def
|
105
|
+
def attributes
|
104
106
|
@hash_object
|
105
107
|
end
|
106
108
|
end
|
@@ -2,7 +2,7 @@ require 'eventmachine'
|
|
2
2
|
|
3
3
|
module Ably::Modules
|
4
4
|
# Provides methods to convert synchronous operations into async operations through the use of
|
5
|
-
# {
|
5
|
+
# {http://www.rubydoc.info/github/eventmachine/eventmachine/EventMachine#defer-class_method EventMachine#defer}.
|
6
6
|
# The async_wrap method can only be called from within an EventMachine reactor, and must be thread safe.
|
7
7
|
#
|
8
8
|
# @note using this AsyncWrapper should only be used for methods that are used less frequently and typically
|
@@ -42,7 +42,7 @@ module Ably::Modules
|
|
42
42
|
raise ArgumentError, 'Block required' unless block_given?
|
43
43
|
|
44
44
|
Ably::Util::SafeDeferrable.new(logger).tap do |deferrable|
|
45
|
-
deferrable.callback
|
45
|
+
deferrable.callback(&success_callback) if success_callback
|
46
46
|
|
47
47
|
operation_with_exception_handling = proc do
|
48
48
|
begin
|
@@ -5,9 +5,9 @@ module Ably::Modules
|
|
5
5
|
# Provides methods to allow this model's `data` property to be encoded and decoded based on the `encoding` property.
|
6
6
|
#
|
7
7
|
# This module expects the following:
|
8
|
-
# - A #
|
9
|
-
# - A #
|
10
|
-
# - A #raw_hash_object attribute that returns the original hash used to create this object
|
8
|
+
# - A #attributes method that returns the underlying hash object
|
9
|
+
# - A #set_attributes_object(attributes) method that updates the underlying hash object
|
10
|
+
# - A #raw_hash_object attribute that returns the original hash object used to create this object
|
11
11
|
#
|
12
12
|
module Encodeable
|
13
13
|
# Encode a message using the channel options and register encoders for the client
|
@@ -46,20 +46,20 @@ module Ably::Modules
|
|
46
46
|
|
47
47
|
def apply_encoders(method, channel)
|
48
48
|
max_encoding_length = 512
|
49
|
-
|
49
|
+
message_attributes = attributes.dup
|
50
50
|
|
51
51
|
begin
|
52
|
-
if
|
53
|
-
raise Ably::Exceptions::EncoderError("Encoding error, encoding value is too long: '#{
|
52
|
+
if message_attributes[:encoding].to_s.length > max_encoding_length
|
53
|
+
raise Ably::Exceptions::EncoderError("Encoding error, encoding value is too long: '#{message_attributes[:encoding]}'", nil, 92100)
|
54
54
|
end
|
55
55
|
|
56
|
-
previous_encoding =
|
56
|
+
previous_encoding = message_attributes[:encoding]
|
57
57
|
channel.client.encoders.each do |encoder|
|
58
|
-
encoder.send method,
|
58
|
+
encoder.send method, message_attributes, channel.options
|
59
59
|
end
|
60
|
-
end until previous_encoding ==
|
60
|
+
end until previous_encoding == message_attributes[:encoding]
|
61
61
|
|
62
|
-
|
62
|
+
set_attributes_object message_attributes
|
63
63
|
rescue Ably::Exceptions::CipherError => cipher_error
|
64
64
|
if channel.respond_to?(:emit)
|
65
65
|
channel.client.logger.error "Encoder error #{cipher_error.code} trying to #{method} message: #{cipher_error.message}"
|
@@ -90,7 +90,13 @@ module Ably::Modules
|
|
90
90
|
end
|
91
91
|
|
92
92
|
private
|
93
|
-
|
93
|
+
def by_index
|
94
|
+
@by_index
|
95
|
+
end
|
96
|
+
|
97
|
+
def by_symbol
|
98
|
+
@by_symbol
|
99
|
+
end
|
94
100
|
|
95
101
|
# Define constants for each of the Enum values
|
96
102
|
# e.g. define_constants(:dog) creates Enum::Dog
|
@@ -173,7 +179,17 @@ module Ably::Modules
|
|
173
179
|
end
|
174
180
|
|
175
181
|
private
|
176
|
-
|
182
|
+
def name
|
183
|
+
@name
|
184
|
+
end
|
185
|
+
|
186
|
+
def index
|
187
|
+
@index
|
188
|
+
end
|
189
|
+
|
190
|
+
def symbol
|
191
|
+
@symbol
|
192
|
+
end
|
177
193
|
|
178
194
|
define_values values
|
179
195
|
end
|
@@ -39,7 +39,7 @@ module Ably
|
|
39
39
|
|
40
40
|
# Ensure @event_emitter_coerce_proc option is passed down to any classes that inherit the class with callbacks
|
41
41
|
def inherited(subclass)
|
42
|
-
subclass.instance_variable_set('@event_emitter_coerce_proc', @event_emitter_coerce_proc)
|
42
|
+
subclass.instance_variable_set('@event_emitter_coerce_proc', @event_emitter_coerce_proc) if defined?(@event_emitter_coerce_proc)
|
43
43
|
super
|
44
44
|
end
|
45
45
|
end
|
@@ -90,7 +90,7 @@ module Ably
|
|
90
90
|
clone.
|
91
91
|
select do |proc_hash|
|
92
92
|
if proc_hash[:unsafe]
|
93
|
-
proc_hash[:emit_proc].call
|
93
|
+
proc_hash[:emit_proc].call(*args)
|
94
94
|
else
|
95
95
|
safe_yield proc_hash[:emit_proc], *args
|
96
96
|
end
|
@@ -133,7 +133,7 @@ module Ably
|
|
133
133
|
def proc_for_block(block, options = {})
|
134
134
|
{
|
135
135
|
emit_proc: Proc.new do |*args|
|
136
|
-
block.call
|
136
|
+
block.call(*args)
|
137
137
|
true if options[:delete_once_run]
|
138
138
|
end,
|
139
139
|
block: block,
|
@@ -12,24 +12,32 @@ module Ably::Modules
|
|
12
12
|
#
|
13
13
|
# @return [Object]
|
14
14
|
def [](key)
|
15
|
-
|
15
|
+
attributes[key]
|
16
16
|
end
|
17
17
|
|
18
18
|
def ==(other)
|
19
19
|
other.kind_of?(self.class) &&
|
20
|
-
|
20
|
+
attributes == other.attributes
|
21
21
|
end
|
22
22
|
|
23
|
-
# Return a JSON ready object from the underlying #
|
23
|
+
# Return a JSON ready object from the underlying #attributes using Ably naming conventions for keys
|
24
|
+
# @return [Hash]
|
24
25
|
def as_json
|
25
|
-
|
26
|
+
attributes.as_json.reject { |key, val| val.nil? }
|
26
27
|
end
|
27
28
|
|
28
|
-
# Stringify the JSON representation of this object from the underlying #
|
29
|
+
# Stringify the JSON representation of this object from the underlying #attributes
|
30
|
+
# @return [String]
|
29
31
|
def to_json(*args)
|
30
32
|
as_json.to_json(*args)
|
31
33
|
end
|
32
34
|
|
35
|
+
# @!attribute [r] hash
|
36
|
+
# @return [Integer] Compute a hash-code for this hash. Two hashes with the same content will have the same hash code
|
37
|
+
def hash
|
38
|
+
attributes.hash
|
39
|
+
end
|
40
|
+
|
33
41
|
private
|
34
42
|
def ensure_utf8_string_for(attribute, value)
|
35
43
|
if value
|
@@ -59,7 +59,7 @@ module Ably::Modules
|
|
59
59
|
|
60
60
|
private
|
61
61
|
def safe_deferrable_block(*args)
|
62
|
-
yield
|
62
|
+
yield(*args)
|
63
63
|
rescue StandardError => e
|
64
64
|
message = "An exception in a Deferrable callback was caught. #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"
|
65
65
|
if defined?(:logger) && logger.respond_to?(:error)
|
@@ -13,7 +13,7 @@ module Ably::Modules
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def safe_yield(block, *args)
|
16
|
-
block.call
|
16
|
+
block.call(*args)
|
17
17
|
rescue StandardError => e
|
18
18
|
message = "An exception in an external block was caught. #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"
|
19
19
|
safe_yield_log_error message
|
@@ -23,7 +23,7 @@ module Ably::Modules
|
|
23
23
|
if defined?(:logger) && logger.respond_to?(:error)
|
24
24
|
return logger.error message
|
25
25
|
end
|
26
|
-
rescue StandardError
|
26
|
+
rescue StandardError
|
27
27
|
fallback_logger.error message
|
28
28
|
end
|
29
29
|
|
@@ -82,21 +82,21 @@ module Ably::Modules
|
|
82
82
|
|
83
83
|
success_wrapper = Proc.new do
|
84
84
|
yield
|
85
|
-
off
|
86
|
-
off
|
85
|
+
off(&success_wrapper)
|
86
|
+
off(&failure_wrapper) if failure_wrapper
|
87
87
|
end
|
88
88
|
|
89
89
|
failure_wrapper = proc do |*args|
|
90
|
-
failure_block.call
|
91
|
-
off
|
92
|
-
off
|
90
|
+
failure_block.call(*args)
|
91
|
+
off(&success_wrapper)
|
92
|
+
off(&failure_wrapper)
|
93
93
|
end if failure_block
|
94
94
|
|
95
95
|
Array(target_states).each do |target_state|
|
96
96
|
safe_unsafe_method options[:unsafe], :once, target_state, &success_wrapper
|
97
97
|
|
98
98
|
safe_unsafe_method options[:unsafe], :once_state_changed do |*args|
|
99
|
-
failure_wrapper.call
|
99
|
+
failure_wrapper.call(*args) unless state == target_state
|
100
100
|
end if failure_block
|
101
101
|
end
|
102
102
|
end
|
@@ -119,8 +119,8 @@ module Ably::Modules
|
|
119
119
|
raise ArgumentError, 'Block required' unless block_given?
|
120
120
|
|
121
121
|
once_block = proc do |*args|
|
122
|
-
off
|
123
|
-
yield
|
122
|
+
off(*self.class::STATE.map, &once_block)
|
123
|
+
yield(*args)
|
124
124
|
end
|
125
125
|
|
126
126
|
safe_unsafe_method options[:unsafe], :once, *self.class::STATE.map, &once_block
|
@@ -5,7 +5,7 @@ module Ably::Modules
|
|
5
5
|
# This can be removed once https://github.com/gocardless/statesman/issues/95 is solved
|
6
6
|
def before_transition(options = nil, &block)
|
7
7
|
arrayify_transition(options) do |options_without_from_array|
|
8
|
-
super
|
8
|
+
super(*options_without_from_array, &block)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -13,7 +13,7 @@ module Ably::Modules
|
|
13
13
|
# This can be removed once https://github.com/gocardless/statesman/issues/95 is solved
|
14
14
|
def after_transition(options = nil, &block)
|
15
15
|
arrayify_transition(options) do |options_without_from_array|
|
16
|
-
super
|
16
|
+
super(*options_without_from_array, &block)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -59,7 +59,9 @@ module Ably::Modules
|
|
59
59
|
def_delegators :state_machine, :can_transition_to?
|
60
60
|
|
61
61
|
private
|
62
|
-
|
62
|
+
def state_machine
|
63
|
+
@state_machine
|
64
|
+
end
|
63
65
|
|
64
66
|
def_delegators :state_machine, :exception_for_state_change_to
|
65
67
|
|
@@ -85,7 +87,7 @@ module Ably::Modules
|
|
85
87
|
|
86
88
|
module ClassMethods
|
87
89
|
def emits_klass
|
88
|
-
@emits_klass ||= if @emits_klass_name
|
90
|
+
@emits_klass ||= if defined?(@emits_klass_name) && @emits_klass_name
|
89
91
|
get_const(@emits_klass_name)
|
90
92
|
end
|
91
93
|
end
|