Class: ProxyFS::FS

Inherits:
Object
  • Object
show all
Defined in:
lib/proxyfs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tree) ⇒ FS

Returns a new instance of FS.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/proxyfs.rb', line 81

def initialize tree
  @tree = tree
  iam = self

  @dir = Class.new Dir do
    @@fs = iam

    def self.fs
      @@fs
    end

    def fs
      @@fs
    end
  end

  @file = Class.new File do
    @@fs = iam

    def self.fs
      @@fs
    end

    def fs
      @@fs
    end
  end
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



79
80
81
# File 'lib/proxyfs.rb', line 79

def dir
  @dir
end

#fileObject (readonly)

Returns the value of attribute file.



79
80
81
# File 'lib/proxyfs.rb', line 79

def file
  @file
end

Instance Method Details

#entry(path) ⇒ Object

Raises:

  • (ArgumentError)


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/proxyfs.rb', line 110

def entry path
  path = Pathname.new path

  raise ArgumentError, 'path shall be absolute' unless path.absolute?

  patha = path.each_filename.to_a

  find = Proc.new do |patha, curdir|
    name = patha[0]
    raise Errno::ENOENT unless curdir.include? name

    e = curdir[name]

    rest_patha = patha[1..(-1)]

    if rest_patha.empty?
      e
    else
      if Hash === e
        find[rest_patha, e]
      elsif Array === e
        find[rest_patha, e[0].new(*e[1..(-1)])]
      else
        find[rest_patha, e]
      end
    end
  end

  find[patha, @tree]
end