Class: Middleman::CoreExtensions::Data::Proxies::BaseProxy

Inherits:
Object
  • Object
show all
Defined in:
middleman-core/lib/middleman-core/core_extensions/data/proxies/base.rb

Direct Known Subclasses

ArrayProxy, HashProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, data, data_collection_depth, parent = nil) ⇒ BaseProxy

Returns a new instance of BaseProxy


12
13
14
15
16
17
18
19
20
21
# File 'middleman-core/lib/middleman-core/core_extensions/data/proxies/base.rb', line 12

def initialize(key, data, data_collection_depth, parent = nil)
  @key = key
  @data = data
  @parent = parent

  @data_collection_depth = data_collection_depth
  @depth = @parent.nil? || !@parent.is_a?(BaseProxy) ? 0 : @parent.depth + 1

  @accessed_keys = ::Hamster::Set.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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


27
28
29
30
31
32
33
34
35
# File 'middleman-core/lib/middleman-core/core_extensions/data/proxies/base.rb', line 27

def method_missing(name, *args, &block)
  if @data.respond_to?(name)
    log_access(:__full_access__)

    return @data.send(name, *args, &block)
  end

  super
end

Instance Attribute Details

#accessed_keysObject (readonly)

Returns the value of attribute accessed_keys


9
10
11
# File 'middleman-core/lib/middleman-core/core_extensions/data/proxies/base.rb', line 9

def accessed_keys
  @accessed_keys
end

#depthObject (readonly)

Returns the value of attribute depth


10
11
12
# File 'middleman-core/lib/middleman-core/core_extensions/data/proxies/base.rb', line 10

def depth
  @depth
end

Instance Method Details

#_replace_parent(new_parent) ⇒ Object


43
44
45
# File 'middleman-core/lib/middleman-core/core_extensions/data/proxies/base.rb', line 43

def _replace_parent(new_parent)
  @parent = new_parent
end

#_topObject


37
38
39
40
41
# File 'middleman-core/lib/middleman-core/core_extensions/data/proxies/base.rb', line 37

def _top
  return @parent._top if @parent.is_a?(BaseProxy)

  self
end

#as_json(*args) ⇒ Object


47
48
49
50
# File 'middleman-core/lib/middleman-core/core_extensions/data/proxies/base.rb', line 47

def as_json(*args)
  log_access(:__full_access__)
  @data.as_json(*args)
end

#respond_to_missing?(name) ⇒ Boolean

Returns:

  • (Boolean)

23
24
25
# File 'middleman-core/lib/middleman-core/core_extensions/data/proxies/base.rb', line 23

def respond_to_missing?(name, *)
  @data.respond_to?(name) || super
end