Sha256: de95ff94c787cfa78d315aa8c1f37b32f8d6dfa695e538f05bcad03ce2a19f02

Contents?: true

Size: 942 Bytes

Versions: 1

Compression:

Stored size: 942 Bytes

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 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

1 entries across 1 versions & 1 rubygems

Version Path
web_resource_bundler-0.0.21 lib/web_resource_bundler/file_manager.rb