Class: Plushie::Subscription::Sub
- Inherits:
-
Data
- Object
- Data
- Plushie::Subscription::Sub
- Defined in:
- lib/plushie/subscription.rb
Overview
An immutable subscription specification.
Created via factory methods on Subscription rather than directly.
The runtime uses #key to diff subscriptions between cycles,
starting new ones and stopping removed ones automatically.
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#interval [Integer, nil] interval in milliseconds (only for :every)([Integer, nil]) ⇒ Object
readonly
An immutable subscription specification.
-
#max_rate ⇒ Object
readonly
Returns the value of attribute max_rate.
-
#max_rate [Integer, nil] maximum events per second (nil = unlimited)([Integer, nil](nil = unlimited)) ⇒ Object
readonly
An immutable subscription specification.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#tag [Symbol, nil] identifier for timer event correlation (timers only)([Symbol, nil]) ⇒ Object
readonly
An immutable subscription specification.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#type [Symbol] subscription type (:every, :on_key_press, etc.)([Symbol](: every, :on_key_press, etc.)) ⇒ Object
readonly
An immutable subscription specification.
-
#window_id ⇒ Object
readonly
Returns the value of attribute window_id.
-
#window_id [String, nil] window scope (nil = all windows)([String, nil](nil = all windows)) ⇒ Object
readonly
An immutable subscription specification.
Instance Method Summary collapse
-
#initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil) ⇒ Sub
constructor
A new instance of Sub.
-
#key ⇒ Array
Returns a key that uniquely identifies this subscription.
-
#wire_tag ⇒ String
Derive the wire tag sent to the renderer.
-
#with_max_rate(rate) ⇒ Sub
Set the maximum event rate (events per second).
Constructor Details
#initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil) ⇒ Sub
Returns a new instance of Sub.
32 33 34 |
# File 'lib/plushie/subscription.rb', line 32 def initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil) super end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval
31 32 33 |
# File 'lib/plushie/subscription.rb', line 31 def interval @interval end |
#interval [Integer, nil] interval in milliseconds (only for :every)([Integer, nil]) ⇒ Object (readonly)
An immutable subscription specification.
Created via factory methods on Subscription rather than directly.
The runtime uses #key to diff subscriptions between cycles,
starting new ones and stopping removed ones automatically.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/plushie/subscription.rb', line 31 Sub = Data.define(:type, :tag, :interval, :max_rate, :window_id) do def initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil) super end # Returns a key that uniquely identifies this subscription. # Used by the runtime to diff subscription lists between cycles. # Timer subs include the interval so that changing the interval # creates a new subscription rather than updating the existing one. # Renderer subs are keyed by type and window_id. # # @return [Array] unique identity tuple for this subscription def key if type == :every [:every, interval, tag] else [type, window_id] end end # Derive the wire tag sent to the renderer. Window-scoped # subscriptions include the window_id so they don't collide # with global subscriptions of the same kind. # # @return [String] def wire_tag kind = type.to_s window_id ? "#{kind}:#{window_id}" : kind end # Set the maximum event rate (events per second). # # @param rate [Integer] max events per second # @return [Sub] new Sub with the rate applied def with_max_rate(rate) self.class.new(**to_h.merge(max_rate: rate)) end end |
#max_rate ⇒ Object (readonly)
Returns the value of attribute max_rate
31 32 33 |
# File 'lib/plushie/subscription.rb', line 31 def max_rate @max_rate end |
#max_rate [Integer, nil] maximum events per second (nil = unlimited)([Integer, nil](nil = unlimited)) ⇒ Object (readonly)
An immutable subscription specification.
Created via factory methods on Subscription rather than directly.
The runtime uses #key to diff subscriptions between cycles,
starting new ones and stopping removed ones automatically.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/plushie/subscription.rb', line 31 Sub = Data.define(:type, :tag, :interval, :max_rate, :window_id) do def initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil) super end # Returns a key that uniquely identifies this subscription. # Used by the runtime to diff subscription lists between cycles. # Timer subs include the interval so that changing the interval # creates a new subscription rather than updating the existing one. # Renderer subs are keyed by type and window_id. # # @return [Array] unique identity tuple for this subscription def key if type == :every [:every, interval, tag] else [type, window_id] end end # Derive the wire tag sent to the renderer. Window-scoped # subscriptions include the window_id so they don't collide # with global subscriptions of the same kind. # # @return [String] def wire_tag kind = type.to_s window_id ? "#{kind}:#{window_id}" : kind end # Set the maximum event rate (events per second). # # @param rate [Integer] max events per second # @return [Sub] new Sub with the rate applied def with_max_rate(rate) self.class.new(**to_h.merge(max_rate: rate)) end end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag
31 32 33 |
# File 'lib/plushie/subscription.rb', line 31 def tag @tag end |
#tag [Symbol, nil] identifier for timer event correlation (timers only)([Symbol, nil]) ⇒ Object (readonly)
An immutable subscription specification.
Created via factory methods on Subscription rather than directly.
The runtime uses #key to diff subscriptions between cycles,
starting new ones and stopping removed ones automatically.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/plushie/subscription.rb', line 31 Sub = Data.define(:type, :tag, :interval, :max_rate, :window_id) do def initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil) super end # Returns a key that uniquely identifies this subscription. # Used by the runtime to diff subscription lists between cycles. # Timer subs include the interval so that changing the interval # creates a new subscription rather than updating the existing one. # Renderer subs are keyed by type and window_id. # # @return [Array] unique identity tuple for this subscription def key if type == :every [:every, interval, tag] else [type, window_id] end end # Derive the wire tag sent to the renderer. Window-scoped # subscriptions include the window_id so they don't collide # with global subscriptions of the same kind. # # @return [String] def wire_tag kind = type.to_s window_id ? "#{kind}:#{window_id}" : kind end # Set the maximum event rate (events per second). # # @param rate [Integer] max events per second # @return [Sub] new Sub with the rate applied def with_max_rate(rate) self.class.new(**to_h.merge(max_rate: rate)) end end |
#type ⇒ Object (readonly)
Returns the value of attribute type
31 32 33 |
# File 'lib/plushie/subscription.rb', line 31 def type @type end |
#type [Symbol] subscription type (:every, :on_key_press, etc.)([Symbol](: every, :on_key_press, etc.)) ⇒ Object (readonly)
An immutable subscription specification.
Created via factory methods on Subscription rather than directly.
The runtime uses #key to diff subscriptions between cycles,
starting new ones and stopping removed ones automatically.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/plushie/subscription.rb', line 31 Sub = Data.define(:type, :tag, :interval, :max_rate, :window_id) do def initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil) super end # Returns a key that uniquely identifies this subscription. # Used by the runtime to diff subscription lists between cycles. # Timer subs include the interval so that changing the interval # creates a new subscription rather than updating the existing one. # Renderer subs are keyed by type and window_id. # # @return [Array] unique identity tuple for this subscription def key if type == :every [:every, interval, tag] else [type, window_id] end end # Derive the wire tag sent to the renderer. Window-scoped # subscriptions include the window_id so they don't collide # with global subscriptions of the same kind. # # @return [String] def wire_tag kind = type.to_s window_id ? "#{kind}:#{window_id}" : kind end # Set the maximum event rate (events per second). # # @param rate [Integer] max events per second # @return [Sub] new Sub with the rate applied def with_max_rate(rate) self.class.new(**to_h.merge(max_rate: rate)) end end |
#window_id ⇒ Object (readonly)
Returns the value of attribute window_id
31 32 33 |
# File 'lib/plushie/subscription.rb', line 31 def window_id @window_id end |
#window_id [String, nil] window scope (nil = all windows)([String, nil](nil = all windows)) ⇒ Object (readonly)
An immutable subscription specification.
Created via factory methods on Subscription rather than directly.
The runtime uses #key to diff subscriptions between cycles,
starting new ones and stopping removed ones automatically.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/plushie/subscription.rb', line 31 Sub = Data.define(:type, :tag, :interval, :max_rate, :window_id) do def initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil) super end # Returns a key that uniquely identifies this subscription. # Used by the runtime to diff subscription lists between cycles. # Timer subs include the interval so that changing the interval # creates a new subscription rather than updating the existing one. # Renderer subs are keyed by type and window_id. # # @return [Array] unique identity tuple for this subscription def key if type == :every [:every, interval, tag] else [type, window_id] end end # Derive the wire tag sent to the renderer. Window-scoped # subscriptions include the window_id so they don't collide # with global subscriptions of the same kind. # # @return [String] def wire_tag kind = type.to_s window_id ? "#{kind}:#{window_id}" : kind end # Set the maximum event rate (events per second). # # @param rate [Integer] max events per second # @return [Sub] new Sub with the rate applied def with_max_rate(rate) self.class.new(**to_h.merge(max_rate: rate)) end end |
Instance Method Details
#key ⇒ Array
Returns a key that uniquely identifies this subscription. Used by the runtime to diff subscription lists between cycles. Timer subs include the interval so that changing the interval creates a new subscription rather than updating the existing one. Renderer subs are keyed by type and window_id.
43 44 45 46 47 48 49 |
# File 'lib/plushie/subscription.rb', line 43 def key if type == :every [:every, interval, tag] else [type, window_id] end end |
#wire_tag ⇒ String
Derive the wire tag sent to the renderer. Window-scoped subscriptions include the window_id so they don't collide with global subscriptions of the same kind.
56 57 58 59 |
# File 'lib/plushie/subscription.rb', line 56 def wire_tag kind = type.to_s window_id ? "#{kind}:#{window_id}" : kind end |
#with_max_rate(rate) ⇒ Sub
Set the maximum event rate (events per second).
65 66 67 |
# File 'lib/plushie/subscription.rb', line 65 def with_max_rate(rate) self.class.new(**to_h.merge(max_rate: rate)) end |