Решение на Пета задача от Кристъфър Коруев

Обратно към всички решения

Към профила на Кристъфър Коруев

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 30 неуспешни тест(а)

Код

require 'digest'
class ObjectStore
def initialize
@stage = {}
@commit_history = []
@sha1 = Digest::SHA1.new
end
def ObjectStore.init
ObjectStore.new
end
def add(name, object)
#TO DO: ASK WHEN ADD SHOULD RETURN FALSE
@stage[name] = object
RepoOperationInfo.new(true, name, :add)
end
def commit(message)
return RepoOperationInfo.new(false, :commit) if @stage.empty?
count_of_changed_objects = @stage.keys.length
make_hash_and_commit(message)
RepoOperationInfo.new(true, message, count_of_changed_objects, :commit)
end
def remove(name)
last_commit_files = @commit_history.last.values.first.first
removed_file = last_commit_files.delete(name)
@stage = last_commit_files
return RepoOperationInfo.new(false, name, :remove) if removed_file.nil?
RepoOperationInfo.new(true, name, :remove)
end
def log
i = RepoOperationInfo.new(false, "master", :log) if @commit_history.empty?
return i
log_string = ""
@commit_history.each { |objects| log_string += (get_log(objects) + "\n") }
RepoOperationInfo.new(true, log_string, :log)
end
private
def make_hash_and_commit(message)
committed_objects = {}
time = Time.new
commit_time = time.ctime
message_for_encrypting = commit_time + message
commit_hash = @sha1.hexdigest(message_for_encrypting)
committed_objects[commit_hash] = [@stage, message, commit_time]
@commit_history.push(committed_objects)
@stage = {}
end
def get_log(commit_hash)
commit_hash_key = "Commit " + commit_hash.keys.first + "\n"
commit_date_string = "Date: " + commit_hash.values.first[2] + "\n\n"
commit_message = " " + commit_hash.values.first[1] + "\n"
commit_hash_key + commit_date_string + commit_message
end
end
class RepoOperationInfo
attr_accessor :status, :name
def initialize(status, *name, operation)
@status = status
@name = name
@operation = operation
@message_hash = generate_message_for_operations
end
def message
return @message_hash[@operation].first if success?
@message_hash[@operation].last
end
def success?
return @status
end
private
def generate_message_for_operations
messages = {add: ["Added #{@name.first} to stage",
"Could not add #{@name.first} to stage"],
commit: ["#{@name.first}\n\t#{@name.last} objects changed",
"Nothing to commit, working directory clean."],
remove: ["Added #{@name.first} for removal.",
"Object #{@name.first} is not committed."],
log: ["#{@name.first}",
"Branch #{@name.first} does not have any commits yet."],
get: ["Found object #{@name.first}.",
"Object #{@name.first} is not committed."] }
end
end

Лог от изпълнението

FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Failures:

  1) ObjectStore can add objects
     Failure/Error: expect(repo.add("object", "content")).to be_success("Added object to stage.", "content")
       expected #<RepoOperationInfo:0x007fda2ef906e0 @status=true, @name=["object"], @operation=:add, @message_hash={:add=>["Added object to stage", "Could not add object to stage"], :commit=>["object\n\tobject objects changed", "Nothing to commit, working directory clean."], :remove=>["Added object for removal.", "Object object is not committed."], :log=>["object", "Branch object does not have any commits yet."], :get=>["Found object object.", "Object object is not committed."]}> to be success "Added object to stage." and "content"
     # /tmp/d20160111-5693-6fcwxn/spec.rb:23:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) ObjectStore can commit objects
     Failure/Error: expect(repo.commit("So cool!")).to be_success("So cool!\n\t2 objects changed", repo.head.result)
     NoMethodError:
       undefined method `head' for #<ObjectStore:0x007fda2ef7f458>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:30:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) ObjectStore cannot commit without changed objects
     Failure/Error: result.error? == true
     NoMethodError:
       undefined method `error?' for #<RepoOperationInfo:0x007fda2ef7c280>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:17:in `block (3 levels) in <top (required)>'
     # /tmp/d20160111-5693-6fcwxn/spec.rb:35:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) ObjectStore can remove objects
     Failure/Error: (result == nil || actual.result == result) &&
     NoMethodError:
       undefined method `result' for #<RepoOperationInfo:0x007fda2ef6af30>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:7:in `block (3 levels) in <top (required)>'
     # /tmp/d20160111-5693-6fcwxn/spec.rb:43:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) ObjectStore can commit changes which include only removed objects
     Failure/Error: expect(repo.commit("Removed object2")).to be_success("Removed object2\n\t1 objects changed", repo.head.result)
     NoMethodError:
       undefined method `head' for #<ObjectStore:0x007fda2ef622e0>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:53:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) ObjectStore cannot remove objects that are not committed
     Failure/Error: result.error? == true
     NoMethodError:
       undefined method `error?' for #<RepoOperationInfo:0x007fda2ef5c3b8>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:17:in `block (3 levels) in <top (required)>'
     # /tmp/d20160111-5693-6fcwxn/spec.rb:60:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) ObjectStore can show head
     Failure/Error: last_commit = repo.commit("There we go").result
     NoMethodError:
       undefined method `result' for #<RepoOperationInfo:0x007fda2e9dbe48>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:68:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) ObjectStore cannot show head for empty repository
     Failure/Error: expect(repo.head).to be_error("Branch master does not have any commits yet.")
     NoMethodError:
       undefined method `head' for #<ObjectStore:0x007fda2ebd68d8>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:74:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) ObjectStore can show log of changes for a single commit
     Failure/Error: commit = repo.commit("So cool!").result
     NoMethodError:
       undefined method `result' for #<RepoOperationInfo:0x007fda2ebc3f58>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:81:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) ObjectStore can show log of changes for a single commit
     Failure/Error: commit = repo.commit("So cool!").result
     NoMethodError:
       undefined method `result' for #<RepoOperationInfo:0x007fda2ebb99b8>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:90:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) ObjectStore can show log of changes for multiple commits
     Failure/Error: commit1 = repo.commit("First commit").result
     NoMethodError:
       undefined method `result' for #<RepoOperationInfo:0x007fda2eba5710>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:98:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  12) ObjectStore shows the log for the current branch only
     Failure/Error: commit1 = repo.commit("First commit").result
     NoMethodError:
       undefined method `result' for #<RepoOperationInfo:0x007fda2eb7a7b8>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:114:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  13) ObjectStore cannot show log for empty repository
     Failure/Error: result.error? == true
     NoMethodError:
       undefined method `error?' for #<RepoOperationInfo:0x007fda2eb66b28>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:17:in `block (3 levels) in <top (required)>'
     # /tmp/d20160111-5693-6fcwxn/spec.rb:133:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  14) ObjectStore can list branches
     Failure/Error: repo.branch.create("develop")
     NoMethodError:
       undefined method `branch' for #<ObjectStore:0x007fda2eb546d0>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:138:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  15) ObjectStore can create branches
     Failure/Error: expect(repo.branch.create("develop")).to be_success("Created branch develop.")
     NoMethodError:
       undefined method `branch' for #<ObjectStore:0x007fda2eb4a568>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:145:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  16) ObjectStore cannot create branch if already exists
     Failure/Error: expect(repo.branch.create("master")).to be_error("Branch master already exists.")
     NoMethodError:
       undefined method `branch' for #<ObjectStore:0x007fda2eb35780>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:150:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  17) ObjectStore can switch branches
     Failure/Error: first_commit = repo.commit("First commit").result
     NoMethodError:
       undefined method `result' for #<RepoOperationInfo:0x007fda2eb1e3f0>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:156:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  18) ObjectStore cannot switch to nonexisting branch
     Failure/Error: expect(repo.branch.checkout("develop")).to be_error("Branch develop does not exist.")
     NoMethodError:
       undefined method `branch' for #<ObjectStore:0x007fda2eaeeab0>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:168:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  19) ObjectStore can remove branch
     Failure/Error: repo.branch.create("develop")
     NoMethodError:
       undefined method `branch' for #<ObjectStore:0x007fda2eae61f8>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:173:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  20) ObjectStore cannot remove current branch
     Failure/Error: expect(repo.branch.remove("master")).to be_error("Cannot remove current branch.")
     NoMethodError:
       undefined method `branch' for #<ObjectStore:0x007fda2eadebd8>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:179:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  21) ObjectStore cannot remove nonexisting branch
     Failure/Error: expect(repo.branch.remove("develop")).to be_error("Branch develop does not exist.")
     NoMethodError:
       undefined method `branch' for #<ObjectStore:0x007fda2eada6f0>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:184:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  22) ObjectStore can be initialized with block
     Failure/Error: expect(repo.head).to be_success("Second commit", $second_commit)
     NoMethodError:
       undefined method `head' for #<ObjectStore:0x007fda2ead5218>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:195:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  23) ObjectStore can return objects
     Failure/Error: expect(repo.get("number")).to be_success("Found object number.", 21)
     NoMethodError:
       undefined method `get' for #<ObjectStore:0x007fda2eace8c8>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:202:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  24) ObjectStore cannot return not committed objects
     Failure/Error: expect(repo.get("string")).to be_error("Object string is not committed.")
     NoMethodError:
       undefined method `get' for #<ObjectStore:0x007fda2eab8a28>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:209:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  25) ObjectStore cannot return objects when no commits
     Failure/Error: expect(repo.get("string")).to be_error("Object string is not committed.")
     NoMethodError:
       undefined method `get' for #<ObjectStore:0x007fda2ea44d08>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:214:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  26) ObjectStore can checkout commits
     Failure/Error: first_commit = repo.commit("First commit").result
     NoMethodError:
       undefined method `result' for #<RepoOperationInfo:0x007fda2ea3b078>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:220:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  27) ObjectStore cannot checkout commits with nonexisting hashes
     Failure/Error: expect(repo.checkout("[not-present]")).to be_error("Commit [not-present] does not exist.")
     NoMethodError:
       undefined method `checkout' for #<ObjectStore:0x007fda2ea2df40>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:231:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  28) ObjectStore cannot checkout commits in empty repository
     Failure/Error: expect(repo.checkout("[not-present]")).to be_error("Commit [not-present] does not exist.")
     NoMethodError:
       undefined method `checkout' for #<ObjectStore:0x007fda2ea24b48>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:236:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  29) ObjectStore can show the objects in a repo after overwriting an object
     Failure/Error: first_commit = repo.commit("First commit").result
     NoMethodError:
       undefined method `result' for #<RepoOperationInfo:0x007fda2ea0fe00>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:242:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  30) ObjectStore can show the objects of a repo after removing an object
     Failure/Error: first_commit = repo.commit("First commit").result
     NoMethodError:
       undefined method `result' for #<RepoOperationInfo:0x007fda2ea07020>
     # /tmp/d20160111-5693-6fcwxn/spec.rb:258:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01706 seconds
30 examples, 30 failures

Failed examples:

rspec /tmp/d20160111-5693-6fcwxn/spec.rb:21 # ObjectStore can add objects
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:26 # ObjectStore can commit objects
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:33 # ObjectStore cannot commit without changed objects
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:38 # ObjectStore can remove objects
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:46 # ObjectStore can commit changes which include only removed objects
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:56 # ObjectStore cannot remove objects that are not committed
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:63 # ObjectStore can show head
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:72 # ObjectStore cannot show head for empty repository
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:77 # ObjectStore can show log of changes for a single commit
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:86 # ObjectStore can show log of changes for a single commit
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:95 # ObjectStore can show log of changes for multiple commits
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:111 # ObjectStore shows the log for the current branch only
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:131 # ObjectStore cannot show log for empty repository
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:136 # ObjectStore can list branches
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:143 # ObjectStore can create branches
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:148 # ObjectStore cannot create branch if already exists
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:153 # ObjectStore can switch branches
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:166 # ObjectStore cannot switch to nonexisting branch
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:171 # ObjectStore can remove branch
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:177 # ObjectStore cannot remove current branch
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:182 # ObjectStore cannot remove nonexisting branch
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:187 # ObjectStore can be initialized with block
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:198 # ObjectStore can return objects
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:205 # ObjectStore cannot return not committed objects
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:212 # ObjectStore cannot return objects when no commits
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:217 # ObjectStore can checkout commits
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:227 # ObjectStore cannot checkout commits with nonexisting hashes
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:234 # ObjectStore cannot checkout commits in empty repository
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:239 # ObjectStore can show the objects in a repo after overwriting an object
rspec /tmp/d20160111-5693-6fcwxn/spec.rb:253 # ObjectStore can show the objects of a repo after removing an object

История (1 версия и 0 коментара)

Кристъфър обнови решението на 23.11.2015 12:53 (преди над 8 години)

+require 'digest'
+
+class ObjectStore
+ def initialize
+ @stage = {}
+ @commit_history = []
+ @sha1 = Digest::SHA1.new
+ end
+
+ def ObjectStore.init
+ ObjectStore.new
+ end
+
+ def add(name, object)
+ #TO DO: ASK WHEN ADD SHOULD RETURN FALSE
+ @stage[name] = object
+ RepoOperationInfo.new(true, name, :add)
+ end
+
+ def commit(message)
+ return RepoOperationInfo.new(false, :commit) if @stage.empty?
+ count_of_changed_objects = @stage.keys.length
+ make_hash_and_commit(message)
+ RepoOperationInfo.new(true, message, count_of_changed_objects, :commit)
+ end
+
+ def remove(name)
+ last_commit_files = @commit_history.last.values.first.first
+ removed_file = last_commit_files.delete(name)
+ @stage = last_commit_files
+ return RepoOperationInfo.new(false, name, :remove) if removed_file.nil?
+ RepoOperationInfo.new(true, name, :remove)
+ end
+
+ def log
+ i = RepoOperationInfo.new(false, "master", :log) if @commit_history.empty?
+ return i
+ log_string = ""
+ @commit_history.each { |objects| log_string += (get_log(objects) + "\n") }
+ RepoOperationInfo.new(true, log_string, :log)
+ end
+ private
+
+ def make_hash_and_commit(message)
+ committed_objects = {}
+ time = Time.new
+ commit_time = time.ctime
+ message_for_encrypting = commit_time + message
+ commit_hash = @sha1.hexdigest(message_for_encrypting)
+ committed_objects[commit_hash] = [@stage, message, commit_time]
+ @commit_history.push(committed_objects)
+ @stage = {}
+ end
+
+ def get_log(commit_hash)
+ commit_hash_key = "Commit " + commit_hash.keys.first + "\n"
+ commit_date_string = "Date: " + commit_hash.values.first[2] + "\n\n"
+ commit_message = " " + commit_hash.values.first[1] + "\n"
+ commit_hash_key + commit_date_string + commit_message
+ end
+end
+
+class RepoOperationInfo
+ attr_accessor :status, :name
+
+ def initialize(status, *name, operation)
+ @status = status
+ @name = name
+ @operation = operation
+ @message_hash = generate_message_for_operations
+ end
+
+ def message
+ return @message_hash[@operation].first if success?
+ @message_hash[@operation].last
+ end
+
+ def success?
+ return @status
+ end
+
+ private
+
+ def generate_message_for_operations
+ messages = {add: ["Added #{@name.first} to stage",
+ "Could not add #{@name.first} to stage"],
+ commit: ["#{@name.first}\n\t#{@name.last} objects changed",
+ "Nothing to commit, working directory clean."],
+ remove: ["Added #{@name.first} for removal.",
+ "Object #{@name.first} is not committed."],
+ log: ["#{@name.first}",
+ "Branch #{@name.first} does not have any commits yet."],
+ get: ["Found object #{@name.first}.",
+ "Object #{@name.first} is not committed."] }
+ end
+end