Class: Grancher

Inherits:
Object
  • Object
show all
Defined in:
lib/grancher.rb,
lib/grancher/task.rb

Defined Under Namespace

Classes: Task

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&blk) ⇒ Grancher

Returns a new instance of Grancher.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/grancher.rb', line 82

def initialize(&blk)
  @directories = {}
  @files = {}
  @keep = []
  @repo = '.'
  @message = 'Updated files.'
  @tags = []
  if block_given?
    if blk.arity == 1
      blk.call(self)
    else
      self.instance_eval(&blk)
    end
  end
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



79
80
81
# File 'lib/grancher.rb', line 79

def branch
  @branch
end

#directoriesObject (readonly)

Returns the value of attribute directories.



80
81
82
# File 'lib/grancher.rb', line 80

def directories
  @directories
end

#filesObject (readonly)

Returns the value of attribute files.



80
81
82
# File 'lib/grancher.rb', line 80

def files
  @files
end

#gashObject (readonly)

Returns our Gash-object



99
100
101
# File 'lib/grancher.rb', line 99

def gash
  @gash
end

#messageObject

Returns the value of attribute message.



79
80
81
# File 'lib/grancher.rb', line 79

def message
  @message
end

#push_toObject

Returns the value of attribute push_to.



79
80
81
# File 'lib/grancher.rb', line 79

def push_to
  @push_to
end

#refspecObject

Returns the value of attribute refspec.



79
80
81
# File 'lib/grancher.rb', line 79

def refspec
  @refspec
end

#repoObject

Returns the value of attribute repo.



79
80
81
# File 'lib/grancher.rb', line 79

def repo
  @repo
end

#tagsObject

Returns the value of attribute tags.



79
80
81
# File 'lib/grancher.rb', line 79

def tags
  @tags
end

Instance Method Details

#commit(message = nil) ⇒ Object

Commits the changes.



159
160
161
162
163
164
165
166
167
# File 'lib/grancher.rb', line 159

def commit(message = nil)
  old_keys = gash.keys
  build
  if gash.keys.sort == old_keys.sort
    gash.commit(message || message())
  else
    gash.commit(message || message(), :force => true)
  end
end

#directory(from, to = nil) ⇒ Object

Stores the directory from at to.



104
105
106
# File 'lib/grancher.rb', line 104

def directory(from, to = nil)
  @directories[from.chomp('/')] = to
end

#file(from, to = nil) ⇒ Object

Stores the file from at to.



109
110
111
# File 'lib/grancher.rb', line 109

def file(from, to = nil)
  @files[from] = to
end

#keep(*files) ⇒ Object

Keeps the files (or directories) given.



114
115
116
# File 'lib/grancher.rb', line 114

def keep(*files)
  @keep.concat(files.flatten)
end

#keep_allObject

Keep all the files in the branch.



119
120
121
# File 'lib/grancher.rb', line 119

def keep_all
  @keep_all = true
end

#pushObject

Pushes the branch to the remote.



150
151
152
153
154
155
156
# File 'lib/grancher.rb', line 150

def push
  if @tags.empty?
    gash.send(:git, 'push', @push_to, @refspec)
  else
    gash.send(:git, 'push', '--tags', @push_to, @refspec)
  end
end

#tag(tag, tag_msg = "", commit = nil) ⇒ Object

Tag the most recent checked-out commit



140
141
142
143
144
145
146
147
# File 'lib/grancher.rb', line 140

def tag(tag, tag_msg="", commit=nil)
  @tags << tag
  if commit
    gash.send(:git, 'tag', '-f', '-a', '-m', tag_msg, tag, commit)
  else
    gash.send(:git, 'tag', '-f', '-a', '-m', tag_msg, tag)
  end
end