Skip to content
Browse files

v0.1.0

add branch setting
add callbacks instead of redefinition
  • Loading branch information...
1 parent bd342b2 commit 6e5c18d717e3428da6d42472bd5a133f3d2eb73b @stereobooster committed May 22, 2012
Showing with 25 additions and 13 deletions.
  1. +24 −12 lib/submodule.rb
  2. +1 −1 lib/submodule/version.rb
View
36 lib/submodule.rb
@@ -5,10 +5,10 @@
module Submodule
class Task < ::Rake::TaskLib
-
attr_reader :path
+ attr_accessor :branch
- def initialize
+ def initialize
@cwd = Dir.pwd
base = File.basename Dir["*.gemspec"][0], ".gemspec"
@@ -19,17 +19,29 @@ def initialize
gitmodules = IniFile.new('./.gitmodules').to_h
@path = gitmodules[gitmodules.keys.first]["path"]
+ @path = File.expand_path(@path, @cwd)
@submodule_name = gitmodules.keys.first.gsub('submodule ', '').gsub('"', '').gsub('vendor/', '')
@github = gitmodules[gitmodules.keys.first]["url"].gsub('https://github.com/', '').gsub('.git', '')
- define
- end
- def test
- p "define tests in test function"
+ # TODO: detect default branch
+ @branch = "master"
+
+ yield self if block_given?
+ define
end
- def after_pull
- p "after pull"
+ [:test, :after_pull].each do |method|
+ define_method method do |&block|
+ instance_variable_set("@#{method}", block)
+ end
+ define_method "run_#{method}" do
+ callback = instance_variable_get("@#{method}")
+ if callback.respond_to?(:call)
+ callback.call
+ else
+ warn "define #{method}"
+ end
+ end
end
private
@@ -45,18 +57,18 @@ def define
if hash_before == hash_after
abort "submodule #{@submodule_name} already up-to-date"
end
- test
+ run_test
update_version hash_after
cd @cwd
git_add
- after_pull
+ run_after_pull
git_commit hash_after
end
desc "Test submodule #{@submodule_name}"
task "submodule:test" do
git_update
cd path
- test
+ run_test
cd @cwd
end
self
@@ -77,7 +89,7 @@ def git_update
def git_pull
sh "git clean -f"
- sh "git checkout master"
+ sh "git checkout #{branch}"
sh "git pull"
# res = my_sh "git pull"
# if res =~ /Already up-to-date/
View
2 lib/submodule/version.rb
@@ -1,3 +1,3 @@
module Submodule
- VERSION = "0.0.3"
+ VERSION = "0.1.0"
end

0 comments on commit 6e5c18d

Please sign in to comment.
Something went wrong with that request. Please try again.