ruby_method_wrapper 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 852b2ba10cc7c3bde8b98122f6e650eaf8353047
4
+ data.tar.gz: 96a37bed3ef75a80f12d61e702a436e4738f5998
5
+ SHA512:
6
+ metadata.gz: f14f069b6b1e4acbc912a51f078b952aff7ee7cead850e2d17f4baa8ef6f981261af755c899522d8d609c86a2c42dc6fa836b053b8cff9d5bfd905134ff39312
7
+ data.tar.gz: 35df96ff842f575f535c087cc51158de3cf9a95d4164431a210cbbc03ea511bfca4d98a57d20931c460ec3683223a50fad83c81ec0e6ee1843c38257f0ee55f2
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby_method_wrapper (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rspec (3.4.0)
11
+ rspec-core (~> 3.4.0)
12
+ rspec-expectations (~> 3.4.0)
13
+ rspec-mocks (~> 3.4.0)
14
+ rspec-core (3.4.1)
15
+ rspec-support (~> 3.4.0)
16
+ rspec-expectations (3.4.0)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.4.0)
19
+ rspec-mocks (3.4.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.4.0)
22
+ rspec-support (3.4.1)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ rspec (= 3.4.0)
29
+ ruby_method_wrapper!
30
+
31
+ BUNDLED WITH
32
+ 1.10.6
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # ruby-method-wrapper
2
+
3
+ Allow intercept method invocations. Useful for log, cache, etc...
4
+
5
+ ## Usage
6
+
7
+ Step 1: Include in your Gemfile.
8
+ ```ruby
9
+ gem 'ruby_method_wrapper', git: 'https://github.com/adrianmarino/ruby_method_wrapper.git', branch: 'master'
10
+ ```
11
+
12
+ Step 2: Write an example.
13
+
14
+ ```ruby
15
+ require 'bundler/setup'
16
+ require 'method_wrapper'
17
+
18
+ class Bob
19
+ def say_hello
20
+ puts "Hello!"
21
+ end
22
+ end
23
+
24
+ Bob.wrap_instance_method(pattern: /^say_hello$/, & ->(method, *args, &block) do
25
+ puts "Before call #{method.name}"
26
+ method.call(*args, &block)
27
+ puts "After call #{method.name}"
28
+ end)
29
+
30
+ Bob.new.say_hello
31
+ ```
32
+
33
+ Also is possible:
34
+
35
+ * Invoke private and protected methods.
36
+ * Invoke class methods.
37
+ * Replace method call with another implementation.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new('spec')
4
+
5
+ task :default => :spec
data/bin/test ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require 'method_wrapper'
3
+
4
+ class Bob
5
+ def say_hello
6
+ puts "Hello!"
7
+ end
8
+ end
9
+
10
+ Bob.wrap_instance_method(pattern: /^say_hello$/, & ->(method, *args, &block) do
11
+ puts "Before call #{method.name}"
12
+ method.call(*args, &block)
13
+ puts "After call #{method.name}"
14
+ end)
15
+
16
+ Bob.new.say_hello
@@ -0,0 +1,15 @@
1
+ class Class
2
+ def wrap_method(pattern:, &wrapper)
3
+ methods.grep(pattern).each do |name|
4
+ method = method(name)
5
+ define_singleton_method(name) { |*args, &block| wrapper.call(method, *args, &block) }
6
+ end
7
+ end
8
+
9
+ def wrap_instance_method(pattern:, &wrapper)
10
+ instance_methods.grep(pattern).each do |name|
11
+ method = instance_method(name)
12
+ define_method(name) { |*args, &block| wrapper.call(method.bind(self), *args, &block) }
13
+ end
14
+ end
15
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module MethodWrapper
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ruby_method_wrapper'
8
+ spec.version = MethodWrapper::VERSION
9
+ spec.date = '2015-12-02'
10
+ spec.summary = 'Only another method wrapper lib'
11
+ spec.description = 'Allow wrap instance/class methods to add behavior before, after or arround this'
12
+ spec.authors = 'Adrian Norberto Marino'
13
+ spec.email = 'adrianmarino@gmal.com'
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.require_paths = ['lib']
16
+ spec.licenses = 'MIT'
17
+ spec.homepage = 'http://nonosoft.com.ar'
18
+
19
+ spec.add_development_dependency 'rspec', '3.4.0'
20
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_method_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Adrian Norberto Marino
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.4.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.4.0
27
+ description: Allow wrap instance/class methods to add behavior before, after or arround
28
+ this
29
+ email: adrianmarino@gmal.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - README.md
38
+ - Rakefile
39
+ - bin/test
40
+ - lib/method_wrapper.rb
41
+ - lib/version.rb
42
+ - ruby_method_wrapper.gemspec
43
+ homepage: http://nonosoft.com.ar
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.4.8
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Only another method wrapper lib
67
+ test_files: []
68
+ has_rdoc: