Class: CrudService::Service
- Inherits:
-
Object
- Object
- CrudService::Service
- Defined in:
- lib/service.rb
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) ⇒ 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.
6 7 8 9 |
# File 'lib/service.rb', line 6 def initialize(dal, log) @dal = dal @log = log end |
Instance Attribute Details
#dal ⇒ Object
Returns the value of attribute dal.
3 4 5 |
# File 'lib/service.rb', line 3 def dal @dal end |
#log ⇒ Object
Returns the value of attribute log.
3 4 5 |
# File 'lib/service.rb', line 3 def log @log end |
Instance Method Details
#delete_by_primary_key(primary_key) ⇒ Object
Delete one record matching the specified primary key
36 37 38 |
# File 'lib/service.rb', line 36 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
41 42 43 |
# File 'lib/service.rb', line 41 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
17 18 19 20 21 |
# File 'lib/service.rb', line 17 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
24 25 26 27 28 |
# File 'lib/service.rb', line 24 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
12 13 14 |
# File 'lib/service.rb', line 12 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
31 32 33 |
# File 'lib/service.rb', line 31 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
46 47 48 |
# File 'lib/service.rb', line 46 def valid_insert?(data) @dal.valid_insert?(data) end |
#valid_query?(query) ⇒ Boolean
Return true if the specified query is valid
51 52 53 |
# File 'lib/service.rb', line 51 def valid_query?(query) @dal.valid_query?(query) end |
#valid_update?(data) ⇒ Boolean
Return true if the specified data is valid for update
56 57 58 |
# File 'lib/service.rb', line 56 def valid_update?(data) @dal.valid_update?(data) end |