Sha256: 7e80c9b64c3226c6da36ad3002e01dd756cf76f5e44da27b98759ecb304da88c

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module WebResourceBundler
  class FileManager
    attr_reader :resource_dir, :cache_dir

    def initialize(attributes)
      set_settings(attributes)
    end

    def set_settings(attributes)
      @resource_dir = attributes[:resource_dir]
      @cache_dir    = attributes[:cache_dir]
    end

    def full_path(relative_path)
      File.join(@resource_dir, relative_path)
    end

    def cache_path_with_prefix(prefix, path)
      File.join(@cache_dir, prefix + File.basename(path))
    end

    def exist?(relative_path)
      File.exist? full_path(relative_path)
    end

    def get_content(relative_path)
      raise Exceptions::ResourceNotFoundError.new(full_path(relative_path)) unless exist?(relative_path)
      File.read(full_path(relative_path))
    end

    def create_cache_dir
      path = File.join(@resource_dir, @cache_dir)
      unless File.exist?(path)
        Dir.mkdir(path)
      end
    end
    
    def write_file(path, content)
      File.open(full_path(path), "w") do |f|
        f.print(content)
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
web_resource_bundler-0.0.23 lib/web_resource_bundler/file_manager.rb
web_resource_bundler-0.0.22 lib/web_resource_bundler/file_manager.rb