class FTPMVC::Directory
Attributes
index[R]
name[R]
Public Class Methods
new(options={}, &block)
click to toggle source
# File lib/ftpmvc/directory.rb, line 8 def initialize(options={}, &block) @name = options[:name] @index = [] instance_eval(&block) if block_given? end
Public Instance Methods
get(path)
click to toggle source
# File lib/ftpmvc/directory.rb, line 14 def get(path) file = resolve(path) file ? file.data : nil end
resolve(path)
click to toggle source
# 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
Protected Instance Methods
add_directory(dir)
click to toggle source
# File lib/ftpmvc/directory.rb, line 55 def add_directory(dir) dir.tap { |directory| @index << directory } end
create_and_add_directory(dir, options, &block)
click to toggle source
# File lib/ftpmvc/directory.rb, line 47 def create_and_add_directory(dir, options, &block) if dir.kind_of?(Symbol) options[:name] = options[:name] || dir.to_s dir = symbol_to_class(dir) end add_directory(create_directory(dir, options, &block)) end
create_directory(dir_class, options, &block)
click to toggle source
# File lib/ftpmvc/directory.rb, line 59 def create_directory(dir_class, options, &block) dir_class.new(options, &block) end
directory(*args, &block)
click to toggle source
# File lib/ftpmvc/directory.rb, line 33 def directory(*args, &block) first_arg, second_arg = args if first_arg.kind_of?(self.class) add_directory(first_arg) else if first_arg.kind_of?(Hash) create_and_add_directory(self.class, first_arg, &block) else create_and_add_directory(first_arg, second_arg || {}, &block) end end end
symbol_to_class(symbol)
click to toggle source
# File lib/ftpmvc/directory.rb, line 63 def symbol_to_class(symbol) ActiveSupport::Dependencies.safe_constantize("#{symbol.to_s.camelize}Directory") end