Module: SimpleService::ServiceBase::InstanceMethods
Instance Method Summary collapse
- #expects ⇒ Object
- #find_specified_return_keys ⇒ Object
- #returns ⇒ Object
- #setup_execute_chain ⇒ Object
Instance Method Details
#expects ⇒ Object
50 51 52 |
# File 'lib/simple_service/service_base.rb', line 50 def expects self.class.instance_variable_get('@expects') || [] end |
#find_specified_return_keys ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/simple_service/service_base.rb', line 33 def find_specified_return_keys if returns.nil? || returns.empty? context else returns.inject({}) do |to_return, return_param| if context.has_key?(return_param) to_return[return_param] = context[return_param] else error_msg = "#{self.class} tried to return #{return_param}, but it did not exist in the context: #{context.inspect}" raise ReturnKeyError, error_msg end to_return end end end |
#returns ⇒ Object
54 55 56 |
# File 'lib/simple_service/service_base.rb', line 54 def returns self.class.instance_variable_get('@returns') || [] end |
#setup_execute_chain ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/simple_service/service_base.rb', line 16 def setup_execute_chain self.class.class_eval do # grab the method object and hold onto it here execute_method = instance_method(:execute) # redefine the execute method, call the existing execute method object, # and then run return key checking... allows user to implement execute in # their individual command classes without having to call super or any # other method to return only specific context keys define_method :execute do execute_method.bind(self).call find_specified_return_keys end end end |