Class: IntegrationWrapper::Base
- Inherits:
-
Object
- Object
- IntegrationWrapper::Base
- Defined in:
- lib/integration_wrapper/base.rb
Constant Summary collapse
- MODE_ONLINE =
2 modes
"online"
- MODE_OFFLINE =
"offline"
- @@mode =
class methods
Rails.env.eql?("production") ? MODE_ONLINE : MODE_OFFLINE
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Base
constructor
constructor.
- #log(message) ⇒ Object
- #log_enabled? ⇒ Boolean
-
#method_missing(sym, *args, &block) ⇒ Object
If an action comes in, say :foo, then call the foo_online class method if mode is online, and foo_offline if mode is offline.
Constructor Details
#initialize(params = {}) ⇒ Base
constructor
46 47 48 |
# File 'lib/integration_wrapper/base.rb', line 46 def initialize(params = {}) #@mode = Rails.env.eql?("production") ? MODE_ONLINE : MODE_OFFLINE end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
If an action comes in, say :foo, then call the foo_online class method if mode is online, and foo_offline if mode is offline.
def self.perform_action action_name, = {}
self.send("#{action_name}_#{@@mode}", )
end
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/integration_wrapper/base.rb', line 59 def method_missing sym, *args, &block # First check if the method we're trying to call is available. name = "#{sym}_#{@@mode}" if self.respond_to?(name) self.send name, *args, &block else super end end |
Class Method Details
.mode ⇒ Object
29 30 31 |
# File 'lib/integration_wrapper/base.rb', line 29 def self.mode @@mode end |
.mode=(thing) ⇒ Object
33 34 35 36 |
# File 'lib/integration_wrapper/base.rb', line 33 def self.mode= thing raise "Mode must be MODE_ONLINE or MODE_OFFLINE" unless thing.eql?(MODE_ONLINE) || thing.eql?(MODE_OFFLINE) @@mode = thing end |
.modes ⇒ Object
38 39 40 |
# File 'lib/integration_wrapper/base.rb', line 38 def self.modes [MODE_ONLINE, MODE_OFFLINE] end |
Instance Method Details
#log(message) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/integration_wrapper/base.rb', line 74 def log() if log_enabled? Rails.logger.info puts end end |
#log_enabled? ⇒ Boolean
70 71 72 |
# File 'lib/integration_wrapper/base.rb', line 70 def log_enabled? false end |