ActiveResourceKit  v1.2 (498.0)
 All Classes Files Functions Variables Typedefs Enumerator Properties Macros Pages
Instance Methods | Class Methods | Protected Attributes | Properties | List of all members
ARResource Class Reference

Provides the core class mirroring Rails' ActiveResource::Base class. More...

#import <ARResource.h>

Inheritance diagram for ARResource:
Inheritance graph
[legend]
Collaboration diagram for ARResource:
Collaboration graph
[legend]

Instance Methods

(id) - initWithService:
 
(id) - initWithService:attributes:
 
(id) - initWithService:attributes:persisted:
 
(NSDictionary *) - optionsForSubelement
 Answers options for applying this resource's identity to a nested service.
 
(ARService *) - serviceLazily
 Asks for the resource service, lazily constructing a service instance if the resource does not currently retain a service.
 
(void) - mergeAttributes:
 Merges the contents of a dictionary into the receiver's attributes.
 
(void) - loadAttributes:removeRoot:
 Loads resource attributes from a dictionary of key-value pairs.
 
(NSDictionary *) - schema
 
(NSArray *) - knownAttributes
 Answers all the known attributes belonging to this active resource, a unique array of attribute key strings.
 
(BOOL) - isNew
 
(BOOL) - isNewRecord
 
(NSNumber *) - ID
 Answers the primary key.
 
(void) - setID:
 
(void) - saveWithCompletionHandler:
 
(void) - destroyWithCompletionHandler:
 
(void) - existsWithCompletionHandler:
 
(NSData *) - encode
 Answers a serialised data representation of the resource according to the configured serialisation format.
 
(id) - init [implementation]
 
(id) - copyWithZone: [implementation]
 
(void) - setAttributes: [implementation]
 
(id) - valueForUndefinedKey: [implementation]
 
(void) - setValue:forUndefinedKey: [implementation]
 
(void) - setNilValueForKey: [implementation]
 
(NSDictionary *) - dictionaryWithValuesForKeys: [implementation]
 Transfers values from the resource attributes to a dictionary, answering the dictionary.
 
(void) - setValuesForKeysWithDictionary: [implementation]
 
(NSString *) - description [implementation]
 
(void) - updateWithCompletionHandler:
 
(void) - createWithCompletionHandler:
 
(void) - loadAttributesFromResponse:attributes:
 
(NSString *) - elementPathWithOptions:
 Answers this resource's element path.
 
(NSArray *) - toKey
 Enumerates all key attributes.
 
(NSString *) - toParam
 

Class Methods

(ARService *) + service
 Constructs an active resource service using class methods to establish the site and element name.
 

Protected Attributes

NSMutableDictionary *__strong _attributes
 

Properties

ARServiceservice
 
NSDictionary * attributes
 
NSDictionary * prefixOptions
 
BOOL persisted
 

Detailed Description

Provides the core class mirroring Rails' ActiveResource::Base class.

An active resource mimics an active record. Resources behave as records. Only their connection fundamentally differs. Active Records connect to a database whereas Active Resources connect to a RESTful API accessed via HTTP transport.

Class_Diagram__Service_and_Resource.png

Definition at line 40 of file ARResource.h.

Method Documentation

- (id) copyWithZone: (NSZone *)  zone
implementation

Definition at line 64 of file ARResource.m.

- (void) createWithCompletionHandler: (ARHTTPResponse *response, NSError *error)  completionHandler

Provided by category ARResource(Private).

Definition at line 78 of file ARResource+Private.m.

- (NSString *) description
implementation

Definition at line 343 of file ARResource.m.

- (void) destroyWithCompletionHandler: (ARHTTPResponse *response, NSError *error)  completionHandler

Definition at line 319 of file ARResource.m.

- (NSDictionary *) dictionaryWithValuesForKeys: (NSArray *)  keys
implementation

Transfers values from the resource attributes to a dictionary, answering the dictionary.

Accesses the values by sending -valueForKey:aKey to self, where aKey conforms to key-value coding requirements, i.e. lower camel-case. This invokes -valueForUndefinedKey:aKey on self which performs the aKey to a_key translation to Rails resource attribute name.

Definition at line 230 of file ARResource.m.

- (NSString *) elementPathWithOptions: (NSDictionary *)  options

Answers this resource's element path.

Parameters
optionsPrefix and query options for overriding the existing resource prefix options if any.

Provided by category ARResource(Private).

Definition at line 115 of file ARResource+Private.m.

- (NSData *) encode

Answers a serialised data representation of the resource according to the configured serialisation format.

Definition at line 333 of file ARResource.m.

- (void) existsWithCompletionHandler: (ARHTTPResponse *response, BOOL exists, NSError *error)  completionHandler

Definition at line 326 of file ARResource.m.

- (NSNumber *) ID

Answers the primary key.

By convention, Rails' primary keys appear in the column named id. Column type is integer. Hence the ActiveResourceKit implementation answers the primary key only if the type is a number. (This includes other types of number.) Otherwise it answers nil.

Integer Width
The exact integer type depends on the database implementation and configuration at the server side. Databases typically store integers as signed 32-bit integers. Send -[NSNumber intValue] to the resulting number to retrieve the signed 32-bit identifier in such cases.

Definition at line 292 of file ARResource.m.

- (id) init
implementation

Definition at line 54 of file ARResource.m.

- (id) initWithService: (ARService *)  service

Definition at line 95 of file ARResource.m.

- (id) initWithService: (ARService *)  service
attributes: (NSDictionary *)  attributes 

Definition at line 106 of file ARResource.m.

- (id) initWithService: (ARService *)  service
attributes: (NSDictionary *)  attributes
persisted: (BOOL)  persisted 

Definition at line 116 of file ARResource.m.

- (BOOL) isNew

Definition at line 278 of file ARResource.m.

- (BOOL) isNewRecord

Definition at line 283 of file ARResource.m.

- (NSArray *) knownAttributes

Answers all the known attributes belonging to this active resource, a unique array of attribute key strings.

The resulting array includes all the service's known attributes plus this resource instance's known attributes. Duplicates if any do not appear. This deviates from Rails at version 3.1.0 where duplicates do appear.

Definition at line 264 of file ARResource.m.

- (void) loadAttributes: (NSDictionary *)  attributes
removeRoot: (BOOL)  removeRoot 

Loads resource attributes from a dictionary of key-value pairs.

Argument removeRoot becomes a do-not-care if attributes contains just a single key-object pair. In such a case, removing the root depends on whether or not the single key matches the service element name.

Attribute keys use Rails conventions: underscored and lower case. You can also access the attribute values using Key-Value Coding where the keys follow Cocoa conventions: camel case with leading lower case letter. The resource translates the KVC-style keys to Rails conventions when looking up the corresponding value, aKey becomes a_key.

Definition at line 181 of file ARResource.m.

- (void) loadAttributesFromResponse: (ARHTTPResponse *)  response
attributes: (NSDictionary *)  attributes 
Parameters
responseA HTTP response wrapper.
attributesSet of attributes decoded from the response body.

Provided by category ARResource(Private).

Definition at line 102 of file ARResource+Private.m.

- (void) mergeAttributes: (NSDictionary *)  attributes

Merges the contents of a dictionary into the receiver's attributes.

Parameters
attributesThe dictionary (or hash) of attribute key-value pairs used for merging with the receiver's attributes.

If keys within the given dictionary of attributes match keys in the receiver's current attributes, merging replaces the objects in the receiver by those in the given dictionary.

Definition at line 169 of file ARResource.m.

- (NSDictionary *) optionsForSubelement

Answers options for applying this resource's identity to a nested service.

Use it to access this resource's subelements. First derive a nested service for the subelement. Doing so parameterises the resource identity. Then apply these options to select this resource's subelement or subelements.

Definition at line 126 of file ARResource.m.

- (void) saveWithCompletionHandler: (ARHTTPResponse *response, NSError *error)  completionHandler

Definition at line 307 of file ARResource.m.

- (NSDictionary *) schema

Definition at line 258 of file ARResource.m.

+ (ARService *) service

Constructs an active resource service using class methods to establish the site and element name.

If the ARResource sub-class has a class method called +site, use its answer to set up the Active Resource site. This assumes that +site answers an NSURL object. Similarly, sets up the service element name by sending +elementName to the sub-class, answering a string. However, if the sub-class does not implement the +elementName class method, the element name derives from the ARResource sub-class name.

- (ARService *) serviceLazily

Asks for the resource service, lazily constructing a service instance if the resource does not currently retain a service.

Asks the class for a site URL and an element name. Optionally implement +site and +elementName to supply the URL and element name. If your class does not supply an implementation for +elementName, the element name derives from the sub-class name. This assumes that you do not directly instantiate the ARResource class. If you do, the element name remains nil.

Definition at line 137 of file ARResource.m.

- (void) setAttributes: (NSDictionary *)  attributes
implementation

Definition at line 161 of file ARResource.m.

- (void) setID: (NSNumber *)  ID

Definition at line 298 of file ARResource.m.

- (void) setNilValueForKey: (NSString *)  key
implementation

Definition at line 216 of file ARResource.m.

- (void) setValue: (id)  value
forUndefinedKey: (NSString *)  key 
implementation

Definition at line 211 of file ARResource.m.

- (void) setValuesForKeysWithDictionary: (NSDictionary *)  keyedValues
implementation

Definition at line 240 of file ARResource.m.

- (NSArray *) toKey

Enumerates all key attributes.

Returns
Only answers key attributes if the resource persists. Answers nil otherwise since key attributes only logically exist when the resource begins to persist.

Provided by category ARResource(Private).

Definition at line 124 of file ARResource+Private.m.

- (NSString *) toParam

Provided by category ARResource(Private).

Definition at line 129 of file ARResource+Private.m.

- (void) updateWithCompletionHandler: (ARHTTPResponse *response, NSError *error)  completionHandler

Provided by category ARResource(Private).

Definition at line 55 of file ARResource+Private.m.

- (id) valueForUndefinedKey: (NSString *)  key
implementation

Definition at line 206 of file ARResource.m.

Member Data Documentation

- (NSMutableDictionary* __strong) _attributes
protected

Definition at line 46 of file ARResource.m.

Property Documentation

- (NSDictionary *) attributes
readwriteatomiccopy

Definition at line 92 of file ARResource.h.

- (BOOL) persisted
readwriteatomicassign

Definition at line 138 of file ARResource.h.

- (NSDictionary*) prefixOptions
readwriteatomiccopy

Definition at line 120 of file ARResource.h.

- (ARService *) service
readwriteatomicstrong

Retains the active-resource service. Does not copy the service. This has important implications. If you alter service properties, the changes affect all the resources which depend upon it.

Definition at line 77 of file ARResource.h.


The documentation for this class was generated from the following files: