Class: Gongren::CallProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/gongren/call_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ CallProxy

Returns a new instance of CallProxy.



3
4
5
6
# File 'lib/gongren/call_proxy.rb', line 3

def initialize(options={}, &block)
  @options = options
  @block   = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(selector, *args, &block) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
# File 'lib/gongren/call_proxy.rb', line 8

def method_missing(selector, *args, &block)
  raise ArgumentError, "Cannot generate a CallProxy when a block is involved" if block.present?
  return super unless selector.to_s =~ /^deliver_/
  data = {:selector => selector, :args => args}
  @block.call(data) if @block

  args = map_active_record_instances_to_simpler_representation(args)

  Gongren::RailsServer.submit(options[:key], data)
end

Instance Method Details

#map_active_record_instances_to_simpler_representation(args) ⇒ Object



19
20
21
22
23
# File 'lib/gongren/call_proxy.rb', line 19

def map_active_record_instances_to_simpler_representation(args)
  args.map do |arg|
    arg.kind_of?(ActiveRecord) ? {:active_record => [arg.class.name, arg.id]} : arg
  end
end