class Git::Approvals::Approval
Attributes
path[R]
Public Instance Methods
diff( string, &block )
click to toggle source
Diffs the given string with this approval file. If the file has not been checked in, this method will raise an exception. Otherwise, the supplied block will only be called if the diff fails, meaning there are differences.
# File lib/git/approvals/approval.rb, line 22 def diff( string, &block ) # Make sure the directory of the file exists. FileUtils.mkdir_p File.dirname( path ) # Write the new string to the file. File.open path, 'w' do |f| f << Tilt.new( path ).render( string ) end # If the file hasn't been checked in, raise an error. sh "git ls-files #{path} --error-unmatch" do |err| raise Errno::ENOENT, path end # If the file has changed, call the block. sh "git diff --exit-code #{path}" do |err| block.call err end end
sh( cmd ) { |out| ... }
click to toggle source
Shells out the given command. If the command exits with success, does nothing. If the command does not exit with success, yields the error output to the block.
# File lib/git/approvals/approval.rb, line 46 def sh( cmd ) out, cmd = Open3.capture2e cmd yield out if !cmd.success? end