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

dal[RW]

The DAL layer to use, e.g. an instance of CrudService::DAL

log[RW]

The logger to use, e.g. an instance of Console::Logger

Public Class Methods

new(dal, log) click to toggle source

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_by_primary_key(primary_key) click to toggle source

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
exists_by_primary_key?(primary_key) click to toggle source

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_by_query(query) click to toggle source

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_by_query(query) click to toggle source

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(data) click to toggle source

Insert a record with the supplied data record

# File lib/crud-service/service.rb, line 18
def insert(data)
  @dal.insert(data)
end
update_by_primary_key(primary_key, data) click to toggle source

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
valid_insert?(data) click to toggle source

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
valid_query?(query) click to toggle source

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
valid_update?(data) click to toggle source

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