module Writetheman::Article::File

Attributes

extension[RW]
filename[RW]

Private Instance Methods

create_file() click to toggle source
# File lib/writetheman/article/file.rb, line 9
def create_file
  article_path = source_file_path
  raise "File already exists : #{article_path}" if ::File.exist?(article_path)
  raise "content is empty for create file #{@filename}" if @all_content.nil? || @all_content.empty?
  file = ::File.open(article_path, 'w') { |f| f.write(@all_content) ; f.close }
end
delete_file(filename='') click to toggle source
# File lib/writetheman/article/file.rb, line 25
def delete_file(filename='')          
  filename = @filename if filename.empty?
  article_path = source_file_path(filename)
  raise "File doesn't exist : #{article_path}" if !::File.exist?(article_path)
  ::File.delete article_path
end
read_file() click to toggle source
# File lib/writetheman/article/file.rb, line 16
def read_file
  article_path = source_file_path
  raise "File doesn't exist : #{article_path}" if !::File.exist?(article_path)
  file = ::File.open(article_path, "rb")
  @all_content = file.read
  file.close
  @all_content
end
source_file_path(filename='') click to toggle source
# File lib/writetheman/article/file.rb, line 32
def source_file_path(filename='')
  filename = @filename if filename.empty?
  raise "filename is empty" if filename.nil? || filename.empty?
  check_path_source_blog
  path_source_blog + '/' + filename
end