Module: DexieCable

Extended by:
ActiveSupport::Concern
Defined in:
lib/dexiecable.rb,
lib/dexiecable/query.rb,
lib/dexiecable/concern.rb,
lib/dexiecable/railtie.rb,
lib/dexiecable/version.rb,
lib/dexiecable/scoped_channel.rb,
lib/dexiecable/active_record_ext.rb

Defined Under Namespace

Modules: ActiveRecordExt Classes: Error, Query, Railtie, ScopedChannel

Constant Summary collapse

PUBLIC_STREAM_PREFIX =
"public:"
STREAM_TOKEN_PURPOSE =
"dexiecable:streams"
VERSION =
"2.0.2"

Instance Method Summary collapse

Instance Method Details

#add_stream(data) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/dexiecable/concern.rb', line 74

def add_stream(data)
  token = data["stream"].to_s
  params = data.except("action", "stream").with_indifferent_access

  if signed_token?(token)
    # A token that no longer resolves (expired, revoked, deleted record) is
    # rejected instead of being treated as a public stream name.
    record = resolve_subscribe_target(token)
    return unless record

    stream_for record
    subscribed_to(record, params)
  else
    return if token.blank?

    stream_from public_stream_name(token)
    subscribed_to(token, params)
  end
end

#remove_all_streams(_data) ⇒ Object



107
108
109
# File 'lib/dexiecable/concern.rb', line 107

def remove_all_streams(_data)
  stop_all_streams
end

#remove_stream(data) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/dexiecable/concern.rb', line 94

def remove_stream(data)
  token = data["stream"].to_s

  if signed_token?(token)
    record = resolve_subscribe_target(token)
    return unless record

    stop_stream_from self.class.broadcasting_for(record)
  else
    stop_stream_from public_stream_name(token) if token.present?
  end
end

#subscribedObject



70
71
72
# File 'lib/dexiecable/concern.rb', line 70

def subscribed
  # Streams are added dynamically via +add_stream+.
end

#subscribed_to(_record, _params) ⇒ Object

Override to push initial data when a stream is added. record is the resolved target — a record for private streams, or the stream name for public streams — and params are any extra params sent from the client.



114
115
# File 'lib/dexiecable/concern.rb', line 114

def subscribed_to(_record, _params)
end

#table(name) ⇒ Object

Build a query against a Dexie table, transmitted to all subscribers of this channel.



66
67
68
# File 'lib/dexiecable/concern.rb', line 66

def table(name)
  Query.new(self, name)
end