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. -
– unregisterEmptySectionsUnregisters all sections that have no method. -
sectionsThe 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. -
methodsThe array of all registered methods asGBMethodDatainstances in the order of registration. property -
classMethodsThe array of all registered class methods asGBMethodDatainstances sorten by method selector strings. property -
instanceMethodsThe array of all registered instance methods asGBMethodDatainstances sorten by method selector strings. property -
propertiesThe array of all registered properties asGBMethodDatainstances sorten by property name strings. property
Helper methods
-
– mergeDataFromMethodsProvider:Merges data from the given methods provider.
Output helpers
-
hasSectionsSpecifies whether there is at least one section registered. property -
hasMultipleSectionsSpecifies whether there is are at least two sections registered. property -
hasClassMethodsSpecifies whether there is are at least one class method registered. property -
hasInstanceMethodsSpecifies whether there is are at least one instance method registered. property -
hasPropertiesSpecifies 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 *classMethodsDiscussion
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.hhasClassMethods
Specifies whether there is are at least one class method registered.
@property (readonly) BOOL hasClassMethodsDiscussion
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.hhasInstanceMethods
Specifies whether there is are at least one instance method registered.
@property (readonly) BOOL hasInstanceMethodsDiscussion
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.hhasMultipleSections
Specifies whether there is are at least two sections registered.
@property (readonly) BOOL hasMultipleSectionsDiscussion
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.hhasProperties
Specifies whether there is are at least one property registered.
@property (readonly) BOOL hasPropertiesDiscussion
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.hhasSections
Specifies whether there is at least one section registered.
@property (readonly) BOOL hasSectionsDiscussion
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.hinstanceMethods
The array of all registered instance methods as GBMethodData instances sorten by method selector strings.
@property (readonly) NSArray *instanceMethodsDiscussion
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.hmethods
The array of all registered methods as GBMethodData instances in the order of registration.
@property (readonly) NSArray *methodsDeclared In
GBMethodsProvider.hproperties
The array of all registered properties as GBMethodData instances sorten by property name strings.
@property (readonly) NSArray *propertiesDiscussion
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.hsections
The array of all registered sections in the order of registration.
@property (readonly) NSArray *sectionsDiscussion
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.hInstance Methods
initWithParentObject:
Initializes methods provider with the given parent object.
- (id)initWithParentObject:(id)parentParameters
- 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.hmergeDataFromMethodsProvider:
Merges data from the given methods provider.
- (void)mergeDataFromMethodsProvider:(GBMethodsProvider *)sourceParameters
- source
GBMethodsProviderto 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.hmethodBySelector:
Returns the method that matches the given selector.
- (GBMethodData *)methodBySelector:(NSString *)selectorParameters
- 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.hregisterMethod:
Registers the given method to the providers data.
- (void)registerMethod:(GBMethodData *)methodParameters
- 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.hregisterSectionIfNameIsValid:
Registers a new section if the given name is valid section name.
- (GBMethodSectionData *)registerSectionIfNameIsValid:(NSString *)nameParameters
- 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.hregisterSectionWithName:
Registers a new section with the given name.
- (GBMethodSectionData *)registerSectionWithName:(NSString *)nameParameters
- 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.hunregisterEmptySections
Unregisters all sections that have no method.
- (void)unregisterEmptySectionsDiscussion
This is useful for cleaning up.
Declared In
GBMethodsProvider.hunregisterMethod:
Unregisters the given method from the providers data.
- (void)unregisterMethod:(GBMethodData *)methodParameters
- 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