Class: RGitHook::CommitFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rgithook/githook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, inserts, deletions, diff) ⇒ CommitFile

Returns a new instance of CommitFile.



170
171
172
173
174
175
176
177
# File 'lib/rgithook/githook.rb', line 170

def initialize(filename,inserts,deletions,diff)
  @name, @ins, @del = filename,inserts,deletions
  @diff = diff.split("\n")[4..-1].join("\n")
rescue NoMethodError
  # No se pudo generar el diff
ensure
  @diff = "" if @diff.nil?
end

Instance Attribute Details

#delObject (readonly)

Returns the value of attribute del.



169
170
171
# File 'lib/rgithook/githook.rb', line 169

def del
  @del
end

#diffObject (readonly)

Returns the value of attribute diff.



169
170
171
# File 'lib/rgithook/githook.rb', line 169

def diff
  @diff
end

#insObject (readonly)

Returns the value of attribute ins.



169
170
171
# File 'lib/rgithook/githook.rb', line 169

def ins
  @ins
end

#nameObject (readonly)

Returns the value of attribute name.



169
170
171
# File 'lib/rgithook/githook.rb', line 169

def name
  @name
end

Instance Method Details

#to_htmlObject



181
182
183
184
185
186
187
188
189
190
191
# File 'lib/rgithook/githook.rb', line 181

def to_html
  html = "<div style='margin: 5px 0px 10px 20px'>"
  html << "<div style='font-weight: bolder;display: inline;'>#{@name}</div>"
  html << "<div style='color: green; display: inline;'>+#{@ins}</div>"
  html << "<div style='color:red; display: inline;'>-#{@del}</div>"
  diff = RGitHook::Helpers.html_escape(@diff)
  diff.gsub!( /^(\+[^+].*)$/, '<ins style="background:#dfd;text-decoration:none;padding:0 10px;">\1</ins>')
  diff.gsub!( /^(\-[^-].*)$/, '<del style="background:#fdd;text-decoration:none;padding:0 10px;">\1</del>')
  html << "<div style='width: 100%;'><pre style='padding:0;line-height:1.2em;margin:0; overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px;'>"+diff+"</pre></div>\n"
  html << "</div>\n"
end

#to_sObject



178
179
180
# File 'lib/rgithook/githook.rb', line 178

def to_s
  format("FILE: %s (+%s/-%s)\n%s",@name,@ins.to_s,@del.to_s,@diff)
end