Class: CrudService::GenericService
- Inherits:
-
Object
- Object
- CrudService::GenericService
- Defined in:
- lib/generic_service.rb
Overview
This class provides a generic service instance for the provided DAL and logger.
Instance Attribute Summary collapse
-
#dal ⇒ Object
Returns the value of attribute dal.
-
#log ⇒ Object
Returns the value of attribute log.
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) ⇒ GenericService
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) ⇒ GenericService
Instantiate a service with the specified DAL and logger.
8 9 10 11 |
# File 'lib/generic_service.rb', line 8 def initialize(dal, log) @dal = dal @log = log end |
Instance Attribute Details
#dal ⇒ Object
Returns the value of attribute dal.
5 6 7 |
# File 'lib/generic_service.rb', line 5 def dal @dal end |
#log ⇒ Object
Returns the value of attribute log.
5 6 7 |
# File 'lib/generic_service.rb', line 5 def log @log end |
Instance Method Details
#delete_by_primary_key(primary_key) ⇒ Object
Delete one record matching the specified primary key
38 39 40 |
# File 'lib/generic_service.rb', line 38 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
43 44 45 |
# File 'lib/generic_service.rb', line 43 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
19 20 21 22 23 |
# File 'lib/generic_service.rb', line 19 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
26 27 28 29 30 |
# File 'lib/generic_service.rb', line 26 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
14 15 16 |
# File 'lib/generic_service.rb', line 14 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
33 34 35 |
# File 'lib/generic_service.rb', line 33 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
48 49 50 |
# File 'lib/generic_service.rb', line 48 def valid_insert?(data) @dal.valid_insert?(data) end |
#valid_query?(query) ⇒ Boolean
Return true if the specified query is valid
53 54 55 |
# File 'lib/generic_service.rb', line 53 def valid_query?(query) @dal.valid_query?(query) end |
#valid_update?(data) ⇒ Boolean
Return true if the specified data is valid for update
58 59 60 |
# File 'lib/generic_service.rb', line 58 def valid_update?(data) @dal.valid_update?(data) end |