Class: WebResourceBundler::FileManager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ FileManager

Returns a new instance of FileManager.



5
6
7
# File 'lib/web_resource_bundler/file_manager.rb', line 5

def initialize(attributes)
  set_settings(attributes)
end

Instance Attribute Details

#cache_dirObject (readonly)

Returns the value of attribute cache_dir.



3
4
5
# File 'lib/web_resource_bundler/file_manager.rb', line 3

def cache_dir
  @cache_dir
end

#resource_dirObject (readonly)

Returns the value of attribute resource_dir.



3
4
5
# File 'lib/web_resource_bundler/file_manager.rb', line 3

def resource_dir
  @resource_dir
end

Instance Method Details

#cache_path_with_prefix(prefix, path) ⇒ Object



18
19
20
# File 'lib/web_resource_bundler/file_manager.rb', line 18

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

#create_cache_dirObject



31
32
33
34
35
36
# File 'lib/web_resource_bundler/file_manager.rb', line 31

def create_cache_dir
  path = File.join(@resource_dir, @cache_dir)
  unless File.exist?(path)
    Dir.mkdir(path)
  end
end

#exist?(relative_path) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/web_resource_bundler/file_manager.rb', line 22

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

#full_path(relative_path) ⇒ Object



14
15
16
# File 'lib/web_resource_bundler/file_manager.rb', line 14

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

#get_content(relative_path) ⇒ Object



26
27
28
29
# File 'lib/web_resource_bundler/file_manager.rb', line 26

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

#set_settings(attributes) ⇒ Object



9
10
11
12
# File 'lib/web_resource_bundler/file_manager.rb', line 9

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

#write_file(path, content) ⇒ Object



38
39
40
41
42
# File 'lib/web_resource_bundler/file_manager.rb', line 38

def write_file(path, content)
  File.open(full_path(path), "w") do |f|
    f.print(content)
  end
end