cpt_hook 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1701e85c384616c631dd22041b978f86d565fb3e
4
+ data.tar.gz: a438af75ca96bebd63e8878dfcf0de8eafbc7474
5
+ SHA512:
6
+ metadata.gz: 0f4980636453eef0c2fd978a0d2c260efb0f1a2a0e3368c0f59f276189ff5b1a41a0f9682b16fd4e3594b25f7396f054b0a19f2a917081bb85e761bea7e51e1f
7
+ data.tar.gz: 97c51cfbc2d47811540b21810ca4227e3af3d3382f7ee131d7ee588c39a1b123e27f337645b598cec3914cb37a675bc6d7574b4a95623df7ff939632a6ac6b76
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.idea/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake" /></Settings>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$" />
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ </component>
11
+ </module>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding">
4
+ <file url="PROJECT" charset="UTF-8" />
5
+ </component>
6
+ </project>
data/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 1.9.3-p551" project-jdk-type="RUBY_SDK" />
4
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/cpt_hook.iml" filepath="$PROJECT_DIR$/.idea/cpt_hook.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,132 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ChangeListManager">
4
+ <list default="true" id="3693b54d-c907-45c6-9528-2e0394f1319b" name="Default" comment="">
5
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.gitignore" />
6
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.rspec" />
7
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.travis.yml" />
8
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/CODE_OF_CONDUCT.md" />
9
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/Gemfile" />
10
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/LICENSE.txt" />
11
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/README.md" />
12
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/Rakefile" />
13
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/bin/console" />
14
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/bin/setup" />
15
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/cpt_hook.gemspec" />
16
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lib/cpt_hook.rb" />
17
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lib/cpt_hook/version.rb" />
18
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/spec/cpt_hook_spec.rb" />
19
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/spec/spec_helper.rb" />
20
+ </list>
21
+ <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
22
+ <option name="TRACKING_ENABLED" value="true" />
23
+ <option name="SHOW_DIALOG" value="false" />
24
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
25
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
26
+ <option name="LAST_RESOLUTION" value="IGNORE" />
27
+ </component>
28
+ <component name="Git.Settings">
29
+ <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
30
+ </component>
31
+ <component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
32
+ <component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
33
+ <component name="JsGulpfileManager">
34
+ <detection-done>true</detection-done>
35
+ <sorting>DEFINITION_ORDER</sorting>
36
+ </component>
37
+ <component name="ProjectFrameBounds">
38
+ <option name="y" value="22" />
39
+ <option name="width" value="1440" />
40
+ <option name="height" value="874" />
41
+ </component>
42
+ <component name="ProjectView">
43
+ <navigator currentView="ProjectPane" proportions="" version="1">
44
+ <flattenPackages />
45
+ <showMembers />
46
+ <showModules />
47
+ <showLibraryContents />
48
+ <hideEmptyPackages />
49
+ <abbreviatePackageNames />
50
+ <autoscrollToSource />
51
+ <autoscrollFromSource />
52
+ <sortByType />
53
+ <manualOrder />
54
+ <foldersAlwaysOnTop value="true" />
55
+ </navigator>
56
+ <panes>
57
+ <pane id="ProjectPane" />
58
+ <pane id="Scratches" />
59
+ <pane id="Scope" />
60
+ </panes>
61
+ </component>
62
+ <component name="PropertiesComponent">
63
+ <property name="options.lastSelected" value="configurable.group.appearance" />
64
+ <property name="options.splitter.main.proportions" value="0.3" />
65
+ <property name="options.splitter.details.proportions" value="0.2" />
66
+ <property name="WebServerToolWindowFactoryState" value="false" />
67
+ <property name="last_opened_file_path" value="$PROJECT_DIR$" />
68
+ </component>
69
+ <component name="RunDashboard">
70
+ <option name="ruleStates">
71
+ <list>
72
+ <RuleState>
73
+ <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
74
+ </RuleState>
75
+ <RuleState>
76
+ <option name="name" value="StatusDashboardGroupingRule" />
77
+ </RuleState>
78
+ </list>
79
+ </option>
80
+ </component>
81
+ <component name="ShelveChangesManager" show_recycled="false">
82
+ <option name="remove_strategy" value="false" />
83
+ </component>
84
+ <component name="SpringUtil" SPRING_PRE_LOADER_OPTION="true" />
85
+ <component name="TaskManager">
86
+ <task active="true" id="Default" summary="Default task">
87
+ <changelist id="3693b54d-c907-45c6-9528-2e0394f1319b" name="Default" comment="" />
88
+ <created>1511554571329</created>
89
+ <option name="number" value="Default" />
90
+ <option name="presentableId" value="Default" />
91
+ <updated>1511554571329</updated>
92
+ <workItem from="1511554572464" duration="9000" />
93
+ </task>
94
+ <servers />
95
+ </component>
96
+ <component name="TimeTrackingManager">
97
+ <option name="totallyTimeSpent" value="9000" />
98
+ </component>
99
+ <component name="ToolWindowManager">
100
+ <frame x="0" y="22" width="1440" height="874" extended-state="6" />
101
+ <layout>
102
+ <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.24964234" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
103
+ <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
104
+ <window_info id="Messages" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32991013" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
105
+ <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
106
+ <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
107
+ <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
108
+ <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
109
+ <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
110
+ <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
111
+ <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
112
+ <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
113
+ <window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
114
+ <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
115
+ <window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
116
+ <window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="SLIDING" type="SLIDING" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
117
+ <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
118
+ <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
119
+ <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
120
+ </layout>
121
+ </component>
122
+ <component name="TypeScriptGeneratedFilesManager">
123
+ <option name="version" value="1" />
124
+ </component>
125
+ <component name="VcsContentAnnotationSettings">
126
+ <option name="myLimit" value="2678400000" />
127
+ </component>
128
+ <component name="XDebuggerManager">
129
+ <breakpoint-manager />
130
+ <watches-manager />
131
+ </component>
132
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.16.0
@@ -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 donavan.stanley@gmail.com. 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
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in cpt_hook.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 JDonavan
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,41 @@
1
+ # Captain Hook
2
+
3
+ A simple way to add before / after hooks around functions in other objects.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cpt_hook'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cpt_hook
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cpt_hook. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the CptHook project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cpt_hook/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cpt_hook"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/cpt_hook.gemspec ADDED
@@ -0,0 +1,26 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cpt_hook/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cpt_hook'
8
+ spec.version = CptHook::VERSION
9
+ spec.authors = ['JDonavan']
10
+ spec.email = ['donavan.stanley@gmail.com']
11
+
12
+ spec.summary = %q{A simple way to add before / after hooks to other objects methods.}
13
+ spec.homepage = 'https://github.com/Donavan/cpt_hook'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.16'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'delegate'
4
+
5
+ module CptHook
6
+ # A class for extending other classes / modules with before / after hooks.
7
+ #
8
+ class Hookable < SimpleDelegator
9
+ def initialize(obj, method_hooks, additional_contexts = [])
10
+ super(obj)
11
+
12
+ additional_contexts = [additional_contexts] unless additional_contexts.is_a?(Array)
13
+
14
+ _add_hooks(:before, method_hooks, additional_contexts)
15
+ _add_hooks(:after, method_hooks, additional_contexts)
16
+
17
+ method_hooks.map {|h| h[:before] || h[:after]}.uniq.each do |method|
18
+ define_singleton_method(method) do |*args, &block|
19
+ self.send("before_#{method}") if self.respond_to? "before_#{method}"
20
+ #val = __getobj__.send(method, *args, &block)
21
+ val = super(*args, &block)
22
+ self.send("after_#{method}") if self.respond_to? "after_#{method}"
23
+ val
24
+ end
25
+ end
26
+ end
27
+
28
+ def class
29
+ __getobj__.class
30
+ end
31
+
32
+ private
33
+
34
+ def _add_hooks(which, method_hooks, additional_contexts)
35
+ method_hooks.select {|hook| hook.key?(which)}.each do |hook|
36
+ hook[:contexts] = hook.fetch(:contexts, []).concat(additional_contexts)
37
+ define_singleton_method("#{which}_#{hook[which]}") do |*args, &block|
38
+ hook[:call].each do |hook_fn|
39
+ if hook_fn.is_a?(Proc)
40
+ hook_fn.call
41
+ else
42
+ context = hook[:contexts].unshift(__getobj__).find {|c| c.respond_to?(hook_fn)}
43
+ raise "No context found for #{which} hook: #{hook_fn}" unless context
44
+ context.send(hook_fn)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module CptHook
2
+ VERSION = '0.1.0'
3
+ end
data/lib/cpt_hook.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'cpt_hook/version'
2
+ require 'cpt_hook/hookable'
3
+
4
+ module CptHook
5
+ # Your code goes here...
6
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cpt_hook
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - JDonavan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - donavan.stanley@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".idea/.rakeTasks"
64
+ - ".idea/cpt_hook.iml"
65
+ - ".idea/encodings.xml"
66
+ - ".idea/misc.xml"
67
+ - ".idea/modules.xml"
68
+ - ".idea/vcs.xml"
69
+ - ".idea/workspace.xml"
70
+ - ".rspec"
71
+ - ".travis.yml"
72
+ - CODE_OF_CONDUCT.md
73
+ - Gemfile
74
+ - LICENSE.txt
75
+ - README.md
76
+ - Rakefile
77
+ - bin/console
78
+ - bin/setup
79
+ - cpt_hook.gemspec
80
+ - lib/cpt_hook.rb
81
+ - lib/cpt_hook/hookable.rb
82
+ - lib/cpt_hook/version.rb
83
+ homepage: https://github.com/Donavan/cpt_hook
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.6.13
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: A simple way to add before / after hooks to other objects methods.
107
+ test_files: []