Class: WebResourceBundler::FileManager
- Inherits:
-
Object
- Object
- WebResourceBundler::FileManager
- Defined in:
- lib/web_resource_bundler/file_manager.rb
Instance Attribute Summary collapse
-
#cache_dir ⇒ Object
readonly
Returns the value of attribute cache_dir.
-
#resource_dir ⇒ Object
readonly
Returns the value of attribute resource_dir.
Instance Method Summary collapse
- #create_cache_dir ⇒ Object
- #exist?(relative_path) ⇒ Boolean
- #full_path(relative_path) ⇒ Object
- #get_content(relative_path) ⇒ Object
-
#initialize(attributes) ⇒ FileManager
constructor
A new instance of FileManager.
- #set_settings(attributes) ⇒ Object
- #write_file(path, content) ⇒ Object
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_dir ⇒ Object (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_dir ⇒ Object (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
#create_cache_dir ⇒ Object
27 28 29 30 31 32 |
# File 'lib/web_resource_bundler/file_manager.rb', line 27 def create_cache_dir path = File.join(@resource_dir, @cache_dir) unless File.exist?(path) Dir.mkdir(path) end end |
#exist?(relative_path) ⇒ Boolean
18 19 20 |
# File 'lib/web_resource_bundler/file_manager.rb', line 18 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
22 23 24 25 |
# File 'lib/web_resource_bundler/file_manager.rb', line 22 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
34 35 36 37 38 |
# File 'lib/web_resource_bundler/file_manager.rb', line 34 def write_file(path, content) File.open(full_path(path), "w") do |f| f.print(content) end end |