Sha256: b727f6c2fdf0cc6b7ee07c8303396a4d1ebc268ddee1a12f6ff38a6f25b3c015

Contents?: true

Size: 1.57 KB

Versions: 5

Compression:

Stored size: 1.57 KB

Contents

module PoolParty    
  class GitResource
    
    virtual_resource(:git) do
      def loaded(*args)
        has_package(:name => "git-core")
      end
    end
    
    virtual_resource(:git_repos) do
      
      def loaded(opts={}, parent=self, &block)
        has_git
        has_git_repos
      end
            
      def has_git_repos        
        has_exec({:name => key, :requires => [get_directory("#{working_dir}"), get_package("git-core")] }) do
          command requires_user ? "git clone #{requires_user}@#{source} #{working_dir}" : "cd #{working_dir} && git clone #{source}"
          cwd "#{working_dir if working_dir}"
          creates creates_dir
        end
        has_exec(:name => "update-#{name}") do
          cwd ::File.dirname( creates_dir )
          command "git pull"
        end                
      end
      
      def at(dir)
        working_dir dir
        has_directory(:name => "#{dir}", :requires => get_directory("#{::File.dirname(dir)}"))
      end
      
      def to(dir)
        at(dir)
      end
      
      def creates_dir
        "#{::File.join( working_dir, ::File.basename(source, ::File.extname(source)) )}/.git"
      end
      
      # Since git is not a native type, we have to say which core resource
      # it is using to be able to require it
      def class_type_name
        "exec"
      end
      
      # Because we are requiring an exec, instead of a built-in package of the git, we have to overload
      # the to_s method and prepend it with the same name as above
      def key
        "git-#{name}"
      end
      
    end
    
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
auser-poolparty-0.2.91 lib/poolparty/plugins/git.rb
auser-poolparty-0.2.92 lib/poolparty/plugins/git.rb
auser-poolparty-0.2.93 lib/poolparty/plugins/git.rb
auser-poolparty-0.2.94 lib/poolparty/plugins/git.rb
auser-poolparty-1.0.0 lib/poolparty/plugins/git.rb