Sha256: f52d5bebc114403bfd8a96ef11760d687cdcac9363c1cc6bb79ed2e81aa555c2

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

require File.expand_path('../command', File.dirname(__FILE__))

module Nesta
  module Commands
    module Demo
      class Content
        include Command

        @demo_repository = 'git://github.com/gma/nesta-demo-content.git'
        class << self
          attr_accessor :demo_repository
        end

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

        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

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

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

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

        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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nesta-0.12.0 lib/nesta/commands/demo/content.rb