Class: HaveAPI::Fs::Context
- Inherits:
-
Object
- Object
- HaveAPI::Fs::Context
- 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
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#mountpoint ⇒ Object
Returns the value of attribute mountpoint.
-
#object_path ⇒ Object
Returns the value of attribute object_path.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #clone ⇒ Object
-
#initialize ⇒ Context
constructor
A new instance of Context.
- #last ⇒ Object
- #method_missing(name, *args) ⇒ Object
- #set(name, value) ⇒ Object
Constructor Details
#initialize ⇒ Context
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
#cache ⇒ Object
Returns the value of attribute cache.
8 9 10 |
# File 'lib/haveapi/fs/context.rb', line 8 def cache @cache end |
#file_path ⇒ Object
Returns the value of attribute file_path.
8 9 10 |
# File 'lib/haveapi/fs/context.rb', line 8 def file_path @file_path end |
#mountpoint ⇒ Object
Returns the value of attribute mountpoint.
8 9 10 |
# File 'lib/haveapi/fs/context.rb', line 8 def mountpoint @mountpoint end |
#object_path ⇒ Object
Returns the value of attribute object_path.
8 9 10 |
# File 'lib/haveapi/fs/context.rb', line 8 def object_path @object_path end |
#opts ⇒ Object
Returns the value of attribute opts.
8 9 10 |
# File 'lib/haveapi/fs/context.rb', line 8 def opts @opts end |
#url ⇒ Object
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 |
#clone ⇒ Object
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 |
#last ⇒ Object
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 |