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

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

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Content

Returns a new instance of Content.



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

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

Class Attribute Details

.demo_repositoryObject

Returns the value of attribute demo_repository.



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

def demo_repository
  @demo_repository
end

Instance Method Details

#clone_or_update_repository(process) ⇒ Object



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

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

#configure_git_to_ignore_repoObject



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

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)


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

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

#exclude_pathObject



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

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

#execute(process) ⇒ Object



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

def execute(process)
  clone_or_update_repository(process)
  configure_git_to_ignore_repo
  Nesta::ConfigFile.new.set_value('content', @dir)
end

#in_git_repo?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/nesta/commands/demo/content.rb', line 29

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