Muskrat 0.1.0.pre

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: 653675baa0713e797a6314cbf178a78843dbc7f773b85d241eb0ed21f3c4c74f
4
+ data.tar.gz: 5f9e31a66b8f19b979f8b530ab014c6a09d441a5bc4740f35d9e82c4e608f8f7
5
+ SHA512:
6
+ metadata.gz: ee0d4bd3f158049a04e1d71d7a54a703e33464e15938e74dacea2a6b3881fd8dac1bc0b2f7a2658fa3859991152683c9a35a5a9258dc91a1c64852db6d74f62c
7
+ data.tar.gz: a76baecd1371078ef167a291fbb2abbcb18a5877261e60f09bb440d767a2cf80fcb93adcfc107de1015097c871f0088a288cd2012da13945012a78787888dbb2
@@ -0,0 +1,20 @@
1
+ # https://circleci.com/docs/2.0/configuration-reference/, for more info on how to get started.
2
+
3
+ version: 2.1
4
+
5
+ orbs:
6
+ ruby: circleci/ruby@0.1.2
7
+
8
+ jobs:
9
+ build:
10
+ docker:
11
+ - image: circleci/ruby:2.6.3-stretch-node
12
+ steps:
13
+ - checkout
14
+ - run:
15
+ name: Install bundler
16
+ command: gem install bundler -v '2.0.2'
17
+ - ruby/bundle-install
18
+ - run:
19
+ name: Run rspec tests
20
+ command: bundle exec rake spec
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at TODO: Write your email address. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in muskrat.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "rspec", '~> 3.9.0'
8
+ end
9
+
10
+ group :development, :test do
11
+ gem "rails", '~> 5.2.4.1'
12
+ gem "pry-byebug", platforms: :mri
13
+ gem "standard"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,172 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ Muskrat (0.1.0.pre)
5
+ mqtt (~> 0.5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (5.2.4.1)
11
+ actionpack (= 5.2.4.1)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailer (5.2.4.1)
15
+ actionpack (= 5.2.4.1)
16
+ actionview (= 5.2.4.1)
17
+ activejob (= 5.2.4.1)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.2.4.1)
21
+ actionview (= 5.2.4.1)
22
+ activesupport (= 5.2.4.1)
23
+ rack (~> 2.0, >= 2.0.8)
24
+ rack-test (>= 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.2.4.1)
28
+ activesupport (= 5.2.4.1)
29
+ builder (~> 3.1)
30
+ erubi (~> 1.4)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.2.4.1)
34
+ activesupport (= 5.2.4.1)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.2.4.1)
37
+ activesupport (= 5.2.4.1)
38
+ activerecord (5.2.4.1)
39
+ activemodel (= 5.2.4.1)
40
+ activesupport (= 5.2.4.1)
41
+ arel (>= 9.0)
42
+ activestorage (5.2.4.1)
43
+ actionpack (= 5.2.4.1)
44
+ activerecord (= 5.2.4.1)
45
+ marcel (~> 0.3.1)
46
+ activesupport (5.2.4.1)
47
+ concurrent-ruby (~> 1.0, >= 1.0.2)
48
+ i18n (>= 0.7, < 2)
49
+ minitest (~> 5.1)
50
+ tzinfo (~> 1.1)
51
+ arel (9.0.0)
52
+ ast (2.4.0)
53
+ builder (3.2.4)
54
+ byebug (11.0.1)
55
+ coderay (1.1.2)
56
+ concurrent-ruby (1.1.5)
57
+ crass (1.0.5)
58
+ diff-lcs (1.3)
59
+ erubi (1.9.0)
60
+ globalid (0.4.2)
61
+ activesupport (>= 4.2.0)
62
+ i18n (1.8.1)
63
+ concurrent-ruby (~> 1.0)
64
+ jaro_winkler (1.5.4)
65
+ loofah (2.4.0)
66
+ crass (~> 1.0.2)
67
+ nokogiri (>= 1.5.9)
68
+ mail (2.7.1)
69
+ mini_mime (>= 0.1.1)
70
+ marcel (0.3.3)
71
+ mimemagic (~> 0.3.2)
72
+ method_source (0.9.2)
73
+ mimemagic (0.3.3)
74
+ mini_mime (1.0.2)
75
+ mini_portile2 (2.4.0)
76
+ minitest (5.14.0)
77
+ mqtt (0.5.0)
78
+ nio4r (2.5.2)
79
+ nokogiri (1.10.7)
80
+ mini_portile2 (~> 2.4.0)
81
+ parallel (1.19.1)
82
+ parser (2.7.0.2)
83
+ ast (~> 2.4.0)
84
+ pry (0.12.2)
85
+ coderay (~> 1.1.0)
86
+ method_source (~> 0.9.0)
87
+ pry-byebug (3.7.0)
88
+ byebug (~> 11.0)
89
+ pry (~> 0.10)
90
+ rack (2.1.1)
91
+ rack-test (1.1.0)
92
+ rack (>= 1.0, < 3)
93
+ rails (5.2.4.1)
94
+ actioncable (= 5.2.4.1)
95
+ actionmailer (= 5.2.4.1)
96
+ actionpack (= 5.2.4.1)
97
+ actionview (= 5.2.4.1)
98
+ activejob (= 5.2.4.1)
99
+ activemodel (= 5.2.4.1)
100
+ activerecord (= 5.2.4.1)
101
+ activestorage (= 5.2.4.1)
102
+ activesupport (= 5.2.4.1)
103
+ bundler (>= 1.3.0)
104
+ railties (= 5.2.4.1)
105
+ sprockets-rails (>= 2.0.0)
106
+ rails-dom-testing (2.0.3)
107
+ activesupport (>= 4.2.0)
108
+ nokogiri (>= 1.6)
109
+ rails-html-sanitizer (1.3.0)
110
+ loofah (~> 2.3)
111
+ railties (5.2.4.1)
112
+ actionpack (= 5.2.4.1)
113
+ activesupport (= 5.2.4.1)
114
+ method_source
115
+ rake (>= 0.8.7)
116
+ thor (>= 0.19.0, < 2.0)
117
+ rainbow (3.0.0)
118
+ rake (13.0.1)
119
+ rspec (3.9.0)
120
+ rspec-core (~> 3.9.0)
121
+ rspec-expectations (~> 3.9.0)
122
+ rspec-mocks (~> 3.9.0)
123
+ rspec-core (3.9.0)
124
+ rspec-support (~> 3.9.0)
125
+ rspec-expectations (3.9.0)
126
+ diff-lcs (>= 1.2.0, < 2.0)
127
+ rspec-support (~> 3.9.0)
128
+ rspec-mocks (3.9.0)
129
+ diff-lcs (>= 1.2.0, < 2.0)
130
+ rspec-support (~> 3.9.0)
131
+ rspec-support (3.9.0)
132
+ rubocop (0.77.0)
133
+ jaro_winkler (~> 1.5.1)
134
+ parallel (~> 1.10)
135
+ parser (>= 2.6)
136
+ rainbow (>= 2.2.2, < 4.0)
137
+ ruby-progressbar (~> 1.7)
138
+ unicode-display_width (>= 1.4.0, < 1.7)
139
+ rubocop-performance (1.5.2)
140
+ rubocop (>= 0.71.0)
141
+ ruby-progressbar (1.10.1)
142
+ sprockets (4.0.0)
143
+ concurrent-ruby (~> 1.0)
144
+ rack (> 1, < 3)
145
+ sprockets-rails (3.2.1)
146
+ actionpack (>= 4.0)
147
+ activesupport (>= 4.0)
148
+ sprockets (>= 3.0.0)
149
+ standard (0.1.7)
150
+ rubocop (~> 0.77.0)
151
+ rubocop-performance (~> 1.5.1)
152
+ thor (1.0.1)
153
+ thread_safe (0.3.6)
154
+ tzinfo (1.2.6)
155
+ thread_safe (~> 0.1)
156
+ unicode-display_width (1.6.0)
157
+ websocket-driver (0.7.1)
158
+ websocket-extensions (>= 0.1.0)
159
+ websocket-extensions (0.1.4)
160
+
161
+ PLATFORMS
162
+ ruby
163
+
164
+ DEPENDENCIES
165
+ Muskrat!
166
+ pry-byebug
167
+ rails (~> 5.2.4.1)
168
+ rspec (~> 3.9.0)
169
+ standard
170
+
171
+ BUNDLED WITH
172
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 TODO: Write your name
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,41 @@
1
+ # Muskrat β
2
+
3
+ Under Active Development :rocket:
4
+
5
+ ## Ci Status
6
+
7
+ [![CircleCi](https://circleci.com/gh/midhunkrishna/muskrat.svg?style=svg)](https://circleci.com/gh/midhunkrishna/muskrat)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'muskrat'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install muskrat
24
+
25
+ ## Development
26
+
27
+ 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.
28
+
29
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/midhunkrishna/muskrat. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the Muskrat project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/midhunkrishna/muskrat/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rake/testtask"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "muskrat"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/muskrat ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/muskrat/cli'
4
+
5
+ begin
6
+ cli = Muskrat::CLI.new
7
+ cli.parse
8
+ rescue => e
9
+ STDERR.puts e.message
10
+ STDERR.puts e.backtrace.join("\n")
11
+ exit 1
12
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/muskrat.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'muskrat/version'
2
+ require 'muskrat/subscriber'
3
+
4
+ module Muskrat
5
+ DEFAULTS = {
6
+ subscriptions: [],
7
+ concurrency: 10,
8
+ }.freeze
9
+
10
+ def self.options
11
+ @options ||= DEFAULTS.dup
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ require 'muskrat'
2
+ require 'muskrat/configurer'
3
+ require 'muskrat/env'
4
+
5
+ module Muskrat
6
+ class CLI
7
+ def parse(args=ARGV)
8
+ populate_options(args)
9
+ @env = load_requireable_env
10
+ end
11
+
12
+
13
+ private
14
+
15
+ def launch
16
+ end
17
+
18
+ def options
19
+ Muskrat.options
20
+ end
21
+
22
+ def populate_options(args)
23
+ options.merge!(Muskrat::Configurer.parse_from_cli(args))
24
+ end
25
+
26
+ def load_requireable_env
27
+ env = Muskrat::Env.new(options)
28
+ env.load
29
+ env
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ require 'muskrat'
2
+ require 'mqtt'
3
+
4
+ module Muskrat
5
+ class Client
6
+ def initialize
7
+ @client = MQTT::Client.connect(connection_options)
8
+ end
9
+
10
+ def publish_async
11
+ end
12
+
13
+ def publish
14
+ end
15
+
16
+ private
17
+
18
+ def connection_options
19
+ options = Muskrat.options[:mqtt] || {}.reject do |_, value|
20
+ value.nil? || value.empty?
21
+ end
22
+
23
+ {
24
+ host: 'localhost',
25
+ post: 1833
26
+ }.merge(options)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,70 @@
1
+ require 'optparse'
2
+ require 'yaml'
3
+
4
+ require 'muskrat/logger'
5
+
6
+ module Muskrat
7
+ class Configurer
8
+ attr_reader :options
9
+
10
+ CONFIG_FILE_NOT_FOUND='Configuration file not found. Muskrat will fallback to default configurations'.freeze
11
+
12
+ def self.parse_from_cli(args)
13
+ @options = parse_options(args)
14
+ load_config(@options)
15
+ @options
16
+ end
17
+
18
+ def self.reconcile_subscription(opts, subscription)
19
+ topics = Array(subscription[:topic]).map(&:to_sym)
20
+
21
+ config = opts[:subscriber_config].dup || {}
22
+
23
+ topics.each do | topic |
24
+ config[topic] ||= []
25
+
26
+ config[topic].push({
27
+ klass: subscription[:subscriber]
28
+ })
29
+ end
30
+
31
+ { subscriber_config: config }
32
+ end
33
+
34
+ private
35
+
36
+ private_class_method def self.parse_options(args, opts={})
37
+ parser = OptionParser.new do |o|
38
+ o.on "-C", "--config PATH[FILE]", "path to yaml config file" do |arg|
39
+ opts[:config_file] = arg
40
+ end
41
+
42
+ o.on "-R", "--require PATH[DIR|FILE]", "path to Rails root or main file" do |arg|
43
+ opts[:require] = arg
44
+ end
45
+
46
+ o.on "-e", "--environment STR", "your application environment" do |arg|
47
+ opts[:environment] = arg
48
+ end
49
+ end
50
+
51
+ parser.banner = "Muskrat /options/"
52
+ parser.on_tail "-h", "--help", "Show Help" do
53
+ puts parser
54
+ exit 1
55
+ end
56
+
57
+ parser.parse!(args)
58
+ opts
59
+ end
60
+
61
+ private_class_method def self.load_config(opts)
62
+ file_path = opts[:config_file]
63
+ if file_path && File.exist?(file_path)
64
+ opts[:config] = YAML.load(File.read(file_path))
65
+ else
66
+ Muskrat::Logger.log(CONFIG_FILE_NOT_FOUND)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,48 @@
1
+ require 'muskrat/rails_reloader'
2
+
3
+ module Muskrat
4
+ class Env
5
+ DEVELOPMENT='development'.freeze
6
+ RAILS_VERSION_NOT_SUPPORTED='Muskrat only supports Rails version 5 or above.'.freeze
7
+
8
+ attr_reader :options
9
+
10
+ def initialize(options)
11
+ @options = options
12
+ set_execution_env(options[:environment])
13
+ @path = options[:require] || gather_from_fs
14
+ end
15
+
16
+ def load
17
+ load_environment
18
+ end
19
+
20
+
21
+ private
22
+
23
+ def set_execution_env(env_str)
24
+ ENV['RAILS_ENV'] = ENV['RACK_ENV'] = env_str if env_str
25
+ end
26
+
27
+ def load_environment
28
+ if File.directory?(@path)
29
+ require "rails"
30
+ if ::Rails::VERSION::MAJOR < 5
31
+ raise RAILS_VERSION_NOT_SUPPORTED
32
+ else
33
+ require ::File.expand_path('config/environment', @path)
34
+ require "muskrat/rails_reloader"
35
+
36
+ options[:reloader] = Muskrat::RailsReloader.new(::Rails.application)
37
+ end
38
+ else
39
+ require "#{@path}"
40
+ end
41
+ end
42
+
43
+ def gather_from_fs
44
+ pwd = Dir.pwd
45
+ return pwd if File.exist?("#{pwd}/config/application.rb")
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,11 @@
1
+ module Muskrat
2
+ class Logger
3
+ class << self
4
+ $stdout.sync = true
5
+
6
+ def log(str)
7
+ puts str
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Muskrat
2
+ class RailsReloader
3
+ # https://guides.rubyonrails.org/threading_and_code_execution.html#reloader
4
+
5
+ # Rails seperates application code and framework code using Rails Executor.
6
+ # Each thread is advised to be wrapped inside Rails Executor before it runs application code.
7
+ # For long running framework processes, in this case Muskrat, it is advised to use Reloader.
8
+
9
+ def initialize(app)
10
+ @app = app
11
+ end
12
+
13
+ def call
14
+ @app.reloader.wrap do
15
+ yield
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ require 'muskrat'
2
+ require 'muskrat/client'
3
+ require 'muskrat/configurer'
4
+
5
+ module Muskrat
6
+ module Subscriber
7
+ TOPIC_NOT_SPECIFIED='%{klass} not subscribed to any topic.'.freeze
8
+
9
+ module ClassMethods
10
+ def publish(*args)
11
+ end
12
+
13
+ def subscribe(*args)
14
+ topic = args.first&.[](:topic) || args.first&.[]("topic")
15
+
16
+ raise TOPIC_NOT_SPECIFIED % {klass: self.name} unless topic
17
+
18
+ Muskrat.options.merge!(
19
+ Muskrat::Configurer.reconcile_subscription(
20
+ Muskrat.options,
21
+ { subscriber: self.name, topic: topic }
22
+ )
23
+ )
24
+ end
25
+ end
26
+
27
+ def self.included(base)
28
+ base.extend(ClassMethods)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Muskrat
2
+ VERSION = "0.1.0.pre"
3
+ end
data/muskrat.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "muskrat/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "Muskrat"
7
+ spec.version = Muskrat::VERSION
8
+ spec.authors = ["Midhun Krishna"]
9
+ spec.email = ["reachme@midhunkrishna.in"]
10
+
11
+ spec.summary = %q{Simple mqtt message processor.}
12
+ spec.description = %q{mqtt pub-sub message processor for Ruby.}
13
+ spec.homepage = "https://midhunkrishna.in/muskrat"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+
18
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
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
+
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
25
+ end
26
+
27
+ spec.executables = ["muskrat"]
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.required_ruby_version = ">= 2.5.0"
31
+
32
+ spec.add_dependency "mqtt", "~> 0.5.0"
33
+ end
data/todo.md ADDED
@@ -0,0 +1,12 @@
1
+ ## Todo
2
+
3
+ - [ ] - Client interface
4
+ - [ ] - Server configuration setup
5
+ - [ ] - Thread monitors
6
+ - [ ] - Threaded workers
7
+ - [ ] - Interrupt handlers
8
+ - [ ] - Exception management
9
+ - [ ] - Retry mechanism
10
+ - [ ] - Graceful shutdown
11
+ - [ ] - Telemetry
12
+ - [ ] - Web Interface
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Muskrat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Midhun Krishna
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mqtt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.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.5.0
27
+ description: mqtt pub-sub message processor for Ruby.
28
+ email:
29
+ - reachme@midhunkrishna.in
30
+ executables:
31
+ - muskrat
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".circleci/config.yml"
36
+ - ".gitignore"
37
+ - ".rspec"
38
+ - ".travis.yml"
39
+ - CODE_OF_CONDUCT.md
40
+ - Gemfile
41
+ - Gemfile.lock
42
+ - LICENSE.txt
43
+ - README.md
44
+ - Rakefile
45
+ - bin/console
46
+ - bin/muskrat
47
+ - bin/setup
48
+ - lib/muskrat.rb
49
+ - lib/muskrat/cli.rb
50
+ - lib/muskrat/client.rb
51
+ - lib/muskrat/configurer.rb
52
+ - lib/muskrat/env.rb
53
+ - lib/muskrat/logger.rb
54
+ - lib/muskrat/rails_reloader.rb
55
+ - lib/muskrat/subscriber.rb
56
+ - lib/muskrat/version.rb
57
+ - muskrat.gemspec
58
+ - todo.md
59
+ homepage: https://midhunkrishna.in/muskrat
60
+ licenses:
61
+ - MIT
62
+ metadata:
63
+ homepage_uri: https://midhunkrishna.in/muskrat
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 2.5.0
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">"
76
+ - !ruby/object:Gem::Version
77
+ version: 1.3.1
78
+ requirements: []
79
+ rubygems_version: 3.0.6
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Simple mqtt message processor.
83
+ test_files: []