rbminivents 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/CONTRIBUTING.md +14 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +11 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +9 -0
- data/LICENSE +21 -0
- data/README.md +93 -0
- data/lib/rbminivents.rb +39 -0
- data/lib/rbminivents/version.rb +3 -0
- data/rbminivents.gemspec +28 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 516cebd771ef42bc0233d276a1e9d7cafd2f129b70e6f96c6a1e124537a200a8
|
4
|
+
data.tar.gz: ab39feb59826b236c658261550d3d026abab22f2cd608130fac42f626a83e9fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f88f86014ab9421eea8f98a5af2d385bd3e6927b119de5b22067c73b66359058e932bffb45b5caf20563fab042aef56253c271637bd8c268c2b9f16833b388d2
|
7
|
+
data.tar.gz: c3ca2963c64c069b89efa6c2b10f0425184276f3c314a04d95d7e6988474f8654dc8e62d441ec9f7aaabf064c2183564db61add707cfc2f8680c7231f4576753
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
1. [Fork the repository.][fork]
|
4
|
+
2. [Create a topic branch.][branch]
|
5
|
+
3. Implement your feature or bug fix.
|
6
|
+
4. Don't forget to add specs and make sure they pass by running `rspec .`.
|
7
|
+
5. Make sure your code complies with the style guide by running `rubocop`. `rubocop -a` can automatically fix most issues for you.
|
8
|
+
6. If necessary, add documentation for your feature or bug fix.
|
9
|
+
7. Commit and push your changes.
|
10
|
+
8. [Submit a pull request.][pr]
|
11
|
+
|
12
|
+
[fork]: http://help.github.com/fork-a-repo/
|
13
|
+
[branch]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-branches
|
14
|
+
[pr]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests
|
@@ -0,0 +1,11 @@
|
|
1
|
+
### Summary
|
2
|
+
|
3
|
+
Provide a general description of the code changes in your pull
|
4
|
+
request. Were there any bugs you had fixed? If so, mention them. If
|
5
|
+
these bugs have open GitHub issues, be sure to tag them here as well,
|
6
|
+
to keep the conversation linked together.
|
7
|
+
|
8
|
+
### Other Information
|
9
|
+
|
10
|
+
If there's anything else that's important and relevant to your pull
|
11
|
+
request, mention that information here.
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Maxim Barsukov
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# rbminivents
|
2
|
+
This gem allows you to create and emit your events very easily and minimalistic.
|
3
|
+
|
4
|
+
## Description
|
5
|
+
This gem was made under the influence of the tiny JS library [minivents](https://github.com/allouis/minivents) by [allouis](https://github.com/allouis) that I liked. It seemed to me that it would be nice to transfer this to Ruby.
|
6
|
+
|
7
|
+
## Getting started
|
8
|
+
|
9
|
+
### Requirements
|
10
|
+
|
11
|
+
This gem requires Ruby 2.5+. It might work with older versions of Rails though.
|
12
|
+
|
13
|
+
### Installation
|
14
|
+
|
15
|
+
Add the gem to your `Gemfile`:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'rbminivents'
|
19
|
+
```
|
20
|
+
|
21
|
+
and run:
|
22
|
+
|
23
|
+
```
|
24
|
+
bundle install
|
25
|
+
```
|
26
|
+
|
27
|
+
## API
|
28
|
+
This project is similar to the original one in many ways, but some features are not implemented
|
29
|
+
So,
|
30
|
+
|
31
|
+
`on`: Listen to event
|
32
|
+
|
33
|
+
`off`: Stop listening to event
|
34
|
+
|
35
|
+
`emit`: Emit event
|
36
|
+
|
37
|
+
|
38
|
+
## Examples
|
39
|
+
### Standard way
|
40
|
+
```ruby
|
41
|
+
require 'rbminivents'
|
42
|
+
|
43
|
+
sandbox = RbMinivents::Events.new
|
44
|
+
|
45
|
+
sandbox.on(:event) do
|
46
|
+
# do stuff
|
47
|
+
end
|
48
|
+
|
49
|
+
sandbox.emit(:event) # does stuff
|
50
|
+
|
51
|
+
sandbox.off(:event)
|
52
|
+
|
53
|
+
sandbox.emit(:event) # does not do stuff
|
54
|
+
```
|
55
|
+
|
56
|
+
### Passing parameters
|
57
|
+
```ruby
|
58
|
+
require 'rbminivents'
|
59
|
+
|
60
|
+
sandbox = RbMinivents::Events.new
|
61
|
+
|
62
|
+
sandbox.on(:event) do |name|
|
63
|
+
puts "Hello, #{name}!"
|
64
|
+
end
|
65
|
+
|
66
|
+
sandbox.emit(:event, 'Max') #=> Hello, Max!
|
67
|
+
# OR
|
68
|
+
# when there are > 1 arguments, pass them through the array
|
69
|
+
sandbox.emit(:event, ['Max']) #=> Hello, Max!
|
70
|
+
```
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
require 'rbminivents'
|
74
|
+
|
75
|
+
sandbox = RbMinivents::Events.new
|
76
|
+
|
77
|
+
sandbox.on(:event) do |hash, arr, num, bool|
|
78
|
+
puts hash[:name]
|
79
|
+
p arr
|
80
|
+
puts "5 + #{num} = #{5 + num}"
|
81
|
+
puts "It's true!" if bool
|
82
|
+
end
|
83
|
+
|
84
|
+
# max, [1, 2, 3], 5 + 7 = 12
|
85
|
+
sandbox.emit(:event,
|
86
|
+
[
|
87
|
+
{name: 'max'},
|
88
|
+
[1, 2, 3],
|
89
|
+
7,
|
90
|
+
false
|
91
|
+
]
|
92
|
+
)
|
93
|
+
```
|
data/lib/rbminivents.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module RbMinivents
|
2
|
+
class Events
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@events = Hash.new
|
6
|
+
end
|
7
|
+
|
8
|
+
# On: listen to events
|
9
|
+
def on(type, &prc)
|
10
|
+
sym = type.to_s.to_sym
|
11
|
+
|
12
|
+
@events[sym] = prc if block_given?
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
# Off: stop listening to event
|
17
|
+
def off(type)
|
18
|
+
sym = type.to_s.to_sym
|
19
|
+
|
20
|
+
if @events.has_key?(sym)
|
21
|
+
@events.delete(sym)
|
22
|
+
end
|
23
|
+
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
# Emit: send event, callbacks will be triggered
|
28
|
+
def emit(type, args = nil)
|
29
|
+
sym = type.to_s.to_sym
|
30
|
+
|
31
|
+
if @events.has_key?(sym)
|
32
|
+
@events[sym].call(*args)
|
33
|
+
@events.delete(sym)
|
34
|
+
end
|
35
|
+
|
36
|
+
self
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/rbminivents.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('lib/rbminivents/version', __dir__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'rbminivents'
|
5
|
+
spec.version = RbMinivents::VERSION
|
6
|
+
spec.authors = ['Max Barsukov']
|
7
|
+
spec.email = ['maximb2208@gmail.com']
|
8
|
+
spec.summary = 'Tiny eventing gem'
|
9
|
+
spec.description = 'This gem allows you to create and emit your events very easily and minimalistic.'
|
10
|
+
spec.homepage = 'https://github.com/maxbarsukov/rbminivents'
|
11
|
+
spec.license = 'MIT'
|
12
|
+
spec.platform = Gem::Platform::RUBY
|
13
|
+
spec.required_ruby_version = '>= 2.5.0'
|
14
|
+
|
15
|
+
spec.files = Dir['README.md', 'LICENSE',
|
16
|
+
'CHANGELOG.md', 'lib/**/*.rb',
|
17
|
+
'lib/**/*.rake',
|
18
|
+
'rbminivents.gemspec', '.github/*.md',
|
19
|
+
'Gemfile', 'Rakefile']
|
20
|
+
|
21
|
+
spec.test_files = Dir['spec/**/*.rb']
|
22
|
+
spec.extra_rdoc_files = ['README.md']
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'rubocop', '~> 1.0'
|
26
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.5'
|
27
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.2.0'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rbminivents
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Max Barsukov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop-performance
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.2.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.2.0
|
55
|
+
description: This gem allows you to create and emit your events very easily and minimalistic.
|
56
|
+
email:
|
57
|
+
- maximb2208@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files:
|
61
|
+
- README.md
|
62
|
+
files:
|
63
|
+
- ".github/CONTRIBUTING.md"
|
64
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
65
|
+
- CHANGELOG.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE
|
68
|
+
- README.md
|
69
|
+
- lib/rbminivents.rb
|
70
|
+
- lib/rbminivents/version.rb
|
71
|
+
- rbminivents.gemspec
|
72
|
+
homepage: https://github.com/maxbarsukov/rbminivents
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 2.5.0
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubygems_version: 3.2.16
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Tiny eventing gem
|
95
|
+
test_files: []
|