Class: FTPMVC::Directory
- Inherits:
-
Object
- Object
- FTPMVC::Directory
- Defined in:
- lib/ftpmvc/directory.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #get(path) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Directory
constructor
A new instance of Directory.
- #resolve(path) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Directory
Returns a new instance of Directory.
8 9 10 11 12 |
# File 'lib/ftpmvc/directory.rb', line 8 def initialize(={}, &block) @name = [:name] @index = [] instance_eval(&block) if block_given? end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
6 7 8 |
# File 'lib/ftpmvc/directory.rb', line 6 def index @index end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/ftpmvc/directory.rb', line 6 def name @name end |
Instance Method Details
#get(path) ⇒ Object
14 15 16 17 |
# File 'lib/ftpmvc/directory.rb', line 14 def get(path) file = resolve(path) file ? file.data : nil end |
#resolve(path) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ftpmvc/directory.rb', line 19 def resolve(path) path = path.gsub(%r{^/}, '') return self if path.empty? name, subpath = path.split('/', 2) child = index.find { |node| node.name == name } if subpath == nil or child == nil child else child.resolve(subpath) end end |