Skip to content

Instantly share code, notes, and snippets.

@moos3
Created June 14, 2011 21:01
Show Gist options
  • Select an option

  • Save moos3/1025874 to your computer and use it in GitHub Desktop.

Select an option

Save moos3/1025874 to your computer and use it in GitHub Desktop.
class SourceFile
#Class for handling the code files
attr_accessor :name, :path, :hash, :content, :repo, :size, :commit_log, :branch
# Custom object to json
def json_create(o)
new(*o['data'])
end
# Custom object to json
def to_json(*a)
{
'name' => name,
'path' => path,
'checksum' => hash,
'repo' => repo,
'size' => size,
'branch' => branch,
'data' => content,
'commitLog' => commit_log
}.to_json(*a)
end
def path_getter(path)
@path = path.to_s.split(/\//)[5..-1].join("/")
end
# create new new SourceFile object
def initialize(name,path,repo,size)
@name = name
@path = path
@repo = repo
@size = size
path_getter(path)
end
# set Checksum
def checksum(hash)
@hash = hash
end
# store file contents
def file_contents(content)
@content = content
end
# compare hashes
def changed?(hash,old_hash)
if hash != old_hash
false
else
true
end
end
# get checksum from elastic search to compare for change detection
def get_checksum(path)
false
end
# get file commit log
def get_log(path)
@log = %x[svn log #{path}]
end
# Get banch information
def get_branch(repo)
@branch = %x[svn info #{repo}/ | grep url ]
@branch = @branch.spilt('/')[3..-1]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment