Class: HaveAPI::Fs::Component::Children

Inherits:
Object
  • Object
show all
Defined in:
lib/haveapi/fs/component.rb

Overview

An encapsulation of a Hash to store child components.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx) ⇒ Children



13
14
15
16
# File 'lib/haveapi/fs/component.rb', line 13

def initialize(ctx)
  @context = ctx
  @store = {}
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



10
11
12
# File 'lib/haveapi/fs/component.rb', line 10

def context
  @context
end

Instance Method Details

#[](k) ⇒ Object



18
19
20
# File 'lib/haveapi/fs/component.rb', line 18

def [](k)
  @store[k]
end

#[]=(k, v) ⇒ Object

Replace a child named k by a new child represented by v. The old child, if present, is invalidated and dropped from the cache. Factory is used to create an instance of v.



28
29
30
31
32
33
34
35
# File 'lib/haveapi/fs/component.rb', line 28

def []=(k, v)
  if @store.has_key?(k)
    @store[k].invalidate
    @store[k].context.cache.drop_below(@store[k].path)
  end

  @store[k] = Factory.create(@context, k, *v)
end

#set(k, v) ⇒ Object



37
38
39
# File 'lib/haveapi/fs/component.rb', line 37

def set(k, v)
  @store[k] = v
end