GBMethodsProvider Class Reference
Inherits from | NSObject |
Declared in | GBMethodsProvider.h GBMethodsProvider.m |
Overview
A helper class that unifies methods handling.
Dividing implementation of methods provider to a separate class allows us to abstract the logic and reuse it within any object that needs to handle methods using composition. This breaks down the code into simpler and more managable chunks. It also simplifies methods parsing and handling. To use the class, simply "plug" it to the class that needs to handle methods and provide access through public interface.
The downside is that querrying code becomes a bit more verbose as another method or property needs to be sent before getting access to actual methods data.
Tasks
Initialization & disposal
-
– initWithParentObject:
Initializes methods provider with the given parent object.
Sections handling
-
– registerSectionWithName:
Registers a new section with the given name. -
– registerSectionIfNameIsValid:
Registers a new section if the given name is valid section name. -
– unregisterEmptySections
Unregisters all sections that have no method. -
sections
The array of all registered sections in the order of registration. property
Methods handling
-
– registerMethod:
Registers the given method to the providers data. -
– unregisterMethod:
Unregisters the given method from the providers data. -
– methodBySelector:
Returns the method that matches the given selector. -
methods
The array of all registered methods asGBMethodData
instances in the order of registration. property -
classMethods
The array of all registered class methods asGBMethodData
instances sorten by method selector strings. property -
instanceMethods
The array of all registered instance methods asGBMethodData
instances sorten by method selector strings. property -
properties
The array of all registered properties asGBMethodData
instances sorten by property name strings. property
Helper methods
-
– mergeDataFromMethodsProvider:
Merges data from the given methods provider.
Output helpers
-
hasSections
Specifies whether there is at least one section registered. property -
hasMultipleSections
Specifies whether there is are at least two sections registered. property -
hasClassMethods
Specifies whether there is are at least one class method registered. property -
hasInstanceMethods
Specifies whether there is are at least one instance method registered. property -
hasProperties
Specifies whether there is are at least one property registered. property
Properties
classMethods
The array of all registered class methods as GBMethodData
instances sorten by method selector strings.
@property (readonly) NSArray *classMethods
Discussion
This array is automatically filled when methods are registered by sending registerMethod:
to the receiver. If there is no class method registered, empty array is returned.
Declared In
GBMethodsProvider.h
hasClassMethods
Specifies whether there is are at least one class method registered.
@property (readonly) BOOL hasClassMethods
Discussion
This is mainly used as a helper for output generator. It is equivalent querrying for the number of class methods and check if the value is greater than 1, like this: [object.classMethods count] > 0
.
Declared In
GBMethodsProvider.h
hasInstanceMethods
Specifies whether there is are at least one instance method registered.
@property (readonly) BOOL hasInstanceMethods
Discussion
This is mainly used as a helper for output generator. It is equivalent querrying for the number of instance methods and check if the value is greater than 1, like this: [object.instanceMethods count] > 0
.
Declared In
GBMethodsProvider.h
hasMultipleSections
Specifies whether there is are at least two sections registered.
@property (readonly) BOOL hasMultipleSections
Discussion
This is mainly used as a helper for output generator. It is equivalent querrying for the number of sections and check if the value is greater than 1, like this: [object.sections count] > 1
.
See Also
Declared In
GBMethodsProvider.h
hasProperties
Specifies whether there is are at least one property registered.
@property (readonly) BOOL hasProperties
Discussion
This is mainly used as a helper for output generator. It is equivalent querrying for the number of propeties and check if the value is greater than 1, like this: [object.properties count] > 0
.
Declared In
GBMethodsProvider.h
hasSections
Specifies whether there is at least one section registered.
@property (readonly) BOOL hasSections
Discussion
This is mainly used as a helper for output generator. It is equivalent querrying for the number of sections and check if the value is greater than 0, like this: [object.sections count] > 0
.
Declared In
GBMethodsProvider.h
instanceMethods
The array of all registered instance methods as GBMethodData
instances sorten by method selector strings.
@property (readonly) NSArray *instanceMethods
Discussion
This array is automatically filled when methods are registered by sending registerMethod:
to the receiver. If there is no isntance method registered, empty array is returned.
Declared In
GBMethodsProvider.h
methods
The array of all registered methods as GBMethodData
instances in the order of registration.
@property (readonly) NSArray *methods
Declared In
GBMethodsProvider.h
properties
The array of all registered properties as GBMethodData
instances sorten by property name strings.
@property (readonly) NSArray *properties
Discussion
This array is automatically filled when properties are registered by sending registerMethod:
to the receiver. If there is no property registered, empty array is returned.
Declared In
GBMethodsProvider.h
sections
The array of all registered sections in the order of registration.
@property (readonly) NSArray *sections
Discussion
Each section is represented as GBMethodSectionData
object containing the name of the section and the list of all methods registered for that section.
Declared In
GBMethodsProvider.h
Instance Methods
initWithParentObject:
Initializes methods provider with the given parent object.
- (id)initWithParentObject:(id)parent
Parameters
- parent
- The parent object to be used for all registered methods.
Return Value
Returns initialized object.
Discussion
The given parent object is set to each GBMethodData
registered through registerMethod:
. This is the designated initializer.
Exceptions
- NSException
- Thrown if the given parent is
nil
.
Declared In
GBMethodsProvider.h
mergeDataFromMethodsProvider:
Merges data from the given methods provider.
- (void)mergeDataFromMethodsProvider:(GBMethodsProvider *)source
Parameters
- source
GBMethodsProvider
to merge from.
Discussion
This copies all unknown methods from the given source to receiver and invokes merging of data for receivers methods also found in source. It leaves source data intact.
Declared In
GBMethodsProvider.h
methodBySelector:
Returns the method that matches the given selector.
- (GBMethodData *)methodBySelector:(NSString *)selector
Parameters
- selector
- Selector for which to return the method.
Return Value
Returns method data or nil
if no method matches the given selector.
Discussion
If no method matches the given selector, nil
is returned. If nil
or empty string is passed for selector, nil
is returned also.
See Also
Declared In
GBMethodsProvider.h
registerMethod:
Registers the given method to the providers data.
- (void)registerMethod:(GBMethodData *)method
Parameters
- method
- The method to register.
Discussion
If provider doesn't yet have the given method instance registered, the object is added to methods
list. If the same object is already registered, nothing happens. The method is also registered to the end of the list of methods for last registered section. If no section is registered a default section is created. However if another section is registered in such case, a warning is issued!
Note: If another instance of the method with the same selector is registered, an exception is thrown.
Exceptions
- NSException
- Thrown if a method with the same selector is already registered.
See Also
Declared In
GBMethodsProvider.h
registerSectionIfNameIsValid:
Registers a new section if the given name is valid section name.
- (GBMethodSectionData *)registerSectionIfNameIsValid:(NSString *)name
Parameters
- name
- The name of the section.
Return Value
Returns created GBMethodSectionData
object or nil
if name is not valid.
Discussion
The method validates the name string to have at least one char in it and section name is different from last registered section name. If so, it sends the receiver registerSectionWithName:
message, passing it the given name and returns generated GBMethodSectionData
object.. If the name is nil
or empty string, no section is registered and nil
is returned. This is provided only to simplify client code - i.e. no need for testing in each place where section should be registered, while on the other hand, validation tests are nicely encapsulated within the class itself, so no functionality is exposed.
Declared In
GBMethodsProvider.h
registerSectionWithName:
Registers a new section with the given name.
- (GBMethodSectionData *)registerSectionWithName:(NSString *)name
Parameters
- name
- The name of the section.
Return Value
Returns created GBMethodSectionData
object.
Discussion
This creates a new GBMethodSectionData
object with empty array of methods and the given name. Any method registered from now on is added to this section until another section is registered. Registering a section with the same name as one of the existing sections logs a warning but adds the section anyway!
Important: If no section is registered when registering first method, default, no-name section (i.e. [GBMethodSectionData sectionName]
value is nil
) is created automatically. However registering a second (and all subsequent) section would yield a warning in log! This aids creating simple objects which have no section. Note that only a log warning is issued, but all additional sections are added anyway.
Declared In
GBMethodsProvider.h
unregisterEmptySections
Unregisters all sections that have no method.
- (void)unregisterEmptySections
Discussion
This is useful for cleaning up.
Declared In
GBMethodsProvider.h
unregisterMethod:
Unregisters the given method from the providers data.
- (void)unregisterMethod:(GBMethodData *)method
Parameters
- method
- The method to remove.
Discussion
This effectively removes the method from all methods lists as well as from section the method belongs to. If the section becomes empty, the section is removed also. If the method isn't found in the lists, nothing happens.
See Also
Declared In
GBMethodsProvider.h