Class: Lesli::ApplicationLesliService
- Inherits:
-
Object
- Object
- Lesli::ApplicationLesliService
- Defined in:
- app/services/lesli/application_lesli_service.rb
Direct Known Subclasses
ControllerOperator, Role::ActionService, RoleOperator, RoleService, User::SessionService, UserService
Instance Method Summary collapse
-
#create(params) ⇒ Object
Standard method to create new resource into the database.
-
#delete ⇒ Object
Standard method to delete data from the database.
-
#error(error) ⇒ Object
Register a new error for the current service object.
-
#errors ⇒ Object
Get the list of erros.
-
#errors_as_sentence ⇒ Object
Get the list of erros as single string.
-
#find(resource = nil) ⇒ Object
Find an specific resource through the main id.
-
#found? ⇒ Boolean
Method to check if the service object has data available this method ment to be used together and after the find method.
-
#index(params = nil) ⇒ Object
Standard method to index data from the database.
-
#initialize(current_user = nil, query = {}) ⇒ ApplicationLesliService
constructor
Service constructor current_user is always required to initialize a service object current user is used to get the data only from the account context.
-
#list(params = nil) ⇒ Object
Standard method to list data from the database.
-
#result ⇒ Object
Return the resource as a result.
-
#show ⇒ Object
Standard method to show data from the database.
-
#successful? ⇒ Boolean
Check if the service object has errors.
-
#update(params) ⇒ Object
Standard method to update resources into the database.
Constructor Details
#initialize(current_user = nil, query = {}) ⇒ ApplicationLesliService
Service constructor current_user is always required to initialize a service object current user is used to get the data only from the account context
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/services/lesli/application_lesli_service.rb', line 49 def initialize current_user=nil, query={} # make the current user globaly available in the service object @current_user = current_user # stores the resources from the database as result of the active record queries @resource = nil # stores any error found during the life-cycle of the service object @failures = [] # standard conditions to query the database @query = query end |
Instance Method Details
#create(params) ⇒ Object
Standard method to create new resource into the database
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/services/lesli/application_lesli_service.rb', line 92 def create params # Example: # user = current_user.account.users.new(params) # if user.save # self.resource = user # else # self.error(user.errors.full_messages.to_sentence) # end self.resource = params self end |
#delete ⇒ Object
Standard method to delete data from the database
112 113 |
# File 'app/services/lesli/application_lesli_service.rb', line 112 def delete end |
#error(error) ⇒ Object
Register a new error for the current service object
142 143 144 |
# File 'app/services/lesli/application_lesli_service.rb', line 142 def error error self.failures.push(error) end |
#errors ⇒ Object
Get the list of erros
130 131 132 |
# File 'app/services/lesli/application_lesli_service.rb', line 130 def errors self.failures end |
#errors_as_sentence ⇒ Object
Get the list of erros as single string
136 137 138 |
# File 'app/services/lesli/application_lesli_service.rb', line 136 def errors_as_sentence self.failures.to_sentence end |
#find(resource = nil) ⇒ Object
Find an specific resource through the main id
66 67 68 69 70 71 72 73 |
# File 'app/services/lesli/application_lesli_service.rb', line 66 def find resource = nil # Look for the resource in the database # self.resource = current_user.account.users.find_by_id(id) # example # Should always return self self.resource = resource if resource self end |
#found? ⇒ Boolean
Method to check if the service object has data available this method ment to be used together and after the find method
118 119 120 |
# File 'app/services/lesli/application_lesli_service.rb', line 118 def found? !self.resource.blank? end |
#index(params = nil) ⇒ Object
Standard method to index data from the database
82 83 |
# File 'app/services/lesli/application_lesli_service.rb', line 82 def index params=nil end |
#list(params = nil) ⇒ Object
Standard method to list data from the database
77 78 |
# File 'app/services/lesli/application_lesli_service.rb', line 77 def list params=nil end |
#result ⇒ Object
Return the resource as a result
148 149 150 |
# File 'app/services/lesli/application_lesli_service.rb', line 148 def result self.resource end |
#show ⇒ Object
Standard method to show data from the database
87 88 |
# File 'app/services/lesli/application_lesli_service.rb', line 87 def show end |
#successful? ⇒ Boolean
Check if the service object has errors
124 125 126 |
# File 'app/services/lesli/application_lesli_service.rb', line 124 def successful? self.failures.empty? end |
#update(params) ⇒ Object
Standard method to update resources into the database
107 108 |
# File 'app/services/lesli/application_lesli_service.rb', line 107 def update params end |