Class: CrudService::Service
- Inherits:
-
Object
- Object
- CrudService::Service
- Defined in:
- lib/crud-service/service.rb
Overview
Service provides a generic mapping layer between the API and the DAL. You should extend this class, or provide a class with the same interface, to implement service level functionality, or support REST-like RPC.
Instance Attribute Summary collapse
-
#dal ⇒ Object
The DAL layer to use, e.g.
-
#log ⇒ Object
The logger to use, e.g.
Instance Method Summary collapse
-
#delete_by_primary_key(primary_key) ⇒ Object
Delete one record matching the specified primary key.
-
#exists_by_primary_key?(primary_key) ⇒ Boolean
Return true if a record matching the specified primary key exists.
-
#get_all_by_query(query) ⇒ Object
Get all records matching the specified query.
-
#get_one_by_query(query) ⇒ Object
Get one records matching the specified query.
-
#initialize(dal, log) ⇒ Service
constructor
Instantiate a service with the specified DAL and logger.
-
#insert(data) ⇒ Object
Insert a record with the supplied data record.
-
#update_by_primary_key(primary_key, data) ⇒ Object
Update one record matching the specified primary key with data.
-
#valid_insert?(data) ⇒ Boolean
Return true if the specified data is valid for insert.
-
#valid_query?(query) ⇒ Boolean
Return true if the specified query is valid.
-
#valid_update?(data) ⇒ Boolean
Return true if the specified data is valid for update.
Constructor Details
#initialize(dal, log) ⇒ Service
Instantiate a service with the specified DAL and logger.
12 13 14 15 |
# File 'lib/crud-service/service.rb', line 12 def initialize(dal, log) @dal = dal @log = log end |
Instance Attribute Details
#dal ⇒ Object
The DAL layer to use, e.g. an instance of CrudService::DAL
7 8 9 |
# File 'lib/crud-service/service.rb', line 7 def dal @dal end |
#log ⇒ Object
The logger to use, e.g. an instance of Console::Logger
9 10 11 |
# File 'lib/crud-service/service.rb', line 9 def log @log end |
Instance Method Details
#delete_by_primary_key(primary_key) ⇒ Object
Delete one record matching the specified primary key
42 43 44 |
# File 'lib/crud-service/service.rb', line 42 def delete_by_primary_key(primary_key) @dal.delete_by_primary_key(primary_key) end |
#exists_by_primary_key?(primary_key) ⇒ Boolean
Return true if a record matching the specified primary key exists
47 48 49 |
# File 'lib/crud-service/service.rb', line 47 def exists_by_primary_key?(primary_key) @dal.exists_by_primary_key?(primary_key) end |
#get_all_by_query(query) ⇒ Object
Get all records matching the specified query
23 24 25 26 27 |
# File 'lib/crud-service/service.rb', line 23 def get_all_by_query(query) res = @dal.get_all_by_query(query) @dal.map_in_included_relations!(res,query) res end |
#get_one_by_query(query) ⇒ Object
Get one records matching the specified query
30 31 32 33 34 |
# File 'lib/crud-service/service.rb', line 30 def get_one_by_query(query) res = get_all_by_query(query) return nil if res.length == 0 res[0] end |
#insert(data) ⇒ Object
Insert a record with the supplied data record
18 19 20 |
# File 'lib/crud-service/service.rb', line 18 def insert(data) @dal.insert(data) end |
#update_by_primary_key(primary_key, data) ⇒ Object
Update one record matching the specified primary key with data
37 38 39 |
# File 'lib/crud-service/service.rb', line 37 def update_by_primary_key(primary_key, data) @dal.update_by_primary_key(primary_key,data) end |
#valid_insert?(data) ⇒ Boolean
Return true if the specified data is valid for insert
52 53 54 |
# File 'lib/crud-service/service.rb', line 52 def valid_insert?(data) @dal.valid_insert?(data) end |
#valid_query?(query) ⇒ Boolean
Return true if the specified query is valid
57 58 59 |
# File 'lib/crud-service/service.rb', line 57 def valid_query?(query) @dal.valid_query?(query) end |
#valid_update?(data) ⇒ Boolean
Return true if the specified data is valid for update
62 63 64 |
# File 'lib/crud-service/service.rb', line 62 def valid_update?(data) @dal.valid_update?(data) end |