crochets 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: fa8f043b2077e645ba3d3cc2ee8e0f5ad357317f
4
+ data.tar.gz: e7e0aede37071ac4aed8f1e6e3a760e60eda46c6
5
+ !binary "U0hBNTEy":
6
+ metadata.gz: 1df5f29ebbddc42d4b5566e78defdb76e597e9e6946241e500a45835ede91ef9323f480564da79c2391a225d68a749d13c886bb4410dca4a9d555511bfc82055
7
+ data.tar.gz: c896fd6e02c80aa6f9b8013f8bf20e5a297a15a3f5b1499f328319fc2ebb21619b6bc4a787bc241ac998ce76af194e1d05f96ab34a65d35c87c88e5323fdf1e1
@@ -0,0 +1,11 @@
1
+ # .document is used by rdoc and yard to know how to generate documentation
2
+ # for example, it can be used to control how rdoc gets built when you do `gem install foo`
3
+
4
+ README.rdoc
5
+ lib/**/*.rb
6
+ bin/*
7
+
8
+ # Files below this - are treated as 'extra files', and aren't parsed for ruby code
9
+ -
10
+ features/**/*.feature
11
+ LICENSE
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ crochets.komodoproject
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in crochets.gemspec
4
+ gemspec
5
+
6
+ gem 'aquarium', '~> 0.6.0', :git => 'git://github.com/deanwampler/Aquarium.git'
7
+
8
+ gem 'rake', :group => :test
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Alexei Matyushkin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ # Crochets
2
+
3
+ [![Build Status](https://travis-ci.org/mudasobwa/crochets.png)](https://travis-ci.org/mudasobwa/crochets)
4
+
5
+ This gem is kinda syntactic sugar for setting hooks on ruby method calls.
6
+
7
+ It uses [Aquarium](https://github.com/deanwampler/Aquarium) for aspects.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'crochets'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install crochets
22
+
23
+ ## Usage
24
+
25
+ The usage is straightforward:
26
+
27
+ ```ruby
28
+ class MyClass
29
+ def my_method
30
+ puts "Hello, world!"
31
+ end
32
+ end
33
+
34
+ @aspect = Crochets.hook(MyClass, :my_method, after: true, blocking: false) do |obj, *args|
35
+ puts "NB: world is now helloed."
36
+ end
37
+
38
+ # ⇒ Hello, world!
39
+ # ⇒ NB: world is now helloed.
40
+ ```
41
+
42
+ The hook may then be unset:
43
+
44
+ ```ruby
45
+ @aspect.unhook
46
+ ```
47
+
48
+ There are many hooks on the same method may be set simultaneously. They will be invoked in
49
+ the order they were set.
50
+
51
+ ### Arguments
52
+
53
+ The method `Crochets::Crocheter#hook` accepts following parameters:
54
+
55
+ * **object or class** `[Class|Object]` the object or class to set the hook on;
56
+ * **method** `Symbol` the name of the method to set the hook on, or `:all_methods`
57
+ * **after** `[TrueClass|FalseClass]` apply the hook _after_ method body execution
58
+ * **before** `[TrueClass|FalseClass]` apply the hook _before_ method body execution
59
+ * **blocking** `[TrueClass|FalseClass]` when `false`, the hook will be executed in the
60
+ separate thread.
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create new Pull Request
@@ -0,0 +1,21 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Tests'
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.rspec_opts = '-Ispec'
8
+ # spec.rcov = true
9
+ end
10
+
11
+ require 'cucumber/rake/task'
12
+ desc 'Cucumber'
13
+ Cucumber::Rake::Task.new(:features)
14
+
15
+ require 'yard'
16
+ desc 'Yard'
17
+ YARD::Rake::YardocTask.new(:yard) do |t|
18
+ t.files = ['**/*.rb', 'features/**/*.feature', 'features/**/*.rb']
19
+ end
20
+
21
+ task :default => :features
@@ -0,0 +1,33 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require 'crochets/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'crochets'
6
+ s.version = Crochets::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.date = '2013-12-26'
9
+ s.authors = ['Alexei Matyushkin']
10
+ s.email = 'am@mudasobwa.ru'
11
+ s.homepage = 'http://github.com/mudasobwa/crochets'
12
+ s.summary = %Q{Library to utilize setting hooks on Ruby classes}
13
+ s.description = %Q{Easy setting of hook chains on Ruby methods calls in rubtime}
14
+ s.extra_rdoc_files = [
15
+ 'LICENSE',
16
+ 'README.md',
17
+ ]
18
+
19
+ s.required_rubygems_version = Gem::Requirement.new('>= 1.3.7')
20
+ s.rubygems_version = '1.3.7'
21
+ s.specification_version = 3
22
+
23
+ s.files = `git ls-files`.split("\n")
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_paths = ['lib']
27
+
28
+ s.add_development_dependency 'rspec'
29
+ s.add_development_dependency 'yard'
30
+ s.add_development_dependency 'cucumber'
31
+ s.add_development_dependency 'yard-cucumber'
32
+ end
33
+
@@ -0,0 +1,26 @@
1
+ Feature: Crochery built on top of Aquarium Aspects library is working
2
+ In order to build and use crochets library
3
+ A user defines hooks and they are called respectively
4
+
5
+ Scenario: Check no hook
6
+ Given The respective aspects are applied
7
+ When I do not set the hook on tester method
8
+ Then the hook is not being called
9
+
10
+ Scenario: Check hook unsetting
11
+ Given The respective aspects are applied
12
+ When I set the hook on tester method
13
+ And I unset the hook on tester method
14
+ Then the hook is not being called
15
+
16
+ Scenario: Check hook setting
17
+ Given The respective aspects are applied
18
+ When I set the hook on tester method
19
+ Then the hook is being called
20
+
21
+ Scenario: Check non-blocking hook setting
22
+ Given The respective aspects are applied
23
+ When I set the non-blocking hook on tester method
24
+ # And I wait for a while
25
+ Then the hook is being called
26
+
@@ -0,0 +1,40 @@
1
+ Given(/^The respective aspects are applied$/) do
2
+
3
+ end
4
+
5
+ When(/^I do not set the hook on tester method$/) do
6
+
7
+ end
8
+
9
+ When(/^I set the hook on tester method$/) do
10
+ @aspect = Crochets.hook(Crochets::Tester, :some_method, before: true) do |obj, *args|
11
+ puts "BLOCKING BEFORE"
12
+ end
13
+ @aspect2 = Crochets.hook(Crochets::Tester, :some_method, before: true) do |obj, *args|
14
+ puts "BLOCKING BEFORE 2"
15
+ end
16
+ end
17
+
18
+ When(/^I set the non\-blocking hook on tester method$/) do
19
+ @aspect = Crochets.hook(Crochets::Tester, :some_method, after: true, blocking: false) do |obj, *args|
20
+ sleep 1
21
+ puts "NON-BLOCKING AFTER"
22
+ end
23
+ end
24
+
25
+ When(/^I wait for a while$/) do
26
+ sleep 1
27
+ end
28
+
29
+ When(/^I unset the hook on tester method$/) do
30
+ Crochets.unhook @aspect
31
+ end
32
+
33
+ Then(/^the hook is being called$/) do
34
+ Crochets::Tester.new.some_method
35
+ end
36
+
37
+ Then(/^the hook is not being called$/) do
38
+ Crochets::Tester.new.some_method
39
+ end
40
+
@@ -0,0 +1,5 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'crochets'
4
+
5
+ require 'rspec/expectations'
@@ -0,0 +1,34 @@
1
+ require_relative 'crochets/version'
2
+ require 'aquarium'
3
+
4
+ module Crochets
5
+ include Aquarium::DSL
6
+
7
+ extend self
8
+
9
+ def hook obj, meth, before: false, after: false, blocking: true, &cb
10
+ this = Class === obj || object == obj
11
+ around \
12
+ :calls_to => meth, \
13
+ :on_types => (Class === obj ? obj : obj.class), \
14
+ :method_options => [:public, :protected, :private] \
15
+ do |join_point, object, *args|
16
+ blocking ? cb.call(object, *args) : Thread.new { cb.call(object, *args) }\
17
+ if before && this
18
+ result = join_point.proceed
19
+ blocking ? cb.call(object, *args) : Thread.new { cb.call(object, *args) } \
20
+ if after && this
21
+ result
22
+ end if before || after
23
+ end
24
+ # Helper method for calling convention consistency
25
+ def unhook aspect
26
+ aspect.unadvise unless aspect.nil?
27
+ end
28
+
29
+ class Tester
30
+ def some_method
31
+ p "Some method"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Crochets
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Crochets do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'crochets'
4
+
5
+ # Requires supporting files with custom matchers and macros, etc,
6
+ # in ./support/ and its subdirectories.
7
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
8
+
9
+ RSpec.configure do |config|
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crochets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexei Matyushkin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-26 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cucumber
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard-cucumber
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Easy setting of hook chains on Ruby methods calls in rubtime
70
+ email: am@mudasobwa.ru
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - LICENSE
75
+ - README.md
76
+ files:
77
+ - .document
78
+ - .gitignore
79
+ - .travis.yml
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - crochets.gemspec
85
+ - features/crochets.feature
86
+ - features/step_definitions/crochets_steps.rb
87
+ - features/support/env.rb
88
+ - lib/crochets.rb
89
+ - lib/crochets/version.rb
90
+ - spec/crochets_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: http://github.com/mudasobwa/crochets
93
+ licenses: []
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: 1.3.7
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.2
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Library to utilize setting hooks on Ruby classes
115
+ test_files: []
116
+ has_rdoc: