Module: Petra::Proxies::EnumerableProxy
- Includes:
- ModuleProxy
- Defined in:
- lib/petra/proxies/enumerable_proxy.rb
Overview
Module Proxy which is used to proxy classes which include Enumerable, such as Enumerator or Array. It contains wrappers for the default enumerator functions to ensure that objects yielded to their blocks are correctly wrapped in Petra proxies (if needed)
Defined Under Namespace
Modules: InstanceMethods
Constant Summary collapse
- MODULE_NAMES =
%w[Enumerable].freeze
- INCLUDES =
[Enumerable].freeze
Class Method Summary collapse
-
.proxy_entries(enum, surrogate_method: '[]') ⇒ Array<Petra::Proxies::ObjectProxy>
Ensures the the objects yielded to blocks are actually petra proxies.
Class Method Details
.proxy_entries(enum, surrogate_method: '[]') ⇒ Array<Petra::Proxies::ObjectProxy>
Ensures the the objects yielded to blocks are actually petra proxies. This is necessary as the internal call to each
would be forwarded to the actual Enumerable object and result in unproxied objects.
This method will only proxy objects which allow this through the class config as the enum’s entries are seen as inherited objects. ‘[]` is used as method causing the proxy creation as it’s closest to what’s actually happening.
39 40 41 |
# File 'lib/petra/proxies/enumerable_proxy.rb', line 39 def self.proxy_entries(enum, surrogate_method: '[]') enum.entries.map { |o| o.petra(inherited: true, configuration_args: [surrogate_method]) } end |