Module: Lebowski::Foundation::ProxyFactory

Defined in:
lib/lebowski/foundation/proxy_factory.rb

Constant Summary collapse

@@proxies =
{}

Class Method Summary collapse

Class Method Details

.create_proxy(key, parent, rel_path, driver = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lebowski/foundation/proxy_factory.rb', line 17

def self.create_proxy(key, parent, rel_path, driver=nil)
  klass = nil
  
  if key.kind_of?(String)
    klass = @@proxies[key.downcase] 
  elsif key.kind_of?(Class) and key.ancestors.member?(Lebowski::Foundation::SCObject)
    klass = key
  else
    raise ArgumentError.new "key is an invalid type: #{key}"
  end
  
  raise ArgumentError.new "proxy key not recognized: #{key}" if klass.nil?
  
  if (parent.nil? and driver.nil?)
    raise ArgumentError.new "must supply a driver either through the parent or driver arguments"
  end
  
  driver = driver.nil? ? parent.driver : driver
  
  return klass.new(parent, rel_path, driver) if rel_path.kind_of? String
  return klass.new(parent, "#{rel_path}", driver) if rel_path.kind_of? Integer
  
  raise ArgumentError.new "rel_path is an invalid type: #{rel_path.class}"
end

.has_key?(key) ⇒ Boolean

Returns:



13
14
15
# File 'lib/lebowski/foundation/proxy_factory.rb', line 13

def self.has_key?(key)
  return @@proxies.has_key? key.downcase
end

.proxy(klass) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/lebowski/foundation/proxy_factory.rb', line 42

def self.proxy(klass)
  if not (klass.kind_of?(Class) and klass.ancestors.member?(Lebowski::Foundation::SCObject))
    raise ArgumentError.new "class must inherit Lebowski::Foundation::Object: #{klass.class}"
  end
  
  @@proxies[klass.represented_sc_class.downcase] = klass
end