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

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

Class Attribute Summary collapse

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

Returns a new instance of Content



14
15
16
# File 'lib/nesta/commands/demo/content.rb', line 14

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

Class Attribute Details

.demo_repositoryObject

Returns the value of attribute demo_repository



11
12
13
# File 'lib/nesta/commands/demo/content.rb', line 11

def demo_repository
  @demo_repository
end

Instance Method Details

#clone_or_update_repositoryObject



18
19
20
21
22
23
24
25
# File 'lib/nesta/commands/demo/content.rb', line 18

def clone_or_update_repository
  path = Nesta::Path.local(@dir)
  if File.exist?(path)
    FileUtils.cd(path) { run_process('git', 'pull', 'origin', 'master') }
  else
    run_process('git', 'clone', self.class.demo_repository, path)
  end
end

#configure_git_to_ignore_repoObject



41
42
43
44
45
46
# File 'lib/nesta/commands/demo/content.rb', line 41

def configure_git_to_ignore_repo
  if in_git_repo? && ! demo_repo_ignored?
    FileUtils.mkdir_p(File.dirname(exclude_path))
    File.open(exclude_path, 'a') { |file| file.puts @dir }
  end
end

#demo_repo_ignored?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/nesta/commands/demo/content.rb', line 35

def demo_repo_ignored?
  File.read(exclude_path).split.any? { |line| line == @dir }
rescue Errno::ENOENT
  false
end

#exclude_pathObject



27
28
29
# File 'lib/nesta/commands/demo/content.rb', line 27

def exclude_path
  Nesta::Path.local('.git/info/exclude')
end

#executeObject



48
49
50
51
52
# File 'lib/nesta/commands/demo/content.rb', line 48

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

#in_git_repo?Boolean

Returns:

  • (Boolean)


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

def in_git_repo?
  File.directory?(Nesta::Path.local('.git'))
end