Class Grancher

  1. lib/grancher/task.rb
  2. lib/grancher.rb
  3. show all
Parent: Object

What is Grancher?

With Grancher you can easily copy folders and files to a Git branch.

How?

As a library

require 'grancher'
grancher = Grancher.new do |g|
  g.branch = 'gh-pages'
  g.push_to = 'origin'
  g.repo = 'some_repo'          # defaults to '.'
  g.message = 'Updated website' # defaults to 'Updated files.'

  # Put the website-directory in the root
  g.directory 'website'

  # doc -> doc
  g.directory 'doc', 'doc'

  # README -> README
  g.file 'README'

  # AUTHORS -> authors.txt
  g.file 'AUTHORS', 'authors.txt'

  # CHANGELOG -> doc/CHANGELOG
  g.file 'CHANGELOG', 'doc/'
end

grancher.commit
grancher.push

As a Raketask

Instead of:

require 'grancher'
Grancher.new do |g|
  ...
end

Do:

require 'grancher/task'
Grancher::Task.new do |g|
  ...
end

See Grancher::Task for more information.

Keeping the files already in the branch

By default, Grancher will remove any files already in the branch. Use keep and keep_all to change this behaviour:

Grancher.new do |g|
  # Only keep some files/folders:
  g.keep 'index.html', 'test', 'lib/grancer'

  # Keep all the files in the repo:
  g.keep_all
end

Methods

public class

  1. new

public instance

  1. commit
  2. directory
  3. file
  4. gash
  5. keep
  6. keep_all
  7. push

Classes and Modules

Class Grancher::Task

Attributes

branch [RW]
directories [R]
files [R]
gash [R]
message [RW]
push_to [RW]
repo [RW]

Public class methods

new (&blk)
[show source]
    # File lib/grancher.rb, line 72
72:   def initialize(&blk)
73:     @directories = {}
74:     @files = {}
75:     @keep = []
76:     @repo = '.'
77:     @message = 'Updated files.'
78:     
79:     if blk.arity == 1
80:       blk.call(self)
81:     else
82:       self.instance_eval(&blk)
83:     end
84:   end

Public instance methods

commit (message = nil)

Commits the changes.

[show source]
     # File lib/grancher.rb, line 117
117:   def commit(message = nil)
118:     build.commit(message || message())
119:   end
directory (from, to = nil)

Stores the directory from at to.

[show source]
    # File lib/grancher.rb, line 92
92:   def directory(from, to = nil)
93:     @directories[from.chomp('/')] = to
94:   end
file (from, to = nil)

Stores the file from at to.

[show source]
    # File lib/grancher.rb, line 97
97:   def file(from, to = nil)
98:     @files[from] = to
99:   end
gash ()

Returns our Gash-object

[show source]
    # File lib/grancher.rb, line 87
87:   def gash
88:     @gash ||= Gash.new(@repo, @branch)
89:   end
keep (*files)

Keeps the files (or directories) given.

[show source]
     # File lib/grancher.rb, line 102
102:   def keep(*files)
103:     @keep.concat(files)
104:   end
keep_all ()

Keep all the files in the branch.

[show source]
     # File lib/grancher.rb, line 107
107:   def keep_all
108:     @keep_all = true
109:   end
push ()

Pushes the branch to the remote.

[show source]
     # File lib/grancher.rb, line 112
112:   def push
113:     gash.send(:git, 'push', @push_to, @branch + ':refs/heads/' + @branch)
114:   end