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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6890c6589d8ea47c9f205ee4af121827a39c9bce
4
- data.tar.gz: 570e8f15e5c5e872339e61f6f5ddd4365245b975
3
+ metadata.gz: 5827809fbc98f7ff12dcab61273ac7df59a68e71
4
+ data.tar.gz: 2b3e041c27dbdaccb320c7696be119bb73dd52f2
5
5
  SHA512:
6
- metadata.gz: daedd61870cfbc19ff7886a1d64707ebd208f334fb26720ed08d883595c20bbfd812a739dbc8e75d550f990d4a8e553246d0d6a73f0565e042dcf236e06c92d9
7
- data.tar.gz: 9d638399e8ebb4b696871bf0506c755d2988514fd004e79ac5ade4c593df18de6ff82187f19a84388fe97365d05cdfff25c83f9c371e9bc033866f7add6f7478
6
+ metadata.gz: c4bfb63202fc6817d44f1ff7df626b3ca78c1e7c1d5185d4e507d7e2761821a29cc81129c4d8b691fed469e5c5995a502e318e3a3f7128c680595bbf560a2d2a
7
+ data.tar.gz: 444d7a536adc80a5a75cec8c71467faa393210046e741c1075b8f3482f6f3a4d9d69d843128756eb3b9bc455a856019645c97812bc81008b5dc7e8b562fa8e7a
@@ -3,3 +3,5 @@ rvm:
3
3
  - 2.2.2
4
4
  - 2.3.0
5
5
  before_install: gem install bundler -v 1.11.2
6
+ script:
7
+ - CODECLIMATE_REPO_TOKEN=9b21443096807b1b8e50308cf489cdea452b6d418e1fb48e89e55829b2fb6546 bundle exec rspec
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/github/dao-rb/dao-repository/badges/coverage.svg)](https://codeclimate.com/github/dao-rb/dao-repository/coverage)
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
- ## Usage
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.
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'rake', '~> 10.0'
26
26
  spec.add_development_dependency 'rspec', '~> 3.4'
27
27
  spec.add_development_dependency 'rspec-its'
28
+ spec.add_development_dependency 'codeclimate-test-reporter'
28
29
  end
@@ -67,11 +67,11 @@ module Dao
67
67
  end
68
68
 
69
69
  def by_criteria(criteria)
70
- criteria.filter(scope).apply
70
+ criteria.filter(scope)
71
71
  end
72
72
 
73
73
  def by_criteria_count(criteria)
74
- criteria.count_of_result_items(scope).apply
74
+ criteria.count_of_result_items(scope)
75
75
  end
76
76
 
77
77
  protected
@@ -1,5 +1,5 @@
1
1
  module Dao
2
2
  module Repository
3
- VERSION = '1.0.1'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
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.1
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-06-29 00:00:00.000000000 Z
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