Sha256: 4045c84308844cc0432f0c46c0b51c5c183bee14e8166b3f998f7c517e94d55c

Contents?: true

Size: 1.37 KB

Versions: 25

Compression:

Stored size: 1.37 KB

Contents

module Fog
  module Local

    def self.new(options={})

      unless @required
        require 'fog/local/models/directories'
        require 'fog/local/models/directory'
        require 'fog/local/models/file'
        require 'fog/local/models/files'
        @required = true
      end

      unless options[:local_root]
        raise ArgumentError.new('local_root is required to access local')
      end
      if Fog.mocking?
        Fog::Local::Mock.new(options)
      else
        Fog::Local::Real.new(options)
      end
    end

    def self.reset_data(keys=Mock.data.keys)
      Mock.reset_data(keys)
    end

    class Mock

      def self.data
        @data ||= Hash.new do |hash, key|
          hash[key] = {}
        end
      end

      def self.reset_data(keys=data.keys)
        for key in [*keys]
          data.delete(key)
        end
      end

      def initialize(options={})
        @local_root = ::File.expand_path(options[:local_root])
        @data       = self.class.data[@local_root]
      end

      def local_root
        @local_root
      end

      def path(partial)
        partial
      end
    end

    class Real

      def initialize(options={})
        @local_root = ::File.expand_path(options[:local_root])
      end

      def local_root
        @local_root
      end

      def path_to(partial)
        ::File.join(@local_root, partial)
      end
    end

  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
fog-0.1.8 lib/fog/local.rb
fog-0.1.7 lib/fog/local.rb
fog-0.1.6 lib/fog/local.rb
fog-0.1.5 lib/fog/local.rb
fog-0.1.4 lib/fog/local.rb
fog-0.1.3 lib/fog/local.rb
fog-0.1.2 lib/fog/local.rb
fog-0.1.1 lib/fog/local.rb
fog-0.1.0 lib/fog/local.rb
fog-0.0.100 lib/fog/local.rb
fog-0.0.99 lib/fog/local.rb
fog-0.0.98 lib/fog/local.rb
fog-0.0.97 lib/fog/local.rb
fog-0.0.96 lib/fog/local.rb
fog-0.0.95 lib/fog/local.rb
fog-0.0.94 lib/fog/local.rb
fog-0.0.93 lib/fog/local.rb
fog-0.0.92 lib/fog/local.rb
fog-0.0.91 lib/fog/local.rb
fog-0.0.90 lib/fog/local.rb