cable_x 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 76917008d7ce08585ee10c4920f94f7fea9e52fcd04f031617cc94689f7034f1
4
+ data.tar.gz: ea77fe44decf6ce838664e1af8a4c71680274b31fb6119c8af8c2592c1692f59
5
+ SHA512:
6
+ metadata.gz: 6bcec2f189429bc13d423c35b67cc496f4d40894439a1c81ac5fe437ea1c94909d9665f811ddc6298e4e4fb316985bce15494fe96fe9cc340f5e4208cb7d490e
7
+ data.tar.gz: 1ed2df1944dc39fadee3ded7de04f489574e54e7d82d8c252a883065aae964dbaa37dec34b7c1a6d7792d7e44ad9c2c9fbd5113f54d7b5059b7d0bc0efaa499c
@@ -0,0 +1,20 @@
1
+ Copyright 2020 Nitesh Purohit
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # CableX
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'cable_x'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install cable_x
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rdoc/task'
10
+
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = 'rdoc'
13
+ rdoc.title = 'CableX'
14
+ rdoc.options << '--line-numbers'
15
+ rdoc.rdoc_files.include('README.md')
16
+ rdoc.rdoc_files.include('lib/**/*.rb')
17
+ end
18
+
19
+ APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
20
+ load 'rails/tasks/engine.rake'
21
+
22
+ load 'rails/tasks/statistics.rake'
23
+
24
+ require 'bundler/gem_tasks'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_cable'
4
+ require 'rails'
5
+ require_relative 'cable_x/engine'
6
+ require_relative 'cable_x/server'
7
+ require_relative 'cable_x/version'
8
+ require_relative 'cable_x/channel/cable_x_channel'
9
+ module CableX
10
+ class Error < StandardError; end
11
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CableX
4
+ module Cable
5
+ # Channel for realtime updates
6
+ class Channel < ActionCable::Channel::Base
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CableX
4
+ module Cable
5
+ ##
6
+ # Connection class to serve entry point
7
+ class Connection < ActionCable::Connection::Base
8
+ attr_accessor :device_id
9
+ identified_by :device_id
10
+
11
+ def connect
12
+ self.device_id = SecureRandom.hex(20)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../cable/channel'
4
+ require_relative './process/controller'
5
+ require_relative './process/request'
6
+ require_relative './process/response'
7
+ module CableX
8
+ module Channel
9
+ ##
10
+ # CableXChannel class to serve subscription, and cmd execution
11
+ class CableXChannel < Cable::Channel
12
+ include Channel::Process::Controller
13
+ include Channel::Process::Request
14
+ include Channel::Process::Response
15
+
16
+ attr_reader :data, :request, :response, :controller_action_hash, :ctrl, :request_id, :response_body
17
+
18
+ def subscribed
19
+ reject unless device_id.present?
20
+ stream_from device_id
21
+ end
22
+
23
+ def unsubscribed; end
24
+
25
+ def cmd(data)
26
+ @data = data
27
+ invoke_controller
28
+ prepare_response
29
+ transmit response_body, via: device_id
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CableX
4
+ module Channel
5
+ module Process
6
+ ##
7
+ # Process controller specific tasks
8
+ module Controller
9
+ def set_controller
10
+ set_controller_hash
11
+ end
12
+
13
+ def invoke_controller
14
+ set_controller
15
+ set_request
16
+ set_response
17
+ controller_klass.dispatch(controller_action_hash[:action], request, response)
18
+ end
19
+
20
+ def set_controller_hash
21
+ @controller_action_hash = Rails.application.routes.recognize_path data['path'], { method: data['method'] }
22
+ end
23
+
24
+ def controller_klass
25
+ controller_klass_name = controller_action_hash[:controller].split('/').map(&:camelize).join('::')
26
+ "#{controller_klass_name}Controller".constantize
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CableX
4
+ module Channel
5
+ module Process
6
+ ##
7
+ # Process request specific tasks
8
+ module Request
9
+ def set_request
10
+ @request_id = data['request_id']
11
+ @request = ActionDispatch::Request.new({})
12
+ @request.headers = data['headers'] if data['headers']
13
+ @request.request_parameters = controller_action_hash.merge(data['params'] || {}).merge(data['data'] || {})
14
+ @request.request_method = data['method'].upcase
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CableX
4
+ module Channel
5
+ module Process
6
+ ##
7
+ # Process response specific tasks
8
+ module Response
9
+ def set_response
10
+ @response = ActionDispatch::Response.new
11
+ end
12
+
13
+ def prepare_response
14
+ @response_body = { request_id: request_id, body: response.body, code: response.code, headers: response.headers.to_h }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+ require 'active_support/rails'
5
+ require_relative 'server'
6
+ require_relative 'cable/connection'
7
+ module CableX
8
+ ##
9
+ # CableX Engine
10
+ class Engine < ::Rails::Engine
11
+ attr_accessor :allowed_request_origins
12
+ isolate_namespace CableX
13
+
14
+ def self.server
15
+ config = Rails.application.config_for(:cable_x) rescue nil
16
+ self.allowed_request_origins = config[:allowed_request_origins] if config
17
+ server = CableX::Server.server
18
+ server.config.connection_class = -> { CableX::Cable::Connection }
19
+ server.config.allowed_request_origins = allowed_request_origins
20
+ server
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CableX
4
+ ##
5
+ # CableX ActionCable server module
6
+ module Server
7
+ extend ActionCable
8
+
9
+ def self.server
10
+ @server ||= ActionCable::Server::Base.new
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CableX
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate install Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CableX
4
+ ##
5
+ # Install generator
6
+ class InstallGenerator < Rails::Generators::Base
7
+ source_root File.expand_path('templates', __dir__)
8
+
9
+ def create_install_file
10
+ route('mount CableX::Engine.server => "/cable_x"')
11
+ template 'cable_x_yml.rb.tt', File.join('config', 'cable_x.yml')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ ###
2
+ # Set origins appropriately, is follows standard action cable format for allowed_request_origins
3
+ ###
4
+ production:
5
+ ##TODO edit me
6
+ allowed_request_origins: <%= ENV.fetch("CABLE_X_ALLOWED_REQUEST_ORIGINS") { "http://127.0.0.1:3000/cable_x" } %>
7
+ development:
8
+ allowed_request_origins: <%= ENV.fetch("CABLE_X_ALLOWED_REQUEST_ORIGINS") { "http://127.0.0.1:3000/cable_x" } %>
9
+ test:
10
+ allowed_request_origins: <%= ENV.fetch("CABLE_X_ALLOWED_REQUEST_ORIGINS") { "http://127.0.0.1:3000/cable_x" } %>
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ # desc "Explaining what the task does"
3
+ # task :cable_x do
4
+ # # Task goes here
5
+ # end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cable_x
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nitesh Purohit
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.23
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.23
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 4.0.0
55
+ description: Standard MVC over cable for realtime applications to enjoy seamless experience
56
+ over cable. Use specialized clients for Android, IOS, Angular, React, JS
57
+ email:
58
+ - nitesh.purohit.it@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - MIT-LICENSE
64
+ - README.md
65
+ - Rakefile
66
+ - lib/cable_x.rb
67
+ - lib/cable_x/cable/channel.rb
68
+ - lib/cable_x/cable/connection.rb
69
+ - lib/cable_x/channel/cable_x_channel.rb
70
+ - lib/cable_x/channel/process/controller.rb
71
+ - lib/cable_x/channel/process/request.rb
72
+ - lib/cable_x/channel/process/response.rb
73
+ - lib/cable_x/engine.rb
74
+ - lib/cable_x/server.rb
75
+ - lib/cable_x/version.rb
76
+ - lib/generators/cable_x/install/USAGE
77
+ - lib/generators/cable_x/install/install_generator.rb
78
+ - lib/generators/cable_x/install/templates/cable_x_yml.rb.tt
79
+ - lib/tasks/cable_x_tasks.rake
80
+ homepage: https://github.com/Code-Vedas/rails-cable-x
81
+ licenses:
82
+ - MIT
83
+ metadata:
84
+ homepage_uri: https://github.com/Code-Vedas/rails-cable-x
85
+ source_code_uri: https://github.com/Code-Vedas/rails-cable-x
86
+ changelog_uri: https://github.com/Code-Vedas/rails-cable-x
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 2.3.0
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 1.8.11
101
+ requirements: []
102
+ rubygems_version: 3.0.3
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Standard MVC over cable for realtime applications to enjoy seamless experience
106
+ over cable
107
+ test_files: []