Class: Amiba::Page::Create

Inherits:
Thor::Group
  • Object
show all
Includes:
Generator, Repo
Defined in:
lib/amiba/page.rb

Overview

Thor task to create a new page. It checks for the existance of a page already existing and that the user specified a valid format before progressing.

Instance Method Summary collapse

Methods included from Repo

#add_and_commit, #init, #last_commit_date, #last_commit_dates, #pull, #push, #repo

Methods included from Generator

included

Instance Method Details

#add_to_gitObject


49
50
51
52
# File 'lib/amiba/page.rb', line 49

def add_to_git
  add_and_commit @source.filename
  add_and_commit @entry.filename
end

#init_sourceObject


22
23
24
25
# File 'lib/amiba/page.rb', line 22

def init_source
  @source = Amiba::Source::Page.new(name, format, options, Templates.send(format.to_sym))
  @entry = Amiba::Source::PageEntry.new(@source)
end

#save_pageObject


40
41
42
43
44
45
46
47
# File 'lib/amiba/page.rb', line 40

def save_page
  @source.save do |filename, file_data|
    create_file filename, file_data
  end
  @entry.save do |filename, file_data|
    create_file filename, file_data
  end
end

#should_be_correct_formatObject


33
34
35
36
37
38
# File 'lib/amiba/page.rb', line 33

def should_be_correct_format
  if !@source.valid? && !@source.errors[:format].nil?
    raise Thor::Error.new("Error: format should be one of " +
                          Amiba::Source::Page::VALID_FORMATS.join(','))
  end
end

#should_not_existObject


27
28
29
30
31
# File 'lib/amiba/page.rb', line 27

def should_not_exist
  unless @source.new?
    raise Thor::Error.new("Error:A page called '#{name}' has already been created.")
  end
end