Class: Marsdawn::Storage::FileSystem
- Defined in:
- lib/marsdawn/storage/file_system.rb
Instance Method Summary collapse
- #clean_up ⇒ Object
- #finalize ⇒ Object
- #get(uri) ⇒ Object
- #get_document_info ⇒ Object
-
#initialize(config, opts = {}) ⇒ FileSystem
constructor
A new instance of FileSystem.
- #prepare ⇒ Object
- #set(uri, content, front_matter, sysinfo) ⇒ Object
- #set_document_info(doc_info) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(config, opts = {}) ⇒ FileSystem
Returns a new instance of FileSystem.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/marsdawn/storage/file_system.rb', line 8 def initialize config, opts={} @config = { tmp_dir: '/tmp', mode_dir: 0755, mode_file: 0644 }.merge(config) raise "Not specify the local storage path name." unless @config.key?(:path) @path = File.absolute_path(@config[:path]) raise "There is no directory to build to '#{@path}'." unless File.exists?(@path) @opts = { key: '-', lang: 'en', version: '0.0.1' }.merge(opts) set_target_path end |
Instance Method Details
#clean_up ⇒ Object
36 37 38 |
# File 'lib/marsdawn/storage/file_system.rb', line 36 def clean_up FileUtils.remove_entry_secure @tmproot end |
#finalize ⇒ Object
29 30 31 32 33 34 |
# File 'lib/marsdawn/storage/file_system.rb', line 29 def finalize target_dir = File.dirname(@target_path) FileUtils.mkdir_p target_dir, :mode => @config[:mode_dir] unless File.exists?(target_dir) FileUtils.remove_entry_secure @target_path if File.exists?(@target_path) FileUtils.mv @tmproot, @target_path end |
#get(uri) ⇒ Object
56 57 58 59 |
# File 'lib/marsdawn/storage/file_system.rb', line 56 def get uri fullpath = page_file(uri) YAML.load_file fullpath if File.exists?(fullpath) end |
#get_document_info ⇒ Object
52 53 54 |
# File 'lib/marsdawn/storage/file_system.rb', line 52 def get_document_info YAML.load_file @doc_info_file end |
#prepare ⇒ Object
25 26 27 |
# File 'lib/marsdawn/storage/file_system.rb', line 25 def prepare setup_tmp_dir end |
#set(uri, content, front_matter, sysinfo) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/marsdawn/storage/file_system.rb', line 44 def set uri, content, front_matter, sysinfo fullpath = tmp_page_file(uri) dir = File.dirname(fullpath) FileUtils.mkdir_p dir, :mode => @config[:mode_dir] unless File.exists?(dir) data = {content: content, front_matter: front_matter, sysinfo: sysinfo} File.write fullpath, YAML.dump(data) end |
#set_document_info(doc_info) ⇒ Object
40 41 42 |
# File 'lib/marsdawn/storage/file_system.rb', line 40 def set_document_info doc_info File.write @tmp_doc_info_file, YAML.dump(doc_info) end |