Class: HaveAPI::Fs::Context

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

Overview

Every component has its own Context instance and passes it along to its children. Context is used to pass information from the root of the tree to all its branches and leaves. Using the context, every component knows all its parents and can relate to them. It also contains a reference to the global Cache instance.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



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

def initialize
  @object_path = []
  @file_path = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



39
40
41
# File 'lib/haveapi/fs/context.rb', line 39

def method_missing(name, *args)
  self[name] || super
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



8
9
10
# File 'lib/haveapi/fs/context.rb', line 8

def cache
  @cache
end

#file_pathObject

Returns the value of attribute file_path.



8
9
10
# File 'lib/haveapi/fs/context.rb', line 8

def file_path
  @file_path
end

#mountpointObject

Returns the value of attribute mountpoint.



8
9
10
# File 'lib/haveapi/fs/context.rb', line 8

def mountpoint
  @mountpoint
end

#object_pathObject

Returns the value of attribute object_path.



8
9
10
# File 'lib/haveapi/fs/context.rb', line 8

def object_path
  @object_path
end

#optsObject

Returns the value of attribute opts.



8
9
10
# File 'lib/haveapi/fs/context.rb', line 8

def opts
  @opts
end

#urlObject

Returns the value of attribute url.



8
9
10
# File 'lib/haveapi/fs/context.rb', line 8

def url
  @url
end

Instance Method Details

#[](name) ⇒ Object



30
31
32
33
# File 'lib/haveapi/fs/context.rb', line 30

def [](name)
  item = @object_path.reverse.detect { |v| v[0] == name }
  item && item[1]
end

#[]=(name, value) ⇒ Object



26
27
28
# File 'lib/haveapi/fs/context.rb', line 26

def []=(name, value)
  set(name, value)
end

#cloneObject



15
16
17
18
19
20
# File 'lib/haveapi/fs/context.rb', line 15

def clone
  c = super
  c.object_path = c.object_path.clone
  c.file_path = c.file_path.clone
  c
end

#lastObject



35
36
37
# File 'lib/haveapi/fs/context.rb', line 35

def last
  @object_path.last[1]
end

#set(name, value) ⇒ Object



22
23
24
# File 'lib/haveapi/fs/context.rb', line 22

def set(name, value)
  @object_path << [name, value]
end