Class: ActiveSalesforce::RecordingBinding
- Inherits:
-
RForce::Binding
- Object
- RForce::Binding
- ActiveSalesforce::RecordingBinding
- Defined in:
- lib/active_record/connection_adapters/recording_binding.rb
Overview
A wrapper for the Salesforce RForce Binding. recording attribute allows you to save web services traffic information for later debug purpose. It is saved to a file which is specified by in the YAML file, e.g. ‘database.yml’ In production, it should not be used, because it generates a lot of overhead.
Instance Attribute Summary collapse
-
#recorded_responses ⇒ Object
readonly
Returns the value of attribute recorded_responses.
Instance Method Summary collapse
-
#call_remote(method, args) ⇒ Object
Call a method on the remote server.
-
#initialize(url, sid, recording, recording_source, logger) ⇒ RecordingBinding
constructor
A new instance of RecordingBinding.
Constructor Details
#initialize(url, sid, recording, recording_source, logger) ⇒ RecordingBinding
Returns a new instance of RecordingBinding.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/active_record/connection_adapters/recording_binding.rb', line 50 def initialize(url, sid, recording, recording_source, logger) super(url, sid) @recording = recording @recorded_responses = {} @recording_source = recording_source @logger = logger unless @recording YAML.load_documents(recording_source) do |recorded_response| @recorded_responses.merge!(recorded_response) end end end |
Instance Attribute Details
#recorded_responses ⇒ Object (readonly)
Returns the value of attribute recorded_responses.
48 49 50 |
# File 'lib/active_record/connection_adapters/recording_binding.rb', line 48 def recorded_responses @recorded_responses end |
Instance Method Details
#call_remote(method, args) ⇒ Object
Call a method on the remote server. Arguments can be a hash or (if order is important) an array of alternating keys and values.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/active_record/connection_adapters/recording_binding.rb', line 69 def call_remote(method, args) # Blank out username and password safe_args = args.inject([]) {|memo, v| memo << ((memo.last == :username or memo.last == :password) ? "" : v) } key = "#{method}(#{safe_args.join(':')})" if @recording response = super(method, args) unless @recorded_responses[key] # track this { key => request } to avoid duplication in the YAML @recorded_responses[key] = true YAML.dump({ key => response }, @recording_source) end else response = @recorded_responses[key] raise ASFRecordingBindingError.new(@logger, "Unable to find matching response for recorded request '#{key}'") unless response end response end |