observe_event 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 +12 -0
- data/.rspec +1 -0
- data/.rubocop.yml +20 -0
- data/.templates.yml +9 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +82 -0
- data/Rakefile +73 -0
- data/VERSION +1 -0
- data/bin/setup +8 -0
- data/examples/player.rb +1 -0
- data/examples/simple.rb +50 -0
- data/examples/user.rb +62 -0
- data/lib/observe_event.rb +40 -0
- data/observe_event.gemspec +34 -0
- data/templates/LICENSE.txt.erb +21 -0
- data/templates/README.md.erb +32 -0
- data/templates/observe_event.gemspec.erb +33 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1254f7509c1f6a3ba6b815916b41d80b4267b277
|
4
|
+
data.tar.gz: dae66eaf61e0ddebc3d1298592ed175073898b09
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b6e73e82cd606c4fa0ab8f286be9b035cc0d1d3fb0982ab69eb023816d75ff1f7668b4eb364c5c1a26fd10de44a66edc130a4cffeeb3b553e74893493edc961
|
7
|
+
data.tar.gz: 376c446ad20bd20d70fd02c473f3cfcf2e7a8310062554f13f3ece99d48d3fa2a47efcbb54ad76c7ebbaae9aaf26cdcceafe27e4c6cebd62682dd6fb92597bec
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
|
4
|
+
Metrics/AbcSize:
|
5
|
+
Max: 17
|
6
|
+
|
7
|
+
Metrics/CyclomaticComplexity:
|
8
|
+
Max: 7
|
9
|
+
|
10
|
+
Metrics/LineLength:
|
11
|
+
Max: 120
|
12
|
+
|
13
|
+
Metrics/MethodLength:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/BlockLength:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/PerceivedComplexity:
|
20
|
+
Enabled: false
|
data/.templates.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
name: observe_event
|
2
|
+
namespace: ObserveEvent
|
3
|
+
author: Ryan Scott Lewis
|
4
|
+
email: ryanscottlewis@gmail.com
|
5
|
+
github: RyanScottLewis
|
6
|
+
summary: Small and effective implementation of the observer pattern to define event methods on objects.
|
7
|
+
description: |
|
8
|
+
Enables an object to define an event method which to becomes a publisher/observable.
|
9
|
+
Subscribers/observers can to be defined dynamically via a block given to the event.
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 ryan@rynet.us. 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
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Ryan Scott Lewis <ryanscottlewis@gmail.com>
|
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,82 @@
|
|
1
|
+
# ObserveEvent
|
2
|
+
|
3
|
+
Enables an object to define an event method which to becomes a publisher/observable.
|
4
|
+
Subscribers/observers can to be defined dynamically via a block given to the event.
|
5
|
+
|
6
|
+
## Install
|
7
|
+
|
8
|
+
### Bundler: `gem "observe_event"`
|
9
|
+
|
10
|
+
### RubyGems: `gem install observe_event`
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
```rb
|
15
|
+
# frozen_string_literal: true
|
16
|
+
|
17
|
+
require 'observe_event'
|
18
|
+
|
19
|
+
# A simple "timer" class
|
20
|
+
class Timer
|
21
|
+
extend ObserveEvent
|
22
|
+
|
23
|
+
event :tick # Define publisher/observable `tick`
|
24
|
+
event_accessor :running # Define publisher/observable `running_changed`, which notifies it's subscribers/observers
|
25
|
+
|
26
|
+
def state
|
27
|
+
@running ? :running : :stopped
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
timer = Timer.new
|
32
|
+
|
33
|
+
# Define subscriber to `running_changed` on the Timer instance
|
34
|
+
timer.running_changed do |from, to|
|
35
|
+
puts "Timer#running changed from `#{from.inspect}` to `#{to.inspect}`"
|
36
|
+
puts "Timer #{timer.state}"
|
37
|
+
end
|
38
|
+
|
39
|
+
# Define subscribers to `tick` on the Timer instance
|
40
|
+
timer.tick do
|
41
|
+
puts 'Tick' if timer.running
|
42
|
+
end
|
43
|
+
|
44
|
+
timer.tick do
|
45
|
+
puts 'Tock' if timer.running
|
46
|
+
end
|
47
|
+
|
48
|
+
timer.tick
|
49
|
+
timer.tick
|
50
|
+
timer.running = true
|
51
|
+
timer.tick
|
52
|
+
timer.tick
|
53
|
+
timer.running = false
|
54
|
+
timer.tick
|
55
|
+
timer.tick
|
56
|
+
|
57
|
+
# => Timer#running changed from `nil` to `true`
|
58
|
+
# => Timer running
|
59
|
+
# => Tick
|
60
|
+
# => Tock
|
61
|
+
# => Tick
|
62
|
+
# => Tock
|
63
|
+
# => Timer#running changed from `true` to `false`
|
64
|
+
# => Timer stopped
|
65
|
+
```
|
66
|
+
|
67
|
+
See the `examples/` directory for more examples.
|
68
|
+
|
69
|
+
## Development
|
70
|
+
|
71
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
72
|
+
Then, run `rake` to run the tests.
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/RyanScottLewis/observe_event.
|
77
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
|
78
|
+
[Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
if File.exist?("#{File.basename(__dir__)}.gemspec")
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rake/version_task'
|
11
|
+
Rake::VersionTask.new
|
12
|
+
|
13
|
+
require 'rubocop/rake_task'
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
# --
|
16
|
+
|
17
|
+
require 'erb'
|
18
|
+
require 'yaml'
|
19
|
+
|
20
|
+
# Renders templates
|
21
|
+
class TemplateRenderer
|
22
|
+
def initialize
|
23
|
+
@variables = YAML.load_file('.templates.yml')
|
24
|
+
@variables.each { |key, value| @variables[key] = value.strip }
|
25
|
+
end
|
26
|
+
|
27
|
+
def method_missing(name)
|
28
|
+
@variables[name.to_s] || super
|
29
|
+
end
|
30
|
+
|
31
|
+
def respond_to_missing?(name, include_private = false)
|
32
|
+
@variables.key?(name.to_s) || super
|
33
|
+
end
|
34
|
+
|
35
|
+
def file(path)
|
36
|
+
File.read(path).chomp
|
37
|
+
end
|
38
|
+
|
39
|
+
def render(path)
|
40
|
+
contents = File.read(path)
|
41
|
+
document = ERB.new(contents)
|
42
|
+
|
43
|
+
document.result(binding)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
TEMPLATE_RENDERER = TemplateRenderer.new
|
48
|
+
TEMPLATE_INPUT_PATHS = FileList['templates/*.erb']
|
49
|
+
TEMPLATE_OUTPUT_PATHS = TEMPLATE_INPUT_PATHS.map { |path| File.basename(path, '.erb') }
|
50
|
+
TEMPLATE_PATHS = Hash[TEMPLATE_INPUT_PATHS.zip(TEMPLATE_OUTPUT_PATHS)]
|
51
|
+
|
52
|
+
TEMPLATE_PATHS.each do |input_path, output_path|
|
53
|
+
file output_path => input_path do
|
54
|
+
puts "Rendering `#{output_path}`"
|
55
|
+
|
56
|
+
contents = TEMPLATE_RENDERER.render(input_path)
|
57
|
+
File.open(output_path, 'w+') { |file| file.write(contents) }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
desc 'Render templates'
|
62
|
+
task 'templates:build' => TEMPLATE_OUTPUT_PATHS
|
63
|
+
|
64
|
+
desc 'Clean templates'
|
65
|
+
task 'templates:clean' do
|
66
|
+
TEMPLATE_OUTPUT_PATHS.each do |path|
|
67
|
+
rm_f path
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# --
|
72
|
+
|
73
|
+
task default: %w[spec templates:build rubocop:auto_correct]
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/setup
ADDED
data/examples/player.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
examples/../spec/support/player.rb
|
data/examples/simple.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'observe_event'
|
4
|
+
|
5
|
+
# A simple "timer" class
|
6
|
+
class Timer
|
7
|
+
extend ObserveEvent
|
8
|
+
|
9
|
+
event :tick # Define publisher/observable `tick`
|
10
|
+
event_accessor :running # Define publisher/observable `running_changed`, which notifies it's subscribers/observers
|
11
|
+
|
12
|
+
def state
|
13
|
+
@running ? :running : :stopped
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
timer = Timer.new
|
18
|
+
|
19
|
+
# Define subscriber to `running_changed` on the Timer instance
|
20
|
+
timer.running_changed do |from, to|
|
21
|
+
puts "Timer#running changed from `#{from.inspect}` to `#{to.inspect}`"
|
22
|
+
puts "Timer #{timer.state}"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Define subscribers to `tick` on the Timer instance
|
26
|
+
timer.tick do
|
27
|
+
puts 'Tick' if timer.running
|
28
|
+
end
|
29
|
+
|
30
|
+
timer.tick do
|
31
|
+
puts 'Tock' if timer.running
|
32
|
+
end
|
33
|
+
|
34
|
+
timer.tick
|
35
|
+
timer.tick
|
36
|
+
timer.running = true
|
37
|
+
timer.tick
|
38
|
+
timer.tick
|
39
|
+
timer.running = false
|
40
|
+
timer.tick
|
41
|
+
timer.tick
|
42
|
+
|
43
|
+
# => Timer#running changed from `nil` to `true`
|
44
|
+
# => Timer running
|
45
|
+
# => Tick
|
46
|
+
# => Tock
|
47
|
+
# => Tick
|
48
|
+
# => Tock
|
49
|
+
# => Timer#running changed from `true` to `false`
|
50
|
+
# => Timer stopped
|
data/examples/user.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'observe_event'
|
4
|
+
|
5
|
+
# A simple "user" class
|
6
|
+
class User
|
7
|
+
extend ObserveEvent
|
8
|
+
|
9
|
+
def initialize(name)
|
10
|
+
@elevated = false
|
11
|
+
self.name = name
|
12
|
+
end
|
13
|
+
|
14
|
+
event :permissions_elevated # Define publisher/observable `permissions_elevated`
|
15
|
+
|
16
|
+
def elevate_permissions
|
17
|
+
@elevated = true
|
18
|
+
|
19
|
+
permissions_elevated # Notify `permissions_elevated` subscribers/observers
|
20
|
+
end
|
21
|
+
|
22
|
+
event_accessor :name # Define publisher/observable `name_changed`, which notifies it's subscribers/observers
|
23
|
+
end
|
24
|
+
|
25
|
+
user = User.new('Jeff')
|
26
|
+
|
27
|
+
user.name_changed do |from, to| # Define subscriber
|
28
|
+
puts 'User name changed'
|
29
|
+
puts "From: #{from}"
|
30
|
+
puts "To: #{to}"
|
31
|
+
puts '-' * 80
|
32
|
+
p user
|
33
|
+
p self
|
34
|
+
puts
|
35
|
+
end
|
36
|
+
|
37
|
+
user.permissions_elevated do # Define subscriber
|
38
|
+
puts 'User permissions elevated'
|
39
|
+
puts '-' * 80
|
40
|
+
p user
|
41
|
+
p self
|
42
|
+
puts
|
43
|
+
end
|
44
|
+
|
45
|
+
user.name = 'Geoff' # Notify observers via `event_accessor :name`
|
46
|
+
|
47
|
+
user.elevate_permissions # Notify observers via `event :permissions_elevated`
|
48
|
+
|
49
|
+
__END__
|
50
|
+
Output:
|
51
|
+
$ be ruby ./examples/simple.rb
|
52
|
+
User name changed
|
53
|
+
From: Jeff
|
54
|
+
To: Geoff
|
55
|
+
--------------------------------------------------------------------------------
|
56
|
+
#<User:0x007fb60e19b8f8 @name="Geoff", @name_changed=[#<Proc:0x007fb60e19b6c8@./examples/simple.rb:23>], @permissions_elevated=[#<Proc:0x007fb60e19b5b0@./examples/simple.rb:33>]>
|
57
|
+
main
|
58
|
+
|
59
|
+
User permissions elevated
|
60
|
+
--------------------------------------------------------------------------------
|
61
|
+
#<User:0x007fb60e19b8f8 @name="Geoff", @name_changed=[#<Proc:0x007fb60e19b6c8@./examples/simple.rb:23>], @permissions_elevated=[#<Proc:0x007fb60e19b5b0@./examples/simple.rb:33>]>
|
62
|
+
main
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'version'
|
4
|
+
|
5
|
+
# Small and effective implementation of the observer pattern to define event methods on objects
|
6
|
+
module ObserveEvent
|
7
|
+
is_versioned
|
8
|
+
|
9
|
+
def event(name)
|
10
|
+
define_method(name) do |*arguments, &block| # TODO: Allow below, they get tacked onto the block arguments
|
11
|
+
raise ArgumentError, 'Arguments cannot be passed with a block' if !block.nil? && !arguments.empty?
|
12
|
+
|
13
|
+
events = instance_variable_get("@#{name}")
|
14
|
+
|
15
|
+
return if block.nil? && events.nil?
|
16
|
+
return events.each { |event| event.call(*arguments) } if block.nil?
|
17
|
+
return instance_variable_set("@#{name}", [block]) if events.nil?
|
18
|
+
|
19
|
+
events << block
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def event_writer(name)
|
24
|
+
event("#{name}_changed")
|
25
|
+
|
26
|
+
define_method("#{name}=") do |current_value|
|
27
|
+
previous_value = instance_variable_get("@#{name}")
|
28
|
+
|
29
|
+
instance_variable_set("@#{name}", current_value)
|
30
|
+
send("#{name}_changed", previous_value, current_value)
|
31
|
+
|
32
|
+
current_value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def event_accessor(name)
|
37
|
+
attr_reader(name)
|
38
|
+
event_writer(name)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'observe_event'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'observe_event'
|
10
|
+
spec.version = ObserveEvent::VERSION
|
11
|
+
spec.authors = ['Ryan Scott Lewis']
|
12
|
+
spec.email = ['ryanscottlewis@gmail.com']
|
13
|
+
spec.homepage = 'https://github.com/RyanScottLewis/observe_event'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.summary = 'Small and effective implementation of the observer pattern to define event methods on objects.'
|
17
|
+
spec.description = <<~DESCRIPTION.chomp
|
18
|
+
Enables an object to define an event method which to becomes a publisher/observable.
|
19
|
+
Subscribers/observers can to be defined dynamically via a block given to the event.
|
20
|
+
DESCRIPTION
|
21
|
+
|
22
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
f.match(%r{^(test|spec|features)/})
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_dependency 'version', '~> 1.0.0'
|
30
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
31
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
33
|
+
spec.add_development_dependency 'rubocop', '~> 0.48.1'
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 <%= author %> <<%= email %>>
|
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,32 @@
|
|
1
|
+
# <%= namespace %>
|
2
|
+
|
3
|
+
<%= description %>
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
### Bundler: `gem "<%= name %>"`
|
8
|
+
|
9
|
+
### RubyGems: `gem install <%= name %>`
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```rb
|
14
|
+
<%= file("examples/simple.rb") %>
|
15
|
+
```
|
16
|
+
|
17
|
+
See the `examples/` directory for more examples.
|
18
|
+
|
19
|
+
## Development
|
20
|
+
|
21
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
22
|
+
Then, run `rake` to run the tests.
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/<%= github %>/<%= name %>.
|
27
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
|
28
|
+
[Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
29
|
+
|
30
|
+
## License
|
31
|
+
|
32
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require '<%= name %>'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = '<%= name %>'
|
10
|
+
spec.version = <%= namespace %>::VERSION
|
11
|
+
spec.authors = ['<%= author %>']
|
12
|
+
spec.email = ['<%= email %>']
|
13
|
+
spec.homepage = 'https://github.com/<%= github %>/<%= name %>'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.summary = '<%= summary %>'
|
17
|
+
spec.description = <<~DESCRIPTION.chomp
|
18
|
+
<%= description.lines.map { |line| (' ' * 4) + line }.join %>
|
19
|
+
DESCRIPTION
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
22
|
+
f.match(%r{^(test|spec|features)/})
|
23
|
+
end
|
24
|
+
spec.bindir = 'exe'
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_dependency 'version', '~> 1.0.0'
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
30
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
+
spec.add_development_dependency 'rubocop', '~> 0.48.1'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: observe_event
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Scott Lewis
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: version
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.48.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.48.1
|
83
|
+
description: |-
|
84
|
+
Enables an object to define an event method which to becomes a publisher/observable.
|
85
|
+
Subscribers/observers can to be defined dynamically via a block given to the event.
|
86
|
+
email:
|
87
|
+
- ryanscottlewis@gmail.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".rubocop.yml"
|
95
|
+
- ".templates.yml"
|
96
|
+
- ".travis.yml"
|
97
|
+
- CODE_OF_CONDUCT.md
|
98
|
+
- Gemfile
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- VERSION
|
103
|
+
- bin/setup
|
104
|
+
- examples/player.rb
|
105
|
+
- examples/simple.rb
|
106
|
+
- examples/user.rb
|
107
|
+
- lib/observe_event.rb
|
108
|
+
- observe_event.gemspec
|
109
|
+
- templates/LICENSE.txt.erb
|
110
|
+
- templates/README.md.erb
|
111
|
+
- templates/observe_event.gemspec.erb
|
112
|
+
homepage: https://github.com/RyanScottLewis/observe_event
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.6.11
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Small and effective implementation of the observer pattern to define event
|
136
|
+
methods on objects.
|
137
|
+
test_files: []
|