Class: Dao::Repository::Base
- Inherits:
-
Object
- Object
- Dao::Repository::Base
- Defined in:
- lib/dao/repository/base.rb
Class Method Summary collapse
- .all ⇒ Object
- .build(record = nil) ⇒ Object
- .by_criteria(criteria) ⇒ Object
- .by_criteria_count(criteria) ⇒ Object
- .count ⇒ Object
- .delete(domain) ⇒ Object
- .delete_by_id(domain_id) ⇒ Object
- .entity(entity) ⇒ Object
- .find(id, with: nil) ⇒ Object
- .find_by_id(id) ⇒ Object
- .gateway(gateway = nil, source = nil, transformer = nil) ⇒ Object
- .last(with: nil) ⇒ Object
- .save(domain, attributes = {}) ⇒ Object
- .save_all(domains) ⇒ Object
- .with_transaction(&block) ⇒ Object
Class Method Details
.all ⇒ Object
19 20 21 |
# File 'lib/dao/repository/base.rb', line 19 def all scope.all.apply end |
.build(record = nil) ⇒ Object
43 44 45 |
# File 'lib/dao/repository/base.rb', line 43 def build(record = nil) gateway.map(record, {}) end |
.by_criteria(criteria) ⇒ Object
69 70 71 |
# File 'lib/dao/repository/base.rb', line 69 def by_criteria(criteria) criteria.filter(scope) end |
.by_criteria_count(criteria) ⇒ Object
73 74 75 |
# File 'lib/dao/repository/base.rb', line 73 def by_criteria_count(criteria) criteria.count_of_result_items(scope) end |
.count ⇒ Object
39 40 41 |
# File 'lib/dao/repository/base.rb', line 39 def count scope.count.apply end |
.delete(domain) ⇒ Object
57 58 59 |
# File 'lib/dao/repository/base.rb', line 57 def delete(domain) delete_by_id(domain.id) if domain end |
.delete_by_id(domain_id) ⇒ Object
61 62 63 |
# File 'lib/dao/repository/base.rb', line 61 def delete_by_id(domain_id) gateway.delete(domain_id) end |
.entity(entity) ⇒ Object
5 6 7 |
# File 'lib/dao/repository/base.rb', line 5 def entity(entity) @entity = entity end |
.find(id, with: nil) ⇒ Object
23 24 25 26 27 |
# File 'lib/dao/repository/base.rb', line 23 def find(id, with: nil) attributes = {} attributes[:with] = with if with scope.find(id, attributes).apply end |
.find_by_id(id) ⇒ Object
29 30 31 |
# File 'lib/dao/repository/base.rb', line 29 def find_by_id(id) scope.find_by_id(id).apply end |
.gateway(gateway = nil, source = nil, transformer = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/dao/repository/base.rb', line 9 def gateway(gateway = nil, source = nil, transformer = nil) if gateway && source && transformer @gateway = gateway @source = source @transformer = transformer else @gateway.new(@source, @transformer.new(@entity)) end end |
.last(with: nil) ⇒ Object
33 34 35 36 37 |
# File 'lib/dao/repository/base.rb', line 33 def last(with: nil) attributes = {} attributes[:with] = with if with scope.last(attributes).apply end |
.save(domain, attributes = {}) ⇒ Object
47 48 49 |
# File 'lib/dao/repository/base.rb', line 47 def save(domain, attributes = {}) gateway.save!(domain, attributes) end |
.save_all(domains) ⇒ Object
51 52 53 54 55 |
# File 'lib/dao/repository/base.rb', line 51 def save_all(domains) with_transaction do domains.map { |domain| save(domain) } end end |
.with_transaction(&block) ⇒ Object
65 66 67 |
# File 'lib/dao/repository/base.rb', line 65 def with_transaction(&block) gateway.with_transaction(&block) end |