Решение на Пета задача от Александрина Каракехайова

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

Към профила на Александрина Каракехайова

Резултати

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

Код

require 'digest/sha1'
require 'date'
class Branch
attr_accessor :commits
def initialize(name = :master)
@name = name
@commits = {}
end
def create(branch_name)
Branch.new(branch_name)
repository[branch_name] = @commits
end
def check(check_branches, check_current, branch_name)
message = "Branch #{branch_name} does not exist."
if check_branches == true and check_current == false
repository.delete(branch_name)
Objects.new(branch_name, "",true, "Removed branch #{branch_name}")
elsif check_branches and check_current
Objects.new(branch_name, "", false, "Cannot remove current branch.")
else Objects.new(branch_name, "", false, message)
end
end
def remove(branch_name)
check_branches = repository.include?(branch_name)
check_current = branch_name.eql?(current)
check(check_branches, check_current, branch_name)
end
end
class ObjectStore < Branch
attr_accessor :repository, :current
def initialize
@repository = {}
@current = Branch.new
end
def self.init(&block)
new_repository = ObjectStore.new
if block_given?
new_repository.instance_eval &block
else new_repository
end
end
def add(name, object)
changes[name] = object
message = "Added #{name} to stage."
Objects.new(name, object, true, message)
end
def branch
@current
end
def commit(message)
commits[Digest::SHA1.hexdigest(message)] = changes
if changes.size == 0
text = "Nothing to commit, working directory clean."
Objects.new("", "", false, text)
else text = "#{message}" + '\n' + '\t' + "#{commits.size} objects changed"
Objects.new("", "", true, text)
end
end
def remove(name)
result = changes.delete(name) {"not found"}
if result.eql?("not found")
message = "Object #{name} is not committed."
Objects.new(name, "", false, message)
else message = "Added #{name} for removal."
Objects.new(name, "", true, message)
end
end
def checkout(commit_hash)
message = "Commit #{commit_hash} does not exist."
if commits.include?(commit_hash)
Objects.new(commit_hash, "", true, "HEAD is now at #{commit_hash}.")
else Objects.new(commit_hash, "", false, message)
end
end
end
class Objects
def initialize(name, object, state, message)
@name = name
@object = object
@state = state
@message = message
end
def message
@message
end
def success?
@state == true
end
def error?
@state == false
end
def result
@object
end
end
class Commit
attr_accessor :changes
def initialize(message)
@message = message
@changes = {}
end
end

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

FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Failures:

  1) ObjectStore can add objects
     Failure/Error: expect(repo.add("object", "content")).to be_success("Added object to stage.", "content")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f4a0128>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/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: repo.add("object1", "content1")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f499238>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:28: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: expect(repo.commit("So cool!!")).to be_error("Nothing to commit, working directory clean.")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f4943a0>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:60:in `commit'
     # /tmp/d20160111-5693-s5ghrl/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: repo.add("object1", "content1")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f48a418>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:40: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: repo.add("object1", "content1")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f487380>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:48: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: repo.add("object1", "content1")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f485418>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:58: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: repo.add("object1", "content1")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f47f428>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:65: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:0x007f003f47cea8>
     # /tmp/d20160111-5693-s5ghrl/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: repo.add("object1", "content1")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f476e68>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:79: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: repo.add("object1", "content1")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f475180>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:88: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: repo.add("object1", "content1")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f463a48>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:97: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: repo.add("object1", "content1")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f0f71e8>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:113: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: expect(repo.log).to be_error("Branch master does not have any commits yet.")
     NoMethodError:
       undefined method `log' for #<ObjectStore:0x007f003eeef620>
     # /tmp/d20160111-5693-s5ghrl/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")
     NameError:
       undefined local variable or method `repository' for #<Branch:0x007f003eeec858 @name=:master, @commits={}>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:13:in `create'
     # /tmp/d20160111-5693-s5ghrl/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.")
     NameError:
       undefined local variable or method `repository' for #<Branch:0x007f003f0de0f8 @name=:master, @commits={}>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:13:in `create'
     # /tmp/d20160111-5693-s5ghrl/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.")
     NameError:
       undefined local variable or method `repository' for #<Branch:0x007f003f0da2c8 @name=:master, @commits={}>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:13:in `create'
     # /tmp/d20160111-5693-s5ghrl/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: repo.add("object1", "content1")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f0c4888>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:155: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 `checkout' for #<Branch:0x007f003f0bd150 @name=:master, @commits={}>
     # /tmp/d20160111-5693-s5ghrl/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")
     NameError:
       undefined local variable or method `repository' for #<Branch:0x007f003f0b0388 @name=:master, @commits={}>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:13:in `create'
     # /tmp/d20160111-5693-s5ghrl/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.")
     NameError:
       undefined local variable or method `repository' for #<Branch:0x007f003f098d00 @name=:master, @commits={}>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:28:in `remove'
     # /tmp/d20160111-5693-s5ghrl/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.")
     NameError:
       undefined local variable or method `repository' for #<Branch:0x007f003f086358 @name=:master, @commits={}>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:28:in `remove'
     # /tmp/d20160111-5693-s5ghrl/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: add("object1", "content1")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f07eb08>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:189:in `block (3 levels) in <top (required)>'
     # /tmp/d20160111-5693-s5ghrl/solution.rb:44:in `instance_eval'
     # /tmp/d20160111-5693-s5ghrl/solution.rb:44:in `init'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:188: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: repo.add("number", 21)
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f06f388>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:200: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: repo.add("number", 21)
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f06c2a0>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:207: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:0x007f003f05e3a8>
     # /tmp/d20160111-5693-s5ghrl/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: repo.add("number", 42)
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f04d1c0>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:219: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: repo.add("number", 42)
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f034f80>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:229: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 `include?' for nil:NilClass
     # /tmp/d20160111-5693-s5ghrl/solution.rb:81:in `checkout'
     # /tmp/d20160111-5693-s5ghrl/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: repo.add("object1", "content1")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003f006568>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:241: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: repo.add("object1", "content1")
     NameError:
       undefined local variable or method `changes' for #<ObjectStore:0x007f003eff3be8>
     # /tmp/d20160111-5693-s5ghrl/solution.rb:50:in `add'
     # /tmp/d20160111-5693-s5ghrl/spec.rb:255: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.01235 seconds
30 examples, 30 failures

Failed examples:

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

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

Александрина обнови решението на 23.11.2015 16:18 (преди над 8 години)

+require 'digest/sha1'
+require 'date'
+
+class Branch
+ attr_accessor :commits
+ def initialize(name = :master)
+ @name = name
+ @commits = {}
+ end
+
+ def create(branch_name)
+ Branch.new(branch_name)
+ repository[branch_name] = @commits
+ end
+
+ def check(check_branches, check_current, branch_name)
+ message = "Branch #{branch_name} does not exist."
+ if check_branches == true and check_current == false
+ repository.delete(branch_name)
+ Objects.new(branch_name, "",true, "Removed branch #{branch_name}")
+ elsif check_branches and check_current
+ Objects.new(branch_name, "", false, "Cannot remove current branch.")
+ else Objects.new(branch_name, "", false, message)
+ end
+ end
+
+ def remove(branch_name)
+ check_branches = repository.include?(branch_name)
+ check_current = branch_name.eql?(current)
+ check(check_branches, check_current, branch_name)
+ end
+
+end
+
+class ObjectStore < Branch
+ attr_accessor :repository, :current
+ def initialize
+ @repository = {}
+ @current = Branch.new
+ end
+
+ def self.init(&block)
+ new_repository = ObjectStore.new
+ if block_given?
+ new_repository.instance_eval &block
+ else new_repository
+ end
+ end
+
+ def add(name, object)
+ changes[name] = object
+ message = "Added #{name} to stage."
+ Objects.new(name, object, true, message)
+ end
+
+ def branch
+ @current
+ end
+
+ def commit(message)
+ commits[message] = Digest::SHA1.hexdigest(message)
+ if changes.size == 0
+ text = "Nothing to commit, working directory clean."
+ Objects.new("", "", false, text)
+ else text = "#{message}" + '\n' + '\t' + "#{commits.size} objects changed"
+ Objects.new("", "", true, text)
+ end
+ end
+
+ def remove(name)
+ result = changes.delete(name) {"not found"}
+ if result.eql?("not found")
+ message = "Object #{name} is not committed."
+ Objects.new(name, "", false, message)
+ else message = "Added #{name} for removal."
+ Objects.new(name, "", true, message)
+ end
+ end
+end
+
+
+
+class Objects
+ def initialize(name, object, state, message)
+ @name = name
+ @object = object
+ @state = state
+ @message = message
+ end
+
+ def message
+ @message
+ end
+
+ def success?
+ @state == true
+ end
+
+ def error?
+ @state == false
+ end
+
+ def result
+ @object
+ end
+end
+
+class Commit
+ attr_accessor :changes
+ def initialize(message)
+ @message = message
+ @changes = {}
+ end
+
+end

Александрина обнови решението на 23.11.2015 16:22 (преди над 8 години)

require 'digest/sha1'
require 'date'
class Branch
attr_accessor :commits
def initialize(name = :master)
@name = name
@commits = {}
end
def create(branch_name)
Branch.new(branch_name)
repository[branch_name] = @commits
end
def check(check_branches, check_current, branch_name)
- message = "Branch #{branch_name} does not exist."
- if check_branches == true and check_current == false
- repository.delete(branch_name)
- Objects.new(branch_name, "",true, "Removed branch #{branch_name}")
- elsif check_branches and check_current
- Objects.new(branch_name, "", false, "Cannot remove current branch.")
- else Objects.new(branch_name, "", false, message)
- end
+ message = "Branch #{branch_name} does not exist."
+ if check_branches == true and check_current == false
+ repository.delete(branch_name)
+ Objects.new(branch_name, "",true, "Removed branch #{branch_name}")
+ elsif check_branches and check_current
+ Objects.new(branch_name, "", false, "Cannot remove current branch.")
+ else Objects.new(branch_name, "", false, message)
+ end
end
def remove(branch_name)
- check_branches = repository.include?(branch_name)
- check_current = branch_name.eql?(current)
- check(check_branches, check_current, branch_name)
+ check_branches = repository.include?(branch_name)
+ check_current = branch_name.eql?(current)
+ check(check_branches, check_current, branch_name)
end
-
end
class ObjectStore < Branch
attr_accessor :repository, :current
def initialize
@repository = {}
@current = Branch.new
end
def self.init(&block)
- new_repository = ObjectStore.new
- if block_given?
- new_repository.instance_eval &block
- else new_repository
- end
+ new_repository = ObjectStore.new
+ if block_given?
+ new_repository.instance_eval &block
+ else new_repository
+ end
end
def add(name, object)
changes[name] = object
message = "Added #{name} to stage."
Objects.new(name, object, true, message)
end
def branch
@current
end
def commit(message)
commits[message] = Digest::SHA1.hexdigest(message)
if changes.size == 0
text = "Nothing to commit, working directory clean."
Objects.new("", "", false, text)
else text = "#{message}" + '\n' + '\t' + "#{commits.size} objects changed"
Objects.new("", "", true, text)
end
end
def remove(name)
result = changes.delete(name) {"not found"}
if result.eql?("not found")
message = "Object #{name} is not committed."
Objects.new(name, "", false, message)
else message = "Added #{name} for removal."
Objects.new(name, "", true, message)
end
end
end
class Objects
def initialize(name, object, state, message)
@name = name
@object = object
@state = state
@message = message
end
def message
@message
end
def success?
@state == true
end
def error?
@state == false
end
def result
@object
end
end
class Commit
attr_accessor :changes
def initialize(message)
@message = message
@changes = {}
end
-
-end
+end

Александрина обнови решението на 23.11.2015 16:46 (преди над 8 години)

require 'digest/sha1'
require 'date'
class Branch
attr_accessor :commits
def initialize(name = :master)
@name = name
@commits = {}
end
def create(branch_name)
Branch.new(branch_name)
repository[branch_name] = @commits
end
def check(check_branches, check_current, branch_name)
message = "Branch #{branch_name} does not exist."
if check_branches == true and check_current == false
repository.delete(branch_name)
Objects.new(branch_name, "",true, "Removed branch #{branch_name}")
elsif check_branches and check_current
Objects.new(branch_name, "", false, "Cannot remove current branch.")
else Objects.new(branch_name, "", false, message)
end
end
def remove(branch_name)
check_branches = repository.include?(branch_name)
check_current = branch_name.eql?(current)
check(check_branches, check_current, branch_name)
end
end
class ObjectStore < Branch
attr_accessor :repository, :current
def initialize
@repository = {}
@current = Branch.new
end
def self.init(&block)
new_repository = ObjectStore.new
if block_given?
new_repository.instance_eval &block
else new_repository
end
end
def add(name, object)
changes[name] = object
message = "Added #{name} to stage."
Objects.new(name, object, true, message)
end
def branch
@current
end
def commit(message)
- commits[message] = Digest::SHA1.hexdigest(message)
+ commits[Digest::SHA1.hexdigest(message)] = changes
if changes.size == 0
text = "Nothing to commit, working directory clean."
Objects.new("", "", false, text)
else text = "#{message}" + '\n' + '\t' + "#{commits.size} objects changed"
Objects.new("", "", true, text)
end
end
def remove(name)
result = changes.delete(name) {"not found"}
if result.eql?("not found")
message = "Object #{name} is not committed."
Objects.new(name, "", false, message)
else message = "Added #{name} for removal."
Objects.new(name, "", true, message)
end
end
+
+ def checkout(commit_hash)
+ message = "Commit #{commit_hash} does not exist."
+ if commits.include?(commit_hash)
+ Objects.new(commit_hash, "", true, "HEAD is now at #{commit_hash}.")
+ else Objects.new(commit_hash, "", false, message)
+ end
+ end
end
class Objects
def initialize(name, object, state, message)
@name = name
@object = object
@state = state
@message = message
end
def message
@message
end
def success?
@state == true
end
def error?
@state == false
end
def result
@object
end
end
class Commit
attr_accessor :changes
def initialize(message)
@message = message
@changes = {}
end
-end
+end