From 12970b6bbb7c197c5495990af028243ccfb6cc57 Mon Sep 17 00:00:00 2001 From: Nikita Kholin Date: Sat, 29 Jul 2017 22:31:05 +0300 Subject: [PATCH] Create ApplicationService --- app/services/application_service.rb | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/services/application_service.rb diff --git a/app/services/application_service.rb b/app/services/application_service.rb new file mode 100644 index 0000000..be0d0b9 --- /dev/null +++ b/app/services/application_service.rb @@ -0,0 +1,32 @@ +# to call: ApplicationService.(params) +# +class ApplicationService + def self.call(*args, **kwargs) + service = new(*args, **kwargs) + service.perform + service + end + + # def initialize(*args, **kwargs) + # kwargs.each do |method_name, method_value| + # define_method(method_name) { method_value } + # end + # end + + def perform + raise NotImplementedError, 'This is an abstract method' + end + + def errors + # http://api.rubyonrails.org/classes/ActiveModel/Errors.html + {} + end + + def success? + errors.empty? + end + + def failure? + !success? + end +end