Class: Nesta::Commands::Demo::Content
- Inherits:
-
Object
- Object
- Nesta::Commands::Demo::Content
- Defined in:
- lib/nesta/commands/demo/content.rb
Class Attribute Summary collapse
-
.demo_repository ⇒ Object
Returns the value of attribute demo_repository.
Instance Method Summary collapse
- #clone_or_update_repository(process) ⇒ Object
- #configure_git_to_ignore_repo ⇒ Object
- #demo_repo_ignored? ⇒ Boolean
- #exclude_path ⇒ Object
- #execute(process) ⇒ Object
- #in_git_repo? ⇒ Boolean
-
#initialize(*args) ⇒ Content
constructor
A new instance of Content.
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_repository ⇒ Object
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_repo ⇒ Object
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
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_path ⇒ Object
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 |