Module: Police::DataFlow::Proxies
- Defined in:
- lib/police/dataflow/proxies.rb
Overview
Namespace for the auto-generated proxy classes.
Class Method Summary collapse
-
.clear_cache ⇒ Boolean
Clears the cache of proxy classes associated with Ruby classes.
-
.for(proxied_class, label_set) ⇒ Class
A class whose instances proxy instances of a Ruby class.
-
.for!(proxied_class, label_classes) ⇒ Class
A class whose instances proxy instances of a Ruby class.
Class Method Details
.clear_cache ⇒ Boolean
Clears the cache of proxy classes associated with Ruby classes.
This method has a terrible impact on VM performance, and is only intended for testing the Police::DataFlow implementation.
68 69 70 71 |
# File 'lib/police/dataflow/proxies.rb', line 68 def self.clear_cache @classes.clear true end |
.for(proxied_class, label_set) ⇒ Class
A class whose instances proxy instances of a Ruby class.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/police/dataflow/proxies.rb', line 15 def self.for(proxied_class, label_set) unless class_cache = @classes[proxied_class] class_cache = {} @classes[proxied_class] = class_cache end cache_key = label_set.keys.sort!.freeze return class_cache[cache_key] if class_cache.has_key? cache_key label_classes = label_set.map { |label_key, label_hash| label_hash.first.first.class }.sort_by!(&:__id__).freeze proxy_class = for! proxied_class, label_classes class_cache[cache_key] = proxy_class proxy_class end |
.for!(proxied_class, label_classes) ⇒ Class
A class whose instances proxy instances of a Ruby class.
Use for instead of calling this directly.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/police/dataflow/proxies.rb', line 45 def self.for!(proxied_class, label_classes) proxy_class = nil klass = proxied_class until klass == nil if klass == String # TODO(pwnall): String-specific proxying break elsif klass == Numeric proxy_class = Class.new Police::DataFlow::ProxyNumeric end klass = klass.superclass end proxy_class ||= Class.new Police::DataFlow::ProxyBase proxy_class.__police_classes__ = label_classes proxy_class end |