wisper-bubbleable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +4 -0
- data/.travis.yml +6 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +50 -0
- data/LICENSE.txt +21 -0
- data/README.md +84 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/wisper/bubbleable.rb +12 -0
- data/lib/wisper/bubbleable/pipeline.rb +24 -0
- data/lib/wisper/bubbleable/version.rb +7 -0
- data/wisper-bubbleable.gemspec +32 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ab19d23ef323e325f1040abb95ba2ff38dace517832111e8f54245952393d9b8
|
4
|
+
data.tar.gz: a23a69dbdd5a4ab080ee20f87204fffb3e923c7a8a001f91279edabd89d6fd9f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7b95e438d4afb755b89a1d337d479dd243481cec82e33e73318901ae58bb9151629ae43aab59fd0b65da6d60933aeafb1e25b060247fdfc135b505ea6ce53355
|
7
|
+
data.tar.gz: 40c03e0f92e67dfd8a64823978b085f8a0914aec3c5bd8fcf0e2e64627ebaf1f355f4979a3dbdf72da03cfe7bf5282c06a1fb2363d89e9e6acf527f0e32a2cd1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wisper-bubbleable (0.1.0)
|
5
|
+
wisper (~> 2.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
docile (1.3.2)
|
13
|
+
json (2.3.0)
|
14
|
+
method_source (0.9.2)
|
15
|
+
pry (0.12.2)
|
16
|
+
coderay (~> 1.1.0)
|
17
|
+
method_source (~> 0.9.0)
|
18
|
+
rake (12.3.3)
|
19
|
+
rspec (3.9.0)
|
20
|
+
rspec-core (~> 3.9.0)
|
21
|
+
rspec-expectations (~> 3.9.0)
|
22
|
+
rspec-mocks (~> 3.9.0)
|
23
|
+
rspec-core (3.9.0)
|
24
|
+
rspec-support (~> 3.9.0)
|
25
|
+
rspec-expectations (3.9.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.9.0)
|
28
|
+
rspec-mocks (3.9.0)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.9.0)
|
31
|
+
rspec-support (3.9.0)
|
32
|
+
simplecov (0.17.1)
|
33
|
+
docile (~> 1.1)
|
34
|
+
json (>= 1.8, < 3)
|
35
|
+
simplecov-html (~> 0.10.0)
|
36
|
+
simplecov-html (0.10.2)
|
37
|
+
wisper (2.0.1)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
pry (~> 0.12.2)
|
44
|
+
rake (~> 12.0)
|
45
|
+
rspec (~> 3.0)
|
46
|
+
simplecov (~> 0.17.1)
|
47
|
+
wisper-bubbleable!
|
48
|
+
|
49
|
+
BUNDLED WITH
|
50
|
+
2.1.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 xiaohui
|
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,84 @@
|
|
1
|
+
# Wisper::Bubbleable
|
2
|
+
|
3
|
+
A Wisper plugin to bubble events up to parent listener.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'wisper-bubbleable'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install wisper-bubbleable
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class CoffeeStatePublisher
|
25
|
+
include Wisper::Publisher
|
26
|
+
include Wisper::Bubbleable
|
27
|
+
|
28
|
+
def change(state)
|
29
|
+
if state == true
|
30
|
+
broadcast(:power_on, 'Power On')
|
31
|
+
elsif state == false
|
32
|
+
broadcast(:power_off, 'Power Off')
|
33
|
+
else
|
34
|
+
broadcast(:invalid_state, state)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class CoffeeMakerPublisher
|
40
|
+
include Wisper::Publisher
|
41
|
+
include Wisper::Bubbleable
|
42
|
+
|
43
|
+
def power(on_or_off)
|
44
|
+
state = CoffeeStatePublisher.new
|
45
|
+
# ** bubble events here **
|
46
|
+
state.bubble(:power_on, :power_off).to(self)
|
47
|
+
state.on(:power_on) { broadcast(:warming) }
|
48
|
+
state.on(:invalid_state) { |x| broadcast(:error, x) }
|
49
|
+
state.change(on_or_off)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Listener
|
54
|
+
def output(msg); puts msg; end
|
55
|
+
alias power_on output
|
56
|
+
alias power_off output
|
57
|
+
def warming; puts 'Warming up...'; end
|
58
|
+
end
|
59
|
+
|
60
|
+
maker = CoffeeMakerPublisher.new and nil
|
61
|
+
maker.subscribe(Listener.new) and nil
|
62
|
+
maker.power(true) and nil
|
63
|
+
# => Power On
|
64
|
+
# => Warming up...
|
65
|
+
maker.power(false) and nil
|
66
|
+
# => Power Off
|
67
|
+
maker.power('boy') and nil
|
68
|
+
# => <No thing happen>
|
69
|
+
```
|
70
|
+
|
71
|
+
## Development
|
72
|
+
|
73
|
+
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.
|
74
|
+
|
75
|
+
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).
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/xiaohui-zhangxh/wisper-bubbleable.
|
80
|
+
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'wisper'
|
6
|
+
require 'wisper/bubbleable'
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wisper
|
4
|
+
module Bubbleable
|
5
|
+
class Pipeline
|
6
|
+
def initialize(from, *events)
|
7
|
+
@from = from
|
8
|
+
@events = events
|
9
|
+
end
|
10
|
+
|
11
|
+
def to(target)
|
12
|
+
@events.each do |ev|
|
13
|
+
@from.on(ev) do |*args|
|
14
|
+
# listeners = target.send(:local_registrations).map(&:listener)
|
15
|
+
# listeners += target.send(:temporary_registrations).map(&:listener)
|
16
|
+
# should_broadcast = target.listeners.any? { |listener| listener.respond_to?(ev) }
|
17
|
+
# target.send(:broadcast, ev, *args) if should_broadcast
|
18
|
+
target.send(:broadcast, ev, *args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/wisper/bubbleable/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'wisper-bubbleable'
|
7
|
+
spec.version = Wisper::Bubbleable::VERSION
|
8
|
+
spec.authors = ['xiaohui']
|
9
|
+
spec.email = ['xiaohui@tanmer.com']
|
10
|
+
|
11
|
+
spec.summary = 'A Wisper plugin to bubble events up to parent listener'
|
12
|
+
spec.homepage = 'https://github.com/xiaohui-zhangxh/wisper-bubbleable'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
15
|
+
|
16
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
17
|
+
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
20
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
# spec.bindir = "exe"
|
28
|
+
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_dependency 'wisper', '~> 2.0'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wisper-bubbleable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- xiaohui
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: wisper
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '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: '2.0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- xiaohui@tanmer.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".travis.yml"
|
37
|
+
- Gemfile
|
38
|
+
- Gemfile.lock
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- bin/console
|
43
|
+
- bin/setup
|
44
|
+
- lib/wisper/bubbleable.rb
|
45
|
+
- lib/wisper/bubbleable/pipeline.rb
|
46
|
+
- lib/wisper/bubbleable/version.rb
|
47
|
+
- wisper-bubbleable.gemspec
|
48
|
+
homepage: https://github.com/xiaohui-zhangxh/wisper-bubbleable
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata:
|
52
|
+
homepage_uri: https://github.com/xiaohui-zhangxh/wisper-bubbleable
|
53
|
+
source_code_uri: https://github.com/xiaohui-zhangxh/wisper-bubbleable
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.3.0
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubygems_version: 3.0.6
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: A Wisper plugin to bubble events up to parent listener
|
73
|
+
test_files: []
|