Sha256: ea1af03e957e1c5fce6974a22cb9fea4e857cb372c73a04df7c1af446f4c26ac

Contents?: true

Size: 992 Bytes

Versions: 17

Compression:

Stored size: 992 Bytes

Contents

# 
# It allows you dynamically (magically) switch between UniversalEntry/Dir/File
# 
module Vfs
  class EntryProxy < BasicObject    
    attr_reader :_target
    # WRAP = [:[], :entry, :dir, :file].to_set
    
    def initialize entry
      raise 'something wrong happening here!' if entry.respond_to?(:proxy?) and entry.proxy?
      self._target = entry
    end
    
    def proxy?
      true
    end
    
    protected :==, :equal?, :!, :!=
    protected    
      attr_writer :_target
      
      def method_missing m, *a, &b
        unless _target.respond_to? m
          if ::Vfs::UniversalEntry.method_defined? m
            self.target = _target.entry
          elsif ::Vfs::Dir.method_defined? m
            self._target = _target.dir
          elsif ::Vfs::File.method_defined? m
            self._target = _target.file
          end
        end
        
        _target.send m, *a, &b
        
        # return WRAP.include?(m) ? EntryProxy.new(result) : result
      end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
vfs-0.3.12 lib/vfs/entry_proxy.rb
vfs-0.3.11 lib/vfs/entry_proxy.rb
vfs-0.3.10 lib/vfs/entry_proxy.rb
vfs-0.3.9 lib/vfs/entry_proxy.rb
vfs-0.3.8 lib/vfs/entry_proxy.rb
vfs-0.3.7 lib/vfs/entry_proxy.rb
vfs-0.3.6 lib/vfs/entry_proxy.rb
vfs-0.3.5 lib/vfs/entry_proxy.rb
vfs-0.3.4 lib/vfs/entry_proxy.rb
vfs-0.3.3 lib/vfs/entry_proxy.rb
vfs-0.3.2 lib/vfs/entry_proxy.rb
vfs-0.3.1 lib/vfs/entry_proxy.rb
vfs-0.3 lib/vfs/entry_proxy.rb
vfs-0.2.1 lib/vfs/entry_proxy.rb
vfs-0.2 lib/vfs/entry_proxy.rb
vfs-0.1.1 lib/vfs/entry_proxy.rb
vfs-0.1.0 lib/vfs/entry_proxy.rb