Module: Platform::Api::Proxy

Defined in:
lib/platform/api/proxy.rb,
lib/platform/api/proxy/base.rb

Defined Under Namespace

Classes: Base

Class Method Summary collapse

Class Method Details

.add(klass, proxy_class) ⇒ Object



5
6
7
8
# File 'lib/platform/api/proxy.rb', line 5

def self.add(klass, proxy_class)
  proxy_class.ensure_valid_class_name
  (Platform::Config.proxies[klass.name] ||= SortedSet.new) << proxy_class
end

.for(instance, version = nil) ⇒ Object



27
28
29
# File 'lib/platform/api/proxy.rb', line 27

def self.for(instance, version=nil)
  return proxy_class_for(instance.class, version).new(instance)
end

.proxy_class_for(klass, version = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/platform/api/proxy.rb', line 10

def self.proxy_class_for(klass, version=nil)
  unless proxy_array = proxies_for(klass)
    raise ArgumentError, "No proxy for class: #{klass.name}"
  end

  proxy_array = proxy_array.to_a
  if version.nil?
    proxy_class = proxy_array.last
  else
    version = version.to_i
    proxy_class = proxy_array.reverse.find {|ii| ii.api_version <= version}
  end
  raise ArgumentError "No proxy for version: #{version}" if proxy_class.nil?

  proxy_class
end

.resetObject



31
32
33
# File 'lib/platform/api/proxy.rb', line 31

def self.reset
  Platform::Config.proxies.clear
end