Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit d7bbb0b1d851ed038bffa99aad6320f1b0a18fd7 @rodjek committed Nov 23, 2011
Showing with 95 additions and 0 deletions.
  1. +16 −0 README.md
  2. 0 curtain.gemspec
  3. +11 −0 lib/curtain.rb
  4. +27 −0 lib/curtain/dsl.rb
  5. +41 −0 lib/curtain/source/git.rb
@@ -0,0 +1,16 @@
+# Curtain
+
+Really basic proof of concept for a bundler type system for Puppet modules.
+Heavily inspired by Bundler (obviously).
+
+## Modulefile
+
+```ruby
+git 'git://github.com/puppetlabs/puppetlabs-stdlib.git', 'name' => 'stdlib',
+'tag' => 'v2.2.0'
+```
+
+```ruby
+require 'curtain'
+Curtain.install('Modulefile')
+```
No changes.
@@ -0,0 +1,11 @@
+require 'fileutils'
+require 'curtain/source/git'
+require 'curtain/dsl'
+
+module Curtain
+ def self.install(file)
+ Dsl.evaluate(file).each do |source|
+ source.install
+ end
+ end
+end
@@ -0,0 +1,27 @@
+module Curtain
+ class Dsl
+ def self.evaluate(modulefile)
+ builder = new
+ builder.instance_eval(File.read(modulefile.to_s))
+ builder.to_definition
+ end
+
+ def initialize
+ @sources = []
+ end
+
+ def to_definition
+ @sources
+ end
+
+ def git(uri, options = {})
+ source Source::Git.new(options.merge({'uri' => uri}))
+ end
+
+ private
+
+ def source(obj)
+ @sources << obj
+ end
+ end
+end
@@ -0,0 +1,41 @@
+module Curtain
+ module Source
+ class Git
+ def initialize(options)
+ @uri = options['uri']
+ @ref = options['ref'] || options['branch'] || options['tag'] || 'master'
+ @name = options['name'] || name_from_uri
+ end
+
+ def install
+ checkout
+ end
+
+ private
+
+ def path
+ "modules/#{@name}"
+ end
+
+ def name_from_uri
+ File.basename(@uri, '.git')
+ end
+
+ def git(command)
+ out = %x{git #{command}}
+ out
+ end
+
+ def checkout
+ unless File.exist?(path)
+ FileUtils.mkdir_p(File.dirname(path))
+ git "clone #{@uri} #{path}"
+ end
+ Dir.chdir(path) do
+ git "fetch --force --quiet --tags"
+ git "reset --hard #{@ref}"
+ end
+ end
+ end
+ end
+end

0 comments on commit d7bbb0b

Please sign in to comment.