Class: Nesta::Commands::Demo::Content

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/nesta/commands/demo/content.rb

Instance Method Summary collapse

Methods included from Command

#copy_template, #copy_templates, #fail, #run_process, #template_root, #update_config_yaml

Constructor Details

#initialize(*args) ⇒ Content



9
10
11
# File 'lib/nesta/commands/demo/content.rb', line 9

def initialize(*args)
  @dir = 'content-demo'
end

Instance Method Details

#clone_or_update_repositoryObject



13
14
15
16
17
18
19
20
21
# File 'lib/nesta/commands/demo/content.rb', line 13

def clone_or_update_repository
  repository = 'git://github.com/gma/nesta-demo-content.git'
  path = Nesta::Path.local(@dir)
  if File.exist?(path)
    FileUtils.cd(path) { run_process('git', 'pull', 'origin', 'master') }
  else
    run_process('git', 'clone', repository, path)
  end
end

#configure_git_to_ignore_repoObject



23
24
25
26
27
28
# File 'lib/nesta/commands/demo/content.rb', line 23

def configure_git_to_ignore_repo
  excludes = Nesta::Path.local('.git/info/exclude')
  if File.exist?(excludes) && File.read(excludes).scan(@dir).empty?
    File.open(excludes, 'a') { |file| file.puts @dir }
  end
end

#executeObject



30
31
32
33
34
# File 'lib/nesta/commands/demo/content.rb', line 30

def execute
  clone_or_update_repository
  configure_git_to_ignore_repo
  update_config_yaml(/^\s*#?\s*content:.*/, "content: #{@dir}")
end