dao-repository 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/README.md +44 -3
- data/dao-repository.gemspec +1 -0
- data/lib/dao/repository/base.rb +2 -2
- data/lib/dao/repository/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5827809fbc98f7ff12dcab61273ac7df59a68e71
|
4
|
+
data.tar.gz: 2b3e041c27dbdaccb320c7696be119bb73dd52f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4bfb63202fc6817d44f1ff7df626b3ca78c1e7c1d5185d4e507d7e2761821a29cc81129c4d8b691fed469e5c5995a502e318e3a3f7128c680595bbf560a2d2a
|
7
|
+
data.tar.gz: 444d7a536adc80a5a75cec8c71467faa393210046e741c1075b8f3482f6f3a4d9d69d843128756eb3b9bc455a856019645c97812bc81008b5dc7e8b562fa8e7a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# Dao::Repository
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/dao-repository.svg)](https://badge.fury.io/rb/dao-repository)
|
3
4
|
[![Build Status](https://travis-ci.org/dao-rb/dao-repository.svg?branch=master)](https://travis-ci.org/dao-rb/dao-repository)
|
4
5
|
[![Code Climate](https://codeclimate.com/github/dao-rb/dao-repository/badges/gpa.svg)](https://codeclimate.com/github/dao-rb/dao-repository)
|
5
|
-
[![Test Coverage](https://codeclimate.com/
|
6
|
+
[![Test Coverage](https://codeclimate.com/repos/5777e091620b91007d0001e3/badges/c01a62725cb50df7d9f9/coverage.svg)](https://codeclimate.com/repos/5777e091620b91007d0001e3/coverage)
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -19,11 +20,30 @@ And then execute:
|
|
19
20
|
Or install it yourself as:
|
20
21
|
|
21
22
|
$ gem install dao-repository
|
23
|
+
|
24
|
+
## Built-in methods
|
22
25
|
|
23
|
-
|
26
|
+
Repositories in dao-rb are objects that allow you map your data into entities and save them through data gateway.
|
24
27
|
|
25
|
-
|
28
|
+
Basic methods of each repository:
|
29
|
+
|
30
|
+
1. `Repository.all` should return all data.
|
31
|
+
2. `Repository.find` should find entity with given id. You can return entity with its relations by adding a list of them into the second argument (`Repository.find(1, with: [:author, :comments])`), but your gateway should support eager loading. If entity was not found then method will raise an exception.
|
32
|
+
3. `Repository.find_by_id` also should find entity with given id, but if it was not found then method return `nil`.
|
33
|
+
4. `Repository.last` should return last entity. You can return entity with its relations by adding a list of them into the first argument (`Repository.last(with: [:author, :comments])`), but your gateway should support eager loading.
|
34
|
+
5. `Repository.count` should return count of entities.
|
35
|
+
6. `Repository.build` should build entity from data object.
|
36
|
+
7. `Repository.save` should save changes in entity.
|
37
|
+
8. `Repository.save_all` should save collection of entities.
|
38
|
+
9. `Repository.delete` should delete entity.
|
39
|
+
10. `Repository.delete_by_id` should delete entity by id.
|
40
|
+
11. `Repository.with_transaction(&block)` execute block in transaction if gateway support it.
|
41
|
+
12. `Repository.by_criteria` should return entities by given criteria.
|
42
|
+
13. `Repository.by_criteria_count` should return count of elements by given criteria.
|
43
|
+
|
44
|
+
## Usage example
|
26
45
|
|
46
|
+
```ruby
|
27
47
|
require 'dao/entity'
|
28
48
|
require 'dao/repository'
|
29
49
|
require 'dao/gateway/active_record'
|
@@ -58,6 +78,27 @@ post.body # => "Post body"
|
|
58
78
|
post.comments # => [#<CommentEntity:0x007ffdcb923a30>]
|
59
79
|
```
|
60
80
|
|
81
|
+
## Custom methods
|
82
|
+
|
83
|
+
You can define custom methods in your repository:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
class Post < ApplicationRecord
|
87
|
+
has_many :comments
|
88
|
+
|
89
|
+
scope :deleted, -> { where(deleted: true) }
|
90
|
+
end
|
91
|
+
|
92
|
+
class PostRepository < Dao::Repository::Base
|
93
|
+
entity PostEntity
|
94
|
+
gateway Dao::Gateway::ActiveRecord::Base, Post, Dao::Gateway::ActiveRecord::BaseTransformer
|
95
|
+
|
96
|
+
def self.deleted
|
97
|
+
scope.deleted(with: :comments).apply # it will return deleted posts with loaded comments.
|
98
|
+
end
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
61
102
|
## Development
|
62
103
|
|
63
104
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/dao-repository.gemspec
CHANGED
data/lib/dao/repository/base.rb
CHANGED
@@ -67,11 +67,11 @@ module Dao
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def by_criteria(criteria)
|
70
|
-
criteria.filter(scope)
|
70
|
+
criteria.filter(scope)
|
71
71
|
end
|
72
72
|
|
73
73
|
def by_criteria_count(criteria)
|
74
|
-
criteria.count_of_result_items(scope)
|
74
|
+
criteria.count_of_result_items(scope)
|
75
75
|
end
|
76
76
|
|
77
77
|
protected
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dao-repository
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- llxff
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dao-gateway
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: codeclimate-test-reporter
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
84
98
|
description: Base repository for DAO
|
85
99
|
email:
|
86
100
|
- ll.wg.bin@gmail.com
|