Class: Origen::OrgFile::Interceptor

Inherits:
BasicObject
Defined in:
lib/origen/org_file/interceptor.rb

Instance Method Summary collapse

Constructor Details

#initialize(object, options = {}) ⇒ Interceptor

Returns a new instance of Interceptor.



12
13
14
15
# File 'lib/origen/org_file/interceptor.rb', line 12

def initialize(object, options = {})
  @object = object
  @@locked = false unless defined? @@locked
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/origen/org_file/interceptor.rb', line 56

def method_missing(method, *args, &block)
  if !@@locked && @org_file && @org_file_methods_to_intercept.include?(method)
    @org_file.record(@object.global_path_to, method, *args)
    # Locking prevents an operation on an intercepted container object trigger from generating multiple
    # org file entries if its contained objects are also intercepted. e.g. Imagine this is a pin group, we
    # want the org file to reflect the operation called on the pin group, but not the many subsequent internal
    # operations as the group proxies the operation to its contained pins
    @@locked = true
    @object.send(method, *args, &block)
    @@locked = false
  else
    @object.send(method, *args, &block)
  end
end

Instance Method Details

#==(obj) ⇒ Object Also known as: equal?



21
22
23
24
25
26
27
# File 'lib/origen/org_file/interceptor.rb', line 21

def ==(obj)
  if obj.respond_to?(:__org_file_interceptor__)
    @object == obj.__object__
  else
    @object == obj
  end
end

#__object__Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Don't ever use this! An un-wrapped reference to an object must never make it into application code or else any operations called on the un-wrapped reference will not be captured.



85
86
87
# File 'lib/origen/org_file/interceptor.rb', line 85

def __object__
  @object
end

#__org_file_interceptor__Object



76
77
78
# File 'lib/origen/org_file/interceptor.rb', line 76

def __org_file_interceptor__
  true
end

#inspect(*args) ⇒ Object



17
18
19
# File 'lib/origen/org_file/interceptor.rb', line 17

def inspect(*args)
  @object.inspect(*args)
end

#record_to_org_file(id = nil, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/origen/org_file/interceptor.rb', line 30

def record_to_org_file(id = nil, options = {})
  id, options = nil, id if id.is_a?(::Hash)
  if options[:only]
    @org_file_methods_to_intercept = Array(options[:only]).to_set
  else
    @org_file_methods_to_intercept = default_org_file_captures
    if options[:also]
      @org_file_methods_to_intercept += Array(options[:also]).to_set
    end
  end
  @org_file ||= @old_org_file || OrgFile.org_file(id)
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/origen/org_file/interceptor.rb', line 71

def respond_to?(method, include_private = false)
  method == :__org_file_interceptor__ ||
    @object.respond_to?(method, include_private)
end

#stop_recording_to_org_file(&block) ⇒ Object

Temporarily stop recording operations within the given block, or stop recording completely if no block given



45
46
47
48
49
50
51
52
53
54
# File 'lib/origen/org_file/interceptor.rb', line 45

def stop_recording_to_org_file(&block)
  @old_org_file = @org_file
  if OrgFile._block_given_?(&block)
    @org_file = nil
    yield
    @org_file = @old_org_file
  else
    @org_file = nil
  end
end