Module: Diary::Item::Creator

Included in:
Base
Defined in:
lib/diary/item/creator.rb

Defined Under Namespace

Modules: Peristance

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



4
5
6
# File 'lib/diary/item/creator.rb', line 4

def self.extended(base)
  base.send :include, Peristance
end

Instance Method Details

#create(title_or_path) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/diary/item/creator.rb', line 22

def create(title_or_path)
  path_fragments  = title_or_path.split("/")
  title = path_fragments.pop
  path_fragments << title.parameterize
  path = resolve_path(path_fragments.join("/"))

  ensure_directories_exists!(path)

  unless File.exists?(path)
    File.open(path, "w+") do |f|
      f.puts "---\n"
      f.puts "title: #{title}"
      f.puts "\n---\n"
    end

    Diary.message :create, path, :green
  else
    Diary.message :exist, path, :yellow
  end

  self.new(path)
end