Class: CowProxy::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/cow_proxy/base.rb

Overview

Base class to create CowProxy classes

Also, it’s used as default CowProxy class for non-registered classes with copy-on-write disabled, so returned values are wrapped but methods trying to change object still raise exception.

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, parent = nil, parent_var = nil) ⇒ Base

Creates a CowProxy object wrapping obj

Parameters:

  • obj

    An object to wrap with CowProxy class

  • parent (defaults to: nil)

    CowProxy object wrapping obj

  • parent_var (defaults to: nil)

    instance variable name in parent which keeps this CowProxy object



50
51
52
53
54
55
# File 'lib/cow_proxy/base.rb', line 50

def initialize(obj, parent = nil, parent_var = nil)
  @delegate_dc_obj = obj
  @parent_proxy = parent
  @parent_var = parent_var
  @dc_obj_duplicated = false
end

Class Attribute Details

.wrapped_classObject

Class which will be wrapped with this CowProxy class



10
11
12
# File 'lib/cow_proxy/base.rb', line 10

def wrapped_class
  @wrapped_class
end

Class Method Details

.inherited(subclass) ⇒ Object

Setup wrapped_class and register itself into CowProxy with CowProxy.register_proxy



14
15
16
17
# File 'lib/cow_proxy/base.rb', line 14

def inherited(subclass)
  subclass.wrapped_class = wrapped_class
  CowProxy.register_proxy wrapped_class, subclass if wrapped_class
end