dark_prism 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7efcf3e45ce341969e99fd29685210d5b1fc9b2d
4
+ data.tar.gz: c6a0994916aceb1ecd24a7ae0cb852e712c640f4
5
+ SHA512:
6
+ metadata.gz: 8092500d2860d424102f3491a96149991770489978894c0bd3a90dc4077a0e2b30d1edfa2d9e5cd2870dcc4e2eb587dbc5b0e8520690c7742c00769d42703a77
7
+ data.tar.gz: c38bf36557cca2fdc18dfe198e29ad33f584ca4e6c341203e4d0f22eb587a784a411b875ba2d9dd76b395f44b13b39d1c78af78e1235ee97d71e53cabe6579ba
data/.codeclimate.yml ADDED
@@ -0,0 +1,21 @@
1
+
2
+ version: "2"
3
+ plugins:
4
+ flog:
5
+ enabled: true
6
+ config:
7
+ score_threshold: 20.0
8
+ rubocop:
9
+ enabled: true
10
+ reek:
11
+ enabled: true
12
+ duplication:
13
+ enabled: true
14
+ config:
15
+ languages:
16
+ ruby:
17
+ mass_threshold: 35
18
+ exclude_patterns:
19
+ - coverage/
20
+ - docs/
21
+ - spec/
data/.editorconfig ADDED
@@ -0,0 +1,22 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [Rakefile]
12
+ indent_style=space
13
+ indent_size=2
14
+ trim_trailing_whitespace = true
15
+
16
+ [*.rb]
17
+ indent_style=space
18
+ indent_size=2
19
+ trim_trailing_whitespace = true
20
+
21
+ [*.{sh,markdown}]
22
+ indent_size = 4
data/.gitignore ADDED
@@ -0,0 +1,278 @@
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
+
13
+ ### Linux ###
14
+ *~
15
+
16
+ # temporary files which can be created if a process still has a handle open of a deleted file
17
+ .fuse_hidden*
18
+
19
+ # KDE directory preferences
20
+ .directory
21
+
22
+ # Linux trash folder which might appear on any partition or disk
23
+ .Trash-*
24
+
25
+ # .nfs files are created when an open file is removed but is still being accessed
26
+ .nfs*
27
+
28
+ ### OSX ###
29
+ *.DS_Store
30
+ .AppleDouble
31
+ .LSOverride
32
+
33
+ # Icon must end with two \r
34
+ Icon
35
+
36
+ # Thumbnails
37
+ ._*
38
+
39
+ # Files that might appear in the root of a volume
40
+ .DocumentRevisions-V100
41
+ .fseventsd
42
+ .Spotlight-V100
43
+ .TemporaryItems
44
+ .Trashes
45
+ .VolumeIcon.icns
46
+ .com.apple.timemachine.donotpresent
47
+
48
+ # Directories potentially created on remote AFP share
49
+ .AppleDB
50
+ .AppleDesktop
51
+ Network Trash Folder
52
+ Temporary Items
53
+ .apdisk
54
+
55
+ ### Ruby ###
56
+ *.gem
57
+ *.rbc
58
+ /.config
59
+ /coverage/
60
+ /InstalledFiles
61
+ /pkg/
62
+ /spec/reports/
63
+ /spec/examples.txt
64
+ /test/tmp/
65
+ /test/version_tmp/
66
+ /tmp/
67
+
68
+ # Used by dotenv library to load environment variables.
69
+ # .env
70
+
71
+ ## Specific to RubyMotion:
72
+ .dat*
73
+ .repl_history
74
+ build/
75
+ *.bridgesupport
76
+ build-iPhoneOS/
77
+ build-iPhoneSimulator/
78
+
79
+ ## Specific to RubyMotion (use of CocoaPods):
80
+ #
81
+ # We recommend against adding the Pods directory to your .gitignore. However
82
+ # you should judge for yourself, the pros and cons are mentioned at:
83
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
84
+ #
85
+ # vendor/Pods/
86
+
87
+ ## Documentation cache and generated files:
88
+ /.yardoc/
89
+ /_yardoc/
90
+ /doc/
91
+ /rdoc/
92
+
93
+ ## Environment normalization:
94
+ /.bundle/
95
+ /vendor/bundle
96
+ /lib/bundler/man/
97
+
98
+ # for a library or gem, you might want to ignore these files since the code is
99
+ # intended to run in multiple environments; otherwise, check them in:
100
+ # Gemfile.lock
101
+ # .ruby-version
102
+ # .ruby-gemset
103
+
104
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
105
+ .rvmrc
106
+
107
+ ### RubyMine ###
108
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
109
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
110
+
111
+ # User-specific stuff:
112
+ .idea/**/workspace.xml
113
+ .idea/**/tasks.xml
114
+ .idea/dictionaries
115
+
116
+ # Sensitive or high-churn files:
117
+ .idea/**/dataSources/
118
+ .idea/**/dataSources.ids
119
+ .idea/**/dataSources.xml
120
+ .idea/**/dataSources.local.xml
121
+ .idea/**/sqlDataSources.xml
122
+ .idea/**/dynamic.xml
123
+ .idea/**/uiDesigner.xml
124
+
125
+ # Gradle:
126
+ .idea/**/gradle.xml
127
+ .idea/**/libraries
128
+
129
+ # CMake
130
+ cmake-build-debug/
131
+
132
+ # Mongo Explorer plugin:
133
+ .idea/**/mongoSettings.xml
134
+
135
+ ## File-based project format:
136
+ *.iws
137
+
138
+ ## Plugin-specific files:
139
+
140
+ # IntelliJ
141
+ /out/
142
+
143
+ # mpeltonen/sbt-idea plugin
144
+ .idea_modules/
145
+
146
+ # JIRA plugin
147
+ atlassian-ide-plugin.xml
148
+
149
+ # Cursive Clojure plugin
150
+ .idea/replstate.xml
151
+
152
+ # Ruby plugin and RubyMine
153
+ /.rakeTasks
154
+
155
+ # Crashlytics plugin (for Android Studio and IntelliJ)
156
+ com_crashlytics_export_strings.xml
157
+ crashlytics.properties
158
+ crashlytics-build.properties
159
+ fabric.properties
160
+
161
+ ### RubyMine Patch ###
162
+ # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
163
+
164
+ # *.iml
165
+ # modules.xml
166
+ # .idea/misc.xml
167
+ # *.ipr
168
+
169
+ # Sonarlint plugin
170
+ .idea/sonarlint
171
+
172
+ ### RubyMine+all ###
173
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
174
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
175
+
176
+ # User-specific stuff:
177
+
178
+ # Sensitive or high-churn files:
179
+
180
+ # Gradle:
181
+
182
+ # CMake
183
+
184
+ # Mongo Explorer plugin:
185
+
186
+ ## File-based project format:
187
+
188
+ ## Plugin-specific files:
189
+
190
+ # IntelliJ
191
+
192
+ # mpeltonen/sbt-idea plugin
193
+
194
+ # JIRA plugin
195
+
196
+ # Cursive Clojure plugin
197
+
198
+ # Ruby plugin and RubyMine
199
+
200
+ # Crashlytics plugin (for Android Studio and IntelliJ)
201
+
202
+ ### RubyMine+all Patch ###
203
+ # Ignores the whole idea folder
204
+ # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
205
+
206
+ .idea/
207
+
208
+ ### SublimeText ###
209
+ # cache files for sublime text
210
+ *.tmlanguage.cache
211
+ *.tmPreferences.cache
212
+ *.stTheme.cache
213
+
214
+ # workspace files are user-specific
215
+ *.sublime-workspace
216
+
217
+ # project files should be checked into the repository, unless a significant
218
+ # proportion of contributors will probably not be using SublimeText
219
+ # *.sublime-project
220
+
221
+ # sftp configuration file
222
+ sftp-config.json
223
+
224
+ # Package control specific files
225
+ Package Control.last-run
226
+ Package Control.ca-list
227
+ Package Control.ca-bundle
228
+ Package Control.system-ca-bundle
229
+ Package Control.cache/
230
+ Package Control.ca-certs/
231
+ Package Control.merged-ca-bundle
232
+ Package Control.user-ca-bundle
233
+ oscrypto-ca-bundle.crt
234
+ bh_unicode_properties.cache
235
+
236
+ # Sublime-github package stores a github token in this file
237
+ # https://packagecontrol.io/packages/sublime-github
238
+ GitHub.sublime-settings
239
+
240
+ ### Vim ###
241
+ # swap
242
+ .sw[a-p]
243
+ .*.sw[a-p]
244
+ # session
245
+ Session.vim
246
+ # temporary
247
+ .netrwhist
248
+ # auto-generated tag files
249
+ tags
250
+
251
+ ### VisualStudioCode ###
252
+ .vscode
253
+ !.vscode/settings.json
254
+ !.vscode/tasks.json
255
+ !.vscode/launch.json
256
+ !.vscode/extensions.json
257
+ .history
258
+
259
+ ### Windows ###
260
+ # Windows thumbnail cache files
261
+ Thumbs.db
262
+ ehthumbs.db
263
+ ehthumbs_vista.db
264
+
265
+ # Folder config file
266
+ Desktop.ini
267
+
268
+ # Recycle Bin used on file shares
269
+ $RECYCLE.BIN/
270
+
271
+ # Windows Installer files
272
+ *.cab
273
+ *.msi
274
+ *.msm
275
+ *.msp
276
+
277
+ # Windows shortcuts
278
+ *.lnk
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'spec/**/*.rb'
4
+
5
+ Style/Documentation:
6
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,20 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.3.4
6
+ - 2.4.3
7
+ - 2.5.1
8
+ env:
9
+ global:
10
+ - CI="travis"
11
+ - CC_TEST_REPORTER_ID=f6d34116730ca0ce24f577280918a14b1ac3168bf6d01b51eebba93a824f93f1
12
+ before_install: gem install bundler -v 1.16.0
13
+ before_script:
14
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
15
+ - chmod +x ./cc-test-reporter
16
+ - ./cc-test-reporter before-build
17
+ script:
18
+ - bundle exec rspec
19
+ after_script:
20
+ ./cc-test-reporter after-build -t simplecov -p /home/travis/build/sandboxws/dark_prism
@@ -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 aelhussaini@gmail.com. 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,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in dark_prism.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,146 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dark_prism (0.1.0)
5
+ activesupport (>= 4.2.0)
6
+ google-cloud-pubsub (>= 0.27.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.2.0)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ addressable (2.5.2)
17
+ public_suffix (>= 2.0.2, < 4.0)
18
+ ansi (1.5.0)
19
+ ast (2.4.0)
20
+ coderay (1.1.2)
21
+ concurrent-ruby (1.0.5)
22
+ diff-lcs (1.3)
23
+ docile (1.1.5)
24
+ faraday (0.15.0)
25
+ multipart-post (>= 1.2, < 3)
26
+ google-cloud-core (1.2.0)
27
+ google-cloud-env (~> 1.0)
28
+ google-cloud-env (1.0.1)
29
+ faraday (~> 0.11)
30
+ google-cloud-pubsub (0.30.2)
31
+ concurrent-ruby (~> 1.0)
32
+ google-cloud-core (~> 1.2)
33
+ google-gax (~> 1.0)
34
+ grpc-google-iam-v1 (~> 0.6.9)
35
+ google-gax (1.2.0)
36
+ google-protobuf (~> 3.2)
37
+ googleapis-common-protos (>= 1.3.5, < 2.0)
38
+ googleauth (~> 0.6.2)
39
+ grpc (>= 1.7.2, < 2.0)
40
+ rly (~> 0.2.3)
41
+ google-protobuf (3.5.1.2)
42
+ googleapis-common-protos (1.3.7)
43
+ google-protobuf (~> 3.0)
44
+ googleapis-common-protos-types (~> 1.0)
45
+ grpc (~> 1.0)
46
+ googleapis-common-protos-types (1.0.1)
47
+ google-protobuf (~> 3.0)
48
+ googleauth (0.6.2)
49
+ faraday (~> 0.12)
50
+ jwt (>= 1.4, < 3.0)
51
+ logging (~> 2.0)
52
+ memoist (~> 0.12)
53
+ multi_json (~> 1.11)
54
+ os (~> 0.9)
55
+ signet (~> 0.7)
56
+ grpc (1.11.0)
57
+ google-protobuf (~> 3.1)
58
+ googleapis-common-protos-types (~> 1.0.0)
59
+ googleauth (>= 0.5.1, < 0.7)
60
+ grpc-google-iam-v1 (0.6.9)
61
+ googleapis-common-protos (>= 1.3.1, < 2.0)
62
+ grpc (~> 1.0)
63
+ hirb (0.7.3)
64
+ i18n (1.0.1)
65
+ concurrent-ruby (~> 1.0)
66
+ jaro_winkler (1.5.1)
67
+ json (1.8.6)
68
+ jwt (2.1.0)
69
+ little-plugger (1.1.4)
70
+ logging (2.2.2)
71
+ little-plugger (~> 1.1)
72
+ multi_json (~> 1.10)
73
+ memoist (0.16.0)
74
+ method_source (0.9.0)
75
+ minitest (5.11.3)
76
+ multi_json (1.13.1)
77
+ multipart-post (2.0.0)
78
+ os (0.9.6)
79
+ parallel (1.12.1)
80
+ parser (2.5.1.2)
81
+ ast (~> 2.4.0)
82
+ powerpack (0.1.2)
83
+ pry (0.11.3)
84
+ coderay (~> 1.1.0)
85
+ method_source (~> 0.9.0)
86
+ public_suffix (3.0.2)
87
+ rainbow (3.0.0)
88
+ rake (10.5.0)
89
+ rly (0.2.3)
90
+ rspec (3.7.0)
91
+ rspec-core (~> 3.7.0)
92
+ rspec-expectations (~> 3.7.0)
93
+ rspec-mocks (~> 3.7.0)
94
+ rspec-core (3.7.1)
95
+ rspec-support (~> 3.7.0)
96
+ rspec-expectations (3.7.0)
97
+ diff-lcs (>= 1.2.0, < 2.0)
98
+ rspec-support (~> 3.7.0)
99
+ rspec-mocks (3.7.0)
100
+ diff-lcs (>= 1.2.0, < 2.0)
101
+ rspec-support (~> 3.7.0)
102
+ rspec-support (3.7.1)
103
+ rubocop (0.59.2)
104
+ jaro_winkler (~> 1.5.1)
105
+ parallel (~> 1.10)
106
+ parser (>= 2.5, != 2.5.1.1)
107
+ powerpack (~> 0.1)
108
+ rainbow (>= 2.2.2, < 4.0)
109
+ ruby-progressbar (~> 1.7)
110
+ unicode-display_width (~> 1.0, >= 1.0.1)
111
+ ruby-progressbar (1.10.0)
112
+ signet (0.8.1)
113
+ addressable (~> 2.3)
114
+ faraday (~> 0.9)
115
+ jwt (>= 1.5, < 3.0)
116
+ multi_json (~> 1.10)
117
+ simplecov (0.15.1)
118
+ docile (~> 1.1.0)
119
+ json (>= 1.8, < 3)
120
+ simplecov-html (~> 0.10.0)
121
+ simplecov-console (0.4.2)
122
+ ansi
123
+ hirb
124
+ simplecov
125
+ simplecov-html (0.10.2)
126
+ thread_safe (0.3.6)
127
+ tzinfo (1.2.5)
128
+ thread_safe (~> 0.1)
129
+ unicode-display_width (1.4.0)
130
+
131
+ PLATFORMS
132
+ ruby
133
+
134
+ DEPENDENCIES
135
+ bundler (~> 1.16)
136
+ dark_prism!
137
+ pry (~> 0.11.3)
138
+ rake (~> 10.0)
139
+ rspec
140
+ rspec-mocks
141
+ rubocop (~> 0.59.2)
142
+ simplecov
143
+ simplecov-console
144
+
145
+ BUNDLED WITH
146
+ 1.16.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ahmed El.Hussaini
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,119 @@
1
+ # DarkPrism
2
+
3
+ Simple and straightforward event dispatching for ruby.
4
+
5
+ [![Build Status](https://travis-ci.com/sandboxws/dark_prism.svg?branch=master)](https://travis-ci.com/sandboxws/dark_prism)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/5660cb7cfd7c184bf096/maintainability)](https://codeclimate.com/github/sandboxws/dark_prism/maintainability)
7
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/5660cb7cfd7c184bf096/test_coverage)](https://codeclimate.com/github/sandboxws/dark_prism/test_coverage)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'dark_prism'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install dark_prism
25
+
26
+ ## Usage
27
+
28
+ ### Configuration
29
+
30
+ Here is an example of a DarkPrism configuration file that can be placed under Rails' `initializers` directory.
31
+
32
+ ```ruby
33
+ DarkPrism.configure do |config|
34
+ config.register_listeners(Listeners::Base)
35
+ config.gcloud do |gcloud_config|
36
+ gcloud_config.project_id = gcloud_project_id
37
+ gcloud_config.credentials = credentials
38
+ end
39
+ end
40
+ ```
41
+
42
+ `Listeners::Base` class example:
43
+ ```ruby
44
+ module Listeners
45
+ class Base
46
+ def self.listeners
47
+ {
48
+ user_created: [Listeners::Users::Created.new]
49
+ }.freeze
50
+ end
51
+ end
52
+ end
53
+
54
+ module Listeners
55
+ module Users
56
+ class Created
57
+ include DarkPrism::Dispatch
58
+
59
+ def user_created(user)
60
+ dispatch_pubsub(:user_created, user)
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ ```
67
+
68
+ Once you've configured DarkPrism, dispatching events is quiet easy. First you need to include the `Dispatch` module as follows:
69
+
70
+ ```ruby
71
+ include DarkPrism::Dispatch
72
+ ```
73
+
74
+ Once it's included, you can dispatch events through one the following three methods:
75
+
76
+ ### dispatch_event(event_name, obj)
77
+
78
+ This method dispatches an object asynchronously to all available listeners to the event.
79
+
80
+ Example:
81
+ ```ruby
82
+ dispatch_event(:my_event, some_object)
83
+ ```
84
+
85
+ ### dispatch_pubsub(topic_name, message, attributes = nil)
86
+
87
+ This method dispatches an object synchronously to a google pubsub topic.
88
+
89
+ Example:
90
+ ```ruby
91
+ dispatch_pubsub(:my_event, some_object, { foo: :bar })
92
+ ```
93
+
94
+ ### dispatch_pubsub_async(topic_name, message, attributes = nil)
95
+
96
+ This method dispatches an object asynchronously to a google pubsub topic.
97
+
98
+ Example:
99
+ ```ruby
100
+ dispatch_pubsub_async(:my_event, some_object, { foo: :bar })
101
+ ```
102
+
103
+ ## Development
104
+
105
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests.
106
+
107
+ 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).
108
+
109
+ ## Contributing
110
+
111
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sandboxws/dark_prism. 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.
112
+
113
+ ## License
114
+
115
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
116
+
117
+ ## Code of Conduct
118
+
119
+ Everyone interacting in the DarkPrism project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sandboxws/dark_prism/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'dark_prism/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'dark_prism'
9
+ spec.version = DarkPrism::VERSION
10
+ spec.authors = ['Ahmed El.Hussaini']
11
+ spec.email = ['aelhussaini@gmail.com']
12
+
13
+ spec.summary = "dark_prism-#{DarkPrism::VERSION}"
14
+ spec.description = %q{Simple and straightforward event dispatching for ruby}
15
+ spec.homepage = 'https://github.com/sandboxws/dark_prism'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.files += ['LICENSE.md']
22
+ spec.extra_rdoc_files = ['README.md']
23
+ spec.rdoc_options = ['--charset=UTF-8']
24
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
25
+ f.match(%r{^(test|spec|features)/})
26
+ end
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_dependency 'activesupport', '>= 4.2.0'
30
+ spec.add_dependency 'google-cloud-pubsub', '>= 0.27.2'
31
+
32
+ spec.add_development_dependency 'bundler', '~> 1.16'
33
+ spec.add_development_dependency 'pry', '~> 0.11.3'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rspec'
36
+ spec.add_development_dependency 'rspec-mocks'
37
+ spec.add_development_dependency 'rubocop', '~> 0.59.2'
38
+ spec.add_development_dependency 'simplecov'
39
+ spec.add_development_dependency 'simplecov-console'
40
+ end
data/lib/dark_prism.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+ require 'singleton'
4
+ require 'dark_prism/config/main_config'
5
+ require 'dark_prism/dispatch'
6
+ require 'dark_prism/dispatcher'
7
+ require 'dark_prism/version'
8
+
9
+ module DarkPrism
10
+ def self.configure(&block)
11
+ raise NoBlockGivenException unless block_given?
12
+
13
+ Config::MainConfig.configure(&block)
14
+ end
15
+
16
+ class NoBlockGivenException < RuntimeError; end
17
+ end
@@ -0,0 +1,34 @@
1
+ require 'google/cloud/pubsub'
2
+
3
+ module DarkPrism
4
+ module Config
5
+ class GcloudConfig
6
+ include Singleton
7
+ attr_reader :pubsub
8
+ attr_accessor :project_id, :credentials
9
+
10
+ def self.configure(&block)
11
+ raise NoBlockGivenException unless block_given?
12
+
13
+ instance = GcloudConfig.instance
14
+ instance.instance_eval(&block)
15
+ instance.prepare_pubsub
16
+
17
+ instance
18
+ end
19
+
20
+ def prepare_pubsub
21
+ return unless valid?
22
+
23
+ @pubsub = Google::Cloud::Pubsub.new(
24
+ project: project_id,
25
+ keyfile: credentials
26
+ )
27
+ end
28
+
29
+ def valid?
30
+ !project_id.nil? && !credentials.nil?
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,62 @@
1
+ require 'dark_prism/config/gcloud_config'
2
+
3
+ module DarkPrism
4
+ module Config
5
+ class MainConfig
6
+ include Singleton
7
+ attr_reader :dispatcher
8
+ attr_accessor :logger, :enable_sentry
9
+
10
+ def initialize
11
+ @dispatcher = DarkPrism::Dispatcher.instance
12
+ @enable_sentry = false
13
+
14
+ init_logger
15
+ init_sentry
16
+ end
17
+
18
+ def self.configure(&block)
19
+ raise NoBlockGivenException unless block_given?
20
+
21
+ instance = MainConfig.instance
22
+ instance.instance_eval(&block)
23
+
24
+ instance
25
+ end
26
+
27
+ def register_listeners(klass_mod)
28
+ klass_mod.listeners.each do |event_name, listeners|
29
+ dispatcher.add_listeners(event_name, listeners)
30
+ end
31
+ end
32
+
33
+ def enable_sentry=(use_sentry)
34
+ @enable_sentry = use_sentry
35
+ end
36
+
37
+ def gcloud(&block)
38
+ GcloudConfig.configure(&block)
39
+ end
40
+
41
+
42
+ private
43
+
44
+ def remove_logger!
45
+ @logger = nil
46
+ end
47
+
48
+ def init_logger
49
+ if defined?(Rails) && defined?(Rails.logger)
50
+ @logger = Rails.logger
51
+ @dispatcher.logger = @logger
52
+ else
53
+ @logger = Logger.new(STDOUT)
54
+ end
55
+ end
56
+
57
+ def init_sentry
58
+ @dispatcher.enable_sentry = @enable_sentry
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,27 @@
1
+ module DarkPrism
2
+ module Dispatch
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ def dispatch_event(event_name, obj)
7
+ DarkPrism::Dispatcher.instance.dispatch(event_name, obj)
8
+ end
9
+
10
+ def dispatch_pubsub(topic_name, message, attributes = nil)
11
+ DarkPrism::Dispatcher.instance.dispatch_pubsub(
12
+ topic_name,
13
+ message,
14
+ attributes
15
+ )
16
+ end
17
+
18
+ def dispatch_pubsub_async(topic_name, message, attributes = nil)
19
+ DarkPrism::Dispatcher.instance.dispatch_pubsub_async(
20
+ topic_name,
21
+ message,
22
+ attributes
23
+ )
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,98 @@
1
+ module DarkPrism
2
+ class Dispatcher
3
+ include Singleton
4
+ attr_reader :listeners
5
+ attr_accessor :logger, :enable_sentry
6
+
7
+ def initialize
8
+ @listeners = {}.with_indifferent_access
9
+ end
10
+
11
+ def dispatch(event_name, obj)
12
+ return unless @listeners.include?(event_name)
13
+
14
+ @listeners.dig(event_name).each do |listener|
15
+ listener.send(event_name, obj)
16
+ end
17
+
18
+ true
19
+ end
20
+
21
+ def dispatch_pubsub(topic_name, obj, attributes = nil)
22
+ return unless obj.respond_to? :to_pubsub
23
+
24
+ message = obj.to_pubsub
25
+ topic = pubsub.topic topic_name
26
+ unless topic.present?
27
+ raise ArgumentError.new('Topic not found. Please create the pubsub topic and try again')
28
+ end
29
+
30
+ topic.publish message, attributes
31
+ end
32
+
33
+ def dispatch_pubsub_async(topic_name, obj, attributes = nil)
34
+ return unless obj.respond_to? :to_pubsub
35
+
36
+ message = obj.to_pubsub
37
+ topic = pubsub.topic topic_name
38
+ unless topic.present?
39
+ raise ArgumentError.new('Topic not found. Please create the pubsub topic and try again')
40
+ end
41
+
42
+ topic.publish_async message, attributes do |result|
43
+ if result.succeeded?
44
+ logger.info result.data
45
+ else
46
+ if enable_sentry
47
+ Raven.capture_exception(result.error)
48
+ else
49
+ logger.error result.data, result.error
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def add_listener(name, listener)
56
+ unless listener.respond_to?(name)
57
+ message = "#{listener.class.name} cannot respond to #{name}"
58
+ raise ArgumentError, message
59
+ end
60
+
61
+ listeners[name] = [] unless listeners.dig(name)
62
+ listeners[name] << listener unless include_listener?(name, listener)
63
+ end
64
+
65
+ def add_listeners(event_name, listeners)
66
+ listeners.each do |l|
67
+ add_listener(event_name, l)
68
+ end
69
+ end
70
+
71
+ def remove_listener(event_name, listener)
72
+ return unless listeners[event_name].present?
73
+
74
+ listeners[event_name].each_with_index do |l, idx|
75
+ if l.equal?(listener)
76
+ listeners[event_name].delete_at(idx)
77
+ break
78
+ end
79
+ end
80
+ end
81
+
82
+ def clear_all_listeners
83
+ @listeners = {}
84
+ end
85
+
86
+ private
87
+
88
+ def include_listener?(event_name, listener)
89
+ listeners[event_name].select do |l|
90
+ l.class == listener.class
91
+ end.any?
92
+ end
93
+
94
+ def pubsub
95
+ DarkPrism::Config::GcloudConfig.instance.pubsub
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,3 @@
1
+ module DarkPrism
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dark_prism
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ahmed El.Hussaini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: google-cloud-pubsub
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.27.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.27.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.11.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.11.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-mocks
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.59.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.59.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov-console
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Simple and straightforward event dispatching for ruby
154
+ email:
155
+ - aelhussaini@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files:
159
+ - README.md
160
+ files:
161
+ - ".codeclimate.yml"
162
+ - ".editorconfig"
163
+ - ".gitignore"
164
+ - ".rspec"
165
+ - ".rubocop.yml"
166
+ - ".travis.yml"
167
+ - CODE_OF_CONDUCT.md
168
+ - Gemfile
169
+ - Gemfile.lock
170
+ - LICENSE.txt
171
+ - README.md
172
+ - Rakefile
173
+ - dark_prism.gemspec
174
+ - lib/dark_prism.rb
175
+ - lib/dark_prism/config/gcloud_config.rb
176
+ - lib/dark_prism/config/main_config.rb
177
+ - lib/dark_prism/dispatch.rb
178
+ - lib/dark_prism/dispatcher.rb
179
+ - lib/dark_prism/version.rb
180
+ homepage: https://github.com/sandboxws/dark_prism
181
+ licenses:
182
+ - MIT
183
+ metadata: {}
184
+ post_install_message:
185
+ rdoc_options:
186
+ - "--charset=UTF-8"
187
+ require_paths:
188
+ - lib
189
+ required_ruby_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 2.6.14
202
+ signing_key:
203
+ specification_version: 4
204
+ summary: dark_prism-0.1.0
205
+ test_files: []