extension_cable 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8e82701171a978a8d05bfdf9a494b18817f8549a0e130ddd497d98e8cd3462b6
4
+ data.tar.gz: 2156a7a4ec6dd84764f547caf01072f31fc4633e628771c7d5605b7be81ed8cf
5
+ SHA512:
6
+ metadata.gz: 1657057743f328474958f1583de5c671325f2ca5a82b3a0a7f59a1d791dc29efa702413bedcc7d2d1bf876cfdb5a2d2c1a2f28a5f57a0073947554918513b9ff
7
+ data.tar.gz: a65e6f8c3fdbd5563b60dbcbab2bc214a17012cd927867a83bf4514d65548deb8a92eb3a1d5f1996d48b43c74b7fc2228a3bdeac3f55dacee90fee845bddd93c
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.3.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Will Bryant
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # ExtensionCable
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/extension_cable`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/extension_cable.
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake'
5
+ require 'rake/testtask'
6
+
7
+ desc 'Default: run unit tests.'
8
+ task :default => :test
9
+
10
+ desc 'Test the constant_table_saver plugin.'
11
+ Rake::TestTask.new(:test) do |t|
12
+ t.libs << 'lib'
13
+ t.libs << 'test'
14
+ t.pattern = 'test/*_test.rb'
15
+ t.verbose = true
16
+ t.warning = false
17
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/extension_cable/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "extension_cable"
7
+ spec.version = ExtensionCable::VERSION
8
+ spec.authors = ["Will Bryant"]
9
+ spec.email = ["will.bryant@gmail.com"]
10
+
11
+ spec.summary = "Add a second ActionCable PubSub adapter"
12
+ spec.description = "Allows you to use two ActionCable PubSub adapters in one app."
13
+ spec.homepage = "https://github.com/DelivereasyNZ/extension_cable"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/DelivereasyNZ/extension_cable.git"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (File.expand_path(f) == __FILE__) ||
25
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git Gemfile])
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "actioncable"
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ExtensionCable
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "action_cable"
4
+
5
+ require_relative "extension_cable/version"
6
+
7
+ class ExtensionCable
8
+ include ActionCable::Server::Broadcasting
9
+
10
+ ActiveSupport.on_load(:action_cable) do
11
+ app = Rails.application
12
+ app.paths.add "config/extension_cable", with: "config/extension_cable.yml"
13
+ if (config_path = Pathname.new(app.config.paths["config/extension_cable"].first)).exist?
14
+ ExtensionCable.config = app.config_for(config_path).to_h.with_indifferent_access
15
+ end
16
+ end
17
+
18
+ # We don't really run a "server" as such, as we don't serve any HTTP endpoints or run our own threads.
19
+ # But for the ease of porting existing application code, let's use the same nomenclature as ActionCable.
20
+ def self.server
21
+ @server ||= new
22
+ end
23
+
24
+ cattr_accessor :config
25
+
26
+ delegate :mutex, :logger, :event_loop, to: "ActionCable.server"
27
+
28
+ def config
29
+ # Reuse the pubsub_adapter logic from ActionCable to get the nice require behavior and constantizing fudges
30
+ @config ||= ActionCable::Server::Configuration.new.tap do |config|
31
+ config.cable = self.class.config
32
+ end
33
+ end
34
+
35
+ def pubsub
36
+ @pubsub || mutex.synchronize { @pubsub ||= config.pubsub_adapter.new(self) }
37
+ end
38
+
39
+ module Channel
40
+ extend ActiveSupport::Concern
41
+
42
+ included do
43
+ delegate :broadcast_to, to: :class
44
+ end
45
+
46
+ # This redefinition changes the implementation of stream_from and stream_for so that they stream from the
47
+ # ExtensionCable pubsub adapter, instead of the default ActionCable pubsub adapter.
48
+ def pubsub
49
+ ExtensionCable.server.pubsub
50
+ end
51
+
52
+ module ClassMethods
53
+ # Broadcast a hash to a unique broadcasting for this <tt>model</tt> in this channel.
54
+ def broadcast_to(model, message)
55
+ ExtensionCable.server.broadcast(broadcasting_for(model), message)
56
+ end
57
+ end
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: extension_cable
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Will Bryant
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actioncable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Allows you to use two ActionCable PubSub adapters in one app.
28
+ email:
29
+ - will.bryant@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".tool-versions"
35
+ - LICENSE.txt
36
+ - README.md
37
+ - Rakefile
38
+ - extension_cable.gemspec
39
+ - lib/extension_cable.rb
40
+ - lib/extension_cable/version.rb
41
+ homepage: https://github.com/DelivereasyNZ/extension_cable
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ homepage_uri: https://github.com/DelivereasyNZ/extension_cable
46
+ source_code_uri: https://github.com/DelivereasyNZ/extension_cable.git
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.6.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.5.22
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Add a second ActionCable PubSub adapter
66
+ test_files: []