Class: Git::Trifle::PatchPatch

Inherits:
String
  • Object
show all
Extended by:
Pedlar
Defined in:
lib/git-patch-patch/patch_patcher.rb

Overview

patch model as a String for its primary interface, but it knows a lot more

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, attributes = nil) ⇒ PatchPatch

Returns a new instance of PatchPatch.



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/git-patch-patch/patch_patcher.rb', line 172

def initialize(string, attributes=nil)
  # instance attributes in one line
  (attributes ||= {}).each { |k, v| send "#{k}=", v }
  file_with attributes[:file].to_s if attributes[:file]

  # job done ? ok then...
  if @work == true || @work == :done
    # give work the value we want
    @work = :done
    string = file.read
  end

  # changes handler
  @previous = string.to_s

  # vanilla
  super string
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



140
141
142
# File 'lib/git-patch-patch/patch_patcher.rb', line 140

def error
  @error
end

#first_commitObject

Returns the value of attribute first_commit.



140
141
142
# File 'lib/git-patch-patch/patch_patcher.rb', line 140

def first_commit
  @first_commit
end

#second_commitObject

Returns the value of attribute second_commit.



140
141
142
# File 'lib/git-patch-patch/patch_patcher.rb', line 140

def second_commit
  @second_commit
end

#workObject

Returns the value of attribute work.



140
141
142
# File 'lib/git-patch-patch/patch_patcher.rb', line 140

def work
  @work
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


191
192
193
# File 'lib/git-patch-patch/patch_patcher.rb', line 191

def changed?
  self != @previous
end

#reload_from_fileObject

patch content from file



202
203
204
205
# File 'lib/git-patch-patch/patch_patcher.rb', line 202

def reload_from_file
  @previous = self.to_s
  replace file.read
end

#saveObject

to file



196
197
198
199
# File 'lib/git-patch-patch/patch_patcher.rb', line 196

def save
  # trailing \n or git complains
  file.save!(self + "\n")
end