Skip to content

What's the "correct" way to define a lazy attribute? #1

@modocache

Description

@modocache

See: https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#lazy-attributes

I believe can achieve the same effect by using sequence and simply ignoring the index parameter i:

#import <Defactory/Defactory.h>
#import "MyModel.h"

FACTORIES(^{
    [MyModel defineFactory:^(LSFactory *f) {
        f[@"createdAt"] = sequence(^(NSUInteger i) { return [NSDate date]; });
    }];
});

Is this "correct"? How would you feel about adding a lazy function for this specific purpose? Something like:

f[@"createdAt"] = lazy(^{ return [NSDate date]; });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions