class CrudService::Service
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.
Attributes
The DAL layer to use, e.g. an instance of CrudService::DAL
The logger to use, e.g. an instance of Console::Logger
Public Class Methods
Instantiate a service with the specified DAL and logger.
# File lib/crud-service/service.rb, line 12 def initialize(dal, log) @dal = dal @log = log end
Public Instance Methods
Delete one record matching the specified primary key
# File lib/crud-service/service.rb, line 42 def delete_by_primary_key(primary_key) @dal.delete_by_primary_key(primary_key) end
Return true if a record matching the specified primary key exists
# 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 records matching the specified query
# 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 records matching the specified query
# 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 a record with the supplied data record
# File lib/crud-service/service.rb, line 18 def insert(data) @dal.insert(data) end
Update one record matching the specified primary key with data
# 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
Return true if the specified data is valid for insert
# File lib/crud-service/service.rb, line 52 def valid_insert?(data) @dal.valid_insert?(data) end
Return true if the specified query is valid
# File lib/crud-service/service.rb, line 57 def valid_query?(query) @dal.valid_query?(query) end
Return true if the specified data is valid for update
# File lib/crud-service/service.rb, line 62 def valid_update?(data) @dal.valid_update?(data) end