Shelf
Shelf is an easy way to implement repository pattern.
But how?
Add @Locker
on your repositories and create a fixture and production implementations for them.
in fixture implementation add the annotation @Fake
and in production implementation add the annotation
@Prod
. Build the project and be happy!
Example
Locker
@Locker public interface Test {
void test();
}
Fake
@Fake public class TestFake implements Test {
@Override
public void test() {
}
}
Prod
@Prod public class TestProd implements Test {
@Override
public void test() {
}
}
You can call your repository with this:
Prod call
Shelf.forTest().withProd().test();
Fake call
Shelf.forTest().withFake().test();
Import
First, import apt classpath in your project gradle file
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
Then import shelf deppendencies in your app gradle file
apply plugin: 'com.neenbedankt.android-apt' dependencies {
compile 'com.bloder.shelf:core:1.0'
apt 'com.bloder.shelf:compiler:1.0'
}