Class: RapidApi::Services::BaseService
- Inherits:
-
Object
- Object
- RapidApi::Services::BaseService
- Defined in:
- lib/rapid_api/services/base_service.rb
Instance Attribute Summary collapse
-
#bang_mode ⇒ Object
Returns the value of attribute bang_mode.
-
#params ⇒ Object
Returns the value of attribute params.
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #add_error(key, message) ⇒ Object
- #after_initialize ⇒ Object
-
#initialize(params = {}) ⇒ BaseService
constructor
A new instance of BaseService.
- #return_value(value) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ BaseService
Returns a new instance of BaseService.
30 31 32 33 34 |
# File 'lib/rapid_api/services/base_service.rb', line 30 def initialize(params={}) @params = params @response = ServiceResponse.new after_initialize end |
Instance Attribute Details
#bang_mode ⇒ Object
Returns the value of attribute bang_mode.
5 6 7 |
# File 'lib/rapid_api/services/base_service.rb', line 5 def bang_mode @bang_mode end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/rapid_api/services/base_service.rb', line 5 def params @params end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/rapid_api/services/base_service.rb', line 5 def response @response end |
Class Method Details
.method_missing(meth, *args, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rapid_api/services/base_service.rb', line 9 def self.method_missing(meth, *args, &block) if meth[-1] == '!' meth = meth.to_s.split('!')[0].to_sym bang_mode = true else bang_mode = false end if instance_methods.include? meth service = self.new(*args) service.bang_mode = bang_mode service.send(meth) if bang_mode return service.response.value else return service.response end else super end end |
Instance Method Details
#add_error(key, message) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rapid_api/services/base_service.rb', line 39 def add_error(key, ) raise "#{key}: #{}" if bang_mode if response.errors.key? key response.errors[key] << else response.errors[key] = [] response.errors[key] << end end |
#after_initialize ⇒ Object
36 37 |
# File 'lib/rapid_api/services/base_service.rb', line 36 def after_initialize end |
#return_value(value) ⇒ Object
50 51 52 |
# File 'lib/rapid_api/services/base_service.rb', line 50 def return_value(value) response.value = value end |