callbacks_rb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20c32d2155725e636c7f165ccd2f1d11b8d82388
4
+ data.tar.gz: 0ef01c256d08ef9020b1be275bc5722855808b7e
5
+ SHA512:
6
+ metadata.gz: 089598f54013068cb559bca772ef1e7cf50905ff34a45432883a6f095b1493b0e8094aa4e9f2a2287eb14cde292162036d79b191c2e89f610f3d5c672a2fc1ef
7
+ data.tar.gz: ce9126442046477c5e9fe7bd5cd6352a3979f93a95c41b3fe333a26be4db82e3c8401cadacd2c92fb6d15da790e8ad87d2129301683a970fbc9340e6bc0a3d5e
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in callbacks_rb.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 bibendi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # CallbacksRb
2
+
3
+ External callbacks
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'callbacks_rb'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install callbacks_rb
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ class Foo
25
+ include CallbacksRb
26
+
27
+ callback :on_bar
28
+
29
+ def bar
30
+ fire_callback(:on_bar, 'param')
31
+ end
32
+ end
33
+
34
+ Foo.new.on_bar do |arg|
35
+ puts arg.inspect
36
+ end
37
+
38
+ Foo.bar
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/abak-press/callbacks_rb/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'callbacks_rb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'callbacks_rb'
8
+ spec.version = CallbacksRb::VERSION
9
+ spec.authors = ['Napolskih', 'Merkushin']
10
+ spec.email = ["merkushin.m.s@gmail.com"]
11
+ spec.summary = 'External callbacks'
12
+ spec.homepage = ''
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.7'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ end
@@ -0,0 +1,53 @@
1
+ require 'callbacks_rb/version'
2
+
3
+ module CallbacksRb
4
+ def self.included(base)
5
+ base.class_eval do
6
+ attr_reader :callbacks
7
+
8
+ extend ClassMethods
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ def callback(name)
14
+ send :define_method, "#{name}=" do |method, &block|
15
+ register_callback(name.to_sym, method, &block)
16
+ end
17
+
18
+ send :define_method, "#{name}" do |method = nil, &block|
19
+ register_callback(name.to_sym, method, &block)
20
+ end
21
+ end
22
+ end
23
+
24
+ def register_callback(name, method = nil, &block)
25
+ init_callbacks_list unless @callbacks.present?
26
+ name = name.to_sym
27
+ if block_given?
28
+ (@callbacks[name] ||= []) << block
29
+ elsif method.present?
30
+ (@callbacks[name] ||= []) << method
31
+ end
32
+ self
33
+ end
34
+
35
+ def fire_callback(name, *args)
36
+ name = name.to_sym
37
+ return if !@callbacks || !@callbacks.key?(name)
38
+ @callbacks[name].each { |callback| callback.call(*args) }
39
+ end
40
+
41
+ def register_callbacks(list)
42
+ return if list.blank?
43
+ list.each do |name, block|
44
+ register_callback(name, block)
45
+ end
46
+ end
47
+
48
+ protected
49
+
50
+ def init_callbacks_list
51
+ @callbacks = {}
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module CallbacksRb
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: callbacks_rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Napolskih
8
+ - Merkushin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-01-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ prerelease: false
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.7'
21
+ requirement: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ~>
24
+ - !ruby/object:Gem::Version
25
+ version: '1.7'
26
+ type: :development
27
+ name: bundler
28
+ - !ruby/object:Gem::Dependency
29
+ prerelease: false
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '10.0'
40
+ type: :development
41
+ name: rake
42
+ description:
43
+ email:
44
+ - merkushin.m.s@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - callbacks_rb.gemspec
55
+ - lib/callbacks_rb.rb
56
+ - lib/callbacks_rb/version.rb
57
+ homepage: ''
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: External callbacks
81
+ test_files: []