Class: Razor::Rake::Git::Generate
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Razor::Rake::Git::Generate
- Defined in:
- lib/razor/rake/git_generate.rb
Instance Attribute Summary collapse
-
#site_branch ⇒ Object
Returns the value of attribute site_branch.
-
#template_branch ⇒ Object
Returns the value of attribute template_branch.
-
#url_base ⇒ Object
Returns the value of attribute url_base.
Instance Method Summary collapse
- #checkout(branch) ⇒ Object
- #current_branch ⇒ Object
- #define_task ⇒ Object
- #ensure_branch_is_clean ⇒ Object
- #ensure_on_branch(branch) ⇒ Object
- #generate_options ⇒ Object
-
#initialize(name = 'git:generate') {|_self| ... } ⇒ Generate
constructor
A new instance of Generate.
Constructor Details
#initialize(name = 'git:generate') {|_self| ... } ⇒ Generate
Returns a new instance of Generate.
35 36 37 38 39 40 41 42 |
# File 'lib/razor/rake/git_generate.rb', line 35 def initialize(name='git:generate') @name = name @template_branch = 'master' @site_branch = 'site' @url_base = '/' yield self if block_given? define_task end |
Instance Attribute Details
#site_branch ⇒ Object
Returns the value of attribute site_branch.
32 33 34 |
# File 'lib/razor/rake/git_generate.rb', line 32 def site_branch @site_branch end |
#template_branch ⇒ Object
Returns the value of attribute template_branch.
31 32 33 |
# File 'lib/razor/rake/git_generate.rb', line 31 def template_branch @template_branch end |
#url_base ⇒ Object
Returns the value of attribute url_base.
33 34 35 |
# File 'lib/razor/rake/git_generate.rb', line 33 def url_base @url_base end |
Instance Method Details
#checkout(branch) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/razor/rake/git_generate.rb', line 75 def checkout(branch) if block_given? old = current_branch begin `git checkout #{branch}` yield ensure `git checkout #{old}` end else `git checkout #{branch}` end end |
#current_branch ⇒ Object
70 71 72 73 |
# File 'lib/razor/rake/git_generate.rb', line 70 def current_branch `git status` =~ /^# On branch (.+)/ return $1 end |
#define_task ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/razor/rake/git_generate.rb', line 44 def define_task task(@name, [:message]) { |t, args| ensure_on_branch template_branch ensure_branch_is_clean # needed ? # .gitinore workaround #TODO: Solve this problem gitignore = File.read '.gitignore' rescue '' Dir.mktmpdir { |tmp| Razor.generate(, '.', tmp) checkout site_branch do sh 'git rm -r .' sh "cp -r #{tmp}/* ." # .gitignore workaround File.open('.gitignore', 'w') {|f| f << gitignore } sh 'git add .' msg = args. if msg.nil? or msg.empty? sh 'git commit' else sh "git commit -m #{msg}" end end } } end |
#ensure_branch_is_clean ⇒ Object
97 98 99 100 101 |
# File 'lib/razor/rake/git_generate.rb', line 97 def ensure_branch_is_clean clean = (`git status` =~ /nothing to commit \(working directory clean\)\n$/ ) clean and return raise CleanBranchError end |
#ensure_on_branch(branch) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/razor/rake/git_generate.rb', line 89 def ensure_on_branch(branch) current_branch == branch and return ensure_branch_is_clean checkout branch rescue CleanBranchError raise BranchError.new(branch) end |
#generate_options ⇒ Object
103 104 105 106 107 |
# File 'lib/razor/rake/git_generate.rb', line 103 def { :url_base => @url_base } end |