wisperable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2508189d6db5a7daa379351879c75110670c55880fb02f809abd11840c626c96
4
+ data.tar.gz: 75c0a55fccc421e27c8f0eadef0246f5042119fa4f6f745ae2b5f96949840615
5
+ SHA512:
6
+ metadata.gz: ae42a7b0aa8543d70dd13c3c138cc248a20202a6aca512820df8ba36b061b08093fdddc520e2db4c37f5955253ffd1309dd6d3718a4be0faa931f16c0718c64f
7
+ data.tar.gz: 6df787be8701adae037db931cbcd034ff3a5cbf288554c669bb8284f7dcbc0ba955ebe21ede2dfb707cf86f8bac29265ca36da8412cbcdcc37d140fb0d1708f9
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.idea/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format documentation
@@ -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 1.16.3
@@ -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 marco@bitmix.it. 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 wisperable.gemspec
6
+ gemspec
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ wisperable (0.1.0)
5
+ activesupport (~> 5.2)
6
+ wisper (~> 2.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (5.2.1)
12
+ activesupport (= 5.2.1)
13
+ activerecord (5.2.1)
14
+ activemodel (= 5.2.1)
15
+ activesupport (= 5.2.1)
16
+ arel (>= 9.0)
17
+ activesupport (5.2.1)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 0.7, < 2)
20
+ minitest (~> 5.1)
21
+ tzinfo (~> 1.1)
22
+ arel (9.0.0)
23
+ concurrent-ruby (1.0.5)
24
+ diff-lcs (1.3)
25
+ docile (1.3.1)
26
+ i18n (1.1.0)
27
+ concurrent-ruby (~> 1.0)
28
+ json (2.1.0)
29
+ minitest (5.11.3)
30
+ rake (12.3.1)
31
+ rspec (3.8.0)
32
+ rspec-core (~> 3.8.0)
33
+ rspec-expectations (~> 3.8.0)
34
+ rspec-mocks (~> 3.8.0)
35
+ rspec-core (3.8.0)
36
+ rspec-support (~> 3.8.0)
37
+ rspec-expectations (3.8.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.8.0)
40
+ rspec-mocks (3.8.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.8.0)
43
+ rspec-support (3.8.0)
44
+ simplecov (0.16.1)
45
+ docile (~> 1.1)
46
+ json (>= 1.8, < 3)
47
+ simplecov-html (~> 0.10.0)
48
+ simplecov-html (0.10.2)
49
+ sqlite3 (1.3.13)
50
+ thread_safe (0.3.6)
51
+ tzinfo (1.2.5)
52
+ thread_safe (~> 0.1)
53
+ wisper (2.0.0)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ activerecord (~> 5.2)
60
+ bundler (~> 1.16)
61
+ rake (~> 12.3)
62
+ rspec (~> 3.8)
63
+ simplecov (~> 0.16)
64
+ sqlite3 (~> 1.3)
65
+ wisperable!
66
+
67
+ BUNDLED WITH
68
+ 1.16.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Marco Borromeo
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.
@@ -0,0 +1,95 @@
1
+ # Wisperable [![Build Status](https://travis-ci.org/mborromeo/wisperable.svg?branch=master)](https://travis-ci.org/mborromeo/wisperable)
2
+
3
+ Get notified of any ActiveModel events using the [Wisper gem](https://github.com/krisleech/wisper).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'wisperable', '~> 0.1'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install wisperable
20
+
21
+ ## Usage
22
+
23
+ Add `import Wisperable::Model` to your models, and configure which events you want to listen for with `wisperable events: [:created, :updated, :destroyed]`
24
+
25
+ Let's see an example:
26
+ ```ruby
27
+ class Account
28
+ include Wisperable::Model
29
+ wisperable events: [:created, :updated, :destroyed]
30
+ end
31
+ ```
32
+
33
+ When any create, update or destroy event will happen on an instance of Account, a corresponding `account_created`, `account_updated` or `account_destroyed` will be broadcasted by Wisper.
34
+
35
+ You can customize the broadcasting key to be used:
36
+ ```ruby
37
+ class Account
38
+ include Wisperable::Model
39
+ wisperable events: [:created, :updated, :destroyed], publish_key: 'user'
40
+ end
41
+ ```
42
+
43
+ In this key, the broadcast message will be in the form of `user_created`, `user_updated` and `user_destroyed`.
44
+
45
+ ##### Events parameters
46
+ `_created` event broadcasts one parameter with the created object.
47
+ `_updated` event broadcasts two parameters with the updated object and the changed attributes.
48
+ `_destroyed` event broadcasts one parameter with a copy of the destroyed model attribute.
49
+
50
+ Please see the following example of a PORO (Plain Old Ruby Object) able to intercept Wisperable broadcasts:
51
+ ```ruby
52
+ class AccountNotifier
53
+ def account_created(account)
54
+ # account has been created.
55
+ end
56
+
57
+ def account_updated(account, changes)
58
+ # account has been updated.
59
+ # changes contains the changed attributes.
60
+ end
61
+
62
+ def account_destroyed(account)
63
+ # account contains a copy of the destroyed Account model.
64
+ end
65
+ end
66
+ ```
67
+
68
+ Please see [Wisper](https://github.com/krisleech/wisper) for any other subscribers setup instruction.
69
+
70
+ ## Development
71
+
72
+ 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.
73
+
74
+ 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).
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mborromeo/wisperable. 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.
79
+
80
+ If you want to contribute with a pull request please follow these steps:
81
+ * Fork the project, create a new branch from `master`.
82
+ * Squash commits which are related.
83
+ * Write a good enough commit message.
84
+ * Do not bump the VERSION, but do indicate in the pull request message if the change is not backwards compatible.
85
+ * Issue a Pull Request
86
+
87
+ And... thanks for any contribution!
88
+
89
+ ## License
90
+
91
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
92
+
93
+ ## Code of Conduct
94
+
95
+ Everyone interacting in the Wisperable project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mborromeo/wisperable/blob/master/CODE_OF_CONDUCT.md).
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wisperable"
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__)
@@ -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
@@ -0,0 +1,57 @@
1
+ require 'active_support'
2
+ require 'wisper'
3
+ require 'wisperable/version'
4
+
5
+ module Wisperable
6
+ module Model
7
+ extend ActiveSupport::Concern
8
+
9
+ module ClassMethods
10
+ attr_reader :wisperable_opts
11
+
12
+ private
13
+
14
+ def wisperable(opts = {})
15
+ @wisperable_opts = opts
16
+ end
17
+ end
18
+
19
+ included do
20
+ include Wisper::Publisher
21
+
22
+ after_commit :broadcast_after_created, on: :create
23
+ after_commit :broadcast_after_updated, on: :update
24
+ after_commit :broadcast_after_destroyed, on: :destroy
25
+ end
26
+
27
+ private
28
+
29
+ def opts
30
+ self.class.wisperable_opts || {}
31
+ end
32
+
33
+ def events
34
+ opts[:events] || []
35
+ end
36
+
37
+ def publish_key
38
+ opts[:publish_key] || self.class.model_name.param_key
39
+ end
40
+
41
+ def event_enabled?(event)
42
+ events.include?(event)
43
+ end
44
+
45
+ def broadcast_after_created
46
+ broadcast("#{publish_key}_created", self) if event_enabled?(:created)
47
+ end
48
+
49
+ def broadcast_after_updated
50
+ broadcast("#{publish_key}_updated", self, previous_changes) if event_enabled?(:updated)
51
+ end
52
+
53
+ def broadcast_after_destroyed
54
+ broadcast("#{publish_key}_destroyed", attributes) if event_enabled?(:destroyed)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module Wisperable
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "wisperable/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wisperable"
8
+ spec.version = Wisperable::VERSION
9
+ spec.authors = ["Marco Borromeo"]
10
+ spec.email = ["marco@marcoborromeo.com"]
11
+
12
+ spec.summary = %q{Configure and Broadcast ActiveModel events via Wisper}
13
+ spec.homepage = "https://github.com/mborromeo/wisperable"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_runtime_dependency 'activesupport', '~> 5.2'
26
+ spec.add_runtime_dependency 'wisper', '~> 2.0'
27
+
28
+ spec.add_development_dependency 'activerecord', '~> 5.2'
29
+ spec.add_development_dependency 'bundler', '~> 1.16'
30
+ spec.add_development_dependency 'rake', '~> 12.3'
31
+ spec.add_development_dependency 'rspec', '~> 3.8'
32
+ spec.add_development_dependency 'simplecov', '~> 0.16'
33
+ spec.add_development_dependency 'sqlite3', '~> 1.3'
34
+
35
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wisperable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marco Borromeo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-08 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: '5.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: wisper
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '12.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '12.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.16'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.16'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.3'
125
+ description:
126
+ email:
127
+ - marco@marcoborromeo.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - CODE_OF_CONDUCT.md
136
+ - Gemfile
137
+ - Gemfile.lock
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - lib/wisperable.rb
144
+ - lib/wisperable/version.rb
145
+ - wisperable.gemspec
146
+ homepage: https://github.com/mborromeo/wisperable
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.7.7
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Configure and Broadcast ActiveModel events via Wisper
170
+ test_files: []