Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
03d5b793
Commit
03d5b793
authored
Aug 11, 2014
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[HooksManager] Introduction
parent
4e084442
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
132 additions
and
0 deletions
+132
-0
cocoapods.rb
lib/cocoapods.rb
+1
-0
hooks_manager.rb
lib/cocoapods/hooks_manager.rb
+65
-0
hooks_manager_spec.rb
spec/unit/hooks_manager_spec.rb
+66
-0
No files found.
lib/cocoapods.rb
View file @
03d5b793
...
@@ -40,6 +40,7 @@ module Pod
...
@@ -40,6 +40,7 @@ module Pod
autoload
:Executable
,
'cocoapods/executable'
autoload
:Executable
,
'cocoapods/executable'
autoload
:ExternalSources
,
'cocoapods/external_sources'
autoload
:ExternalSources
,
'cocoapods/external_sources'
autoload
:Installer
,
'cocoapods/installer'
autoload
:Installer
,
'cocoapods/installer'
autoload
:HooksManager
,
'cocoapods/hooks_manager'
autoload
:PodTarget
,
'cocoapods/target/pod_target'
autoload
:PodTarget
,
'cocoapods/target/pod_target'
autoload
:Project
,
'cocoapods/project'
autoload
:Project
,
'cocoapods/project'
autoload
:Resolver
,
'cocoapods/resolver'
autoload
:Resolver
,
'cocoapods/resolver'
...
...
lib/cocoapods/hooks_manager.rb
0 → 100644
View file @
03d5b793
module
Pod
# Provides support for the hook system of CocoaPods. The system is designed
# especially for plugins. Interested clients can register to notifications by
# name.
#
# The blocks, to prevent compatibility issues, will receive
# one and only one argument: a context object. This object should be simple
# storage of information (a typed hash). Notifications senders are
# responsible to indicate the class of the object associated with their
# notification name.
#
# Context object should not remove attribute accessors to not break
# compatibility with the plugins (this promise will be honoured strictly
# from CocoaPods 1.0).
#
module
HooksManager
class
<<
self
# @return [Hash{Symbol => Proc}] The list of the blocks that are
# registered for each notification name.
#
attr_reader
:registrations
# Registers a block for the hook with the given name.
#
# @param [Symbol] name
# The name of the notification.
#
# @param [Proc] block
# The block.
#
def
register
(
name
,
&
block
)
raise
ArgumentError
,
'Missing name'
unless
name
raise
ArgumentError
,
'Missing block'
unless
block
@registrations
||=
Hash
.
new
@registrations
[
name
]
||=
Array
.
new
@registrations
[
name
]
<<
block
end
# Runs all the registered blocks for the hook with the given name.
#
# @param [Symbol] name
# The name of the hook.
#
# @param [Object] context
# The context object which should be passed to the blocks.
#
def
run
(
name
,
context
)
raise
ArgumentError
,
'Missing name'
unless
name
raise
ArgumentError
,
'Missing options'
unless
context
if
@registrations
blocks
=
@registrations
[
name
]
if
blocks
blocks
.
each
do
|
block
|
block
.
call
(
context
)
end
end
end
end
end
end
end
spec/unit/hooks_manager_spec.rb
0 → 100644
View file @
03d5b793
require
File
.
expand_path
(
'../../spec_helper'
,
__FILE__
)
module
Pod
describe
HooksManager
do
before
do
@hooks_manager
=
Pod
::
HooksManager
end
describe
'register'
do
it
"allows to register a block for a notification with a given name"
do
@hooks_manager
.
register
(
:post_install
)
{}
@hooks_manager
.
registrations
[
:post_install
].
count
.
should
==
1
@hooks_manager
.
registrations
[
:post_install
].
first
.
class
.
should
==
Proc
end
it
"raises if no name is given"
do
should
.
raise
ArgumentError
do
@hooks_manager
.
register
(
nil
)
{}
end
end
it
"raises if no block is given"
do
should
.
raise
ArgumentError
do
@hooks_manager
.
register
(
:post_install
)
end
end
end
describe
'run'
do
it
"invokes the hooks"
do
@hooks_manager
.
register
(
:post_install
)
do
|
options
|
true
.
should
.
be
.
true
end
@hooks_manager
.
run
(
:post_install
,
Object
.
new
)
end
it
"handles the case that no listeners have registered"
do
should
.
not
.
raise
do
@hooks_manager
.
run
(
:post_install
,
Object
.
new
)
end
end
it
"handles the case that no listeners have registered for a name"
do
@hooks_manager
.
register
(
:post_install
)
do
|
options
|
true
.
should
.
be
.
true
end
should
.
not
.
raise
do
@hooks_manager
.
run
(
:pre_install
,
Object
.
new
)
end
end
it
"raises if no name is given"
do
should
.
raise
ArgumentError
do
@hooks_manager
.
run
(
nil
,
Object
.
new
)
{}
end
end
it
"raises if no context object is given"
do
should
.
raise
ArgumentError
do
@hooks_manager
.
run
(
:post_install
,
nil
)
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment