class GitMeThere::Scenario
Attributes
g[RW]
Give direct access to the Git::Base object in a scenario
Public Class Methods
new(name="my-scenario", explanation="")
click to toggle source
# File lib/gitmethere.rb, line 28 def initialize(name="my-scenario", explanation="") @name = name @g = Git.init(name) self.create_file(name='README.md', content=explanation) @g.add @g.commit("Initial commit") end
Public Instance Methods
append_to_file(name="my-file.md", content="Adding a bit more content")
click to toggle source
# File lib/gitmethere.rb, line 53 def append_to_file(name="my-file.md", content="Adding a bit more content") File.open("#{@name}/#{name}", 'a') do | f | f.puts content end end
checkout_branch(branch)
click to toggle source
# File lib/gitmethere.rb, line 37 def checkout_branch(branch) @g.branch(branch).checkout end
commit(message, author = nil)
click to toggle source
# File lib/gitmethere.rb, line 74 def commit(message, author = nil) if author.nil? @g.commit(message) else @g.commit(message, author: author.git_author) end end
create_file(name="my-file.md", content="")
click to toggle source
# File lib/gitmethere.rb, line 45 def create_file(name="my-file.md", content="") File.open("#{@name}/#{name}", 'w') do | f | unless content.empty? f.puts content end end end
delete_file(name="my-file.md")
click to toggle source
# File lib/gitmethere.rb, line 70 def delete_file(name="my-file.md") File.delete("#{@name}/#{name}") end
pause(message = nil)
click to toggle source
# File lib/gitmethere.rb, line 82 def pause(message = nil) STDIN.echo = false if message puts message end puts "Press any key to continue..." input = STDIN.getch ensure STDIN.ioflush STDIN.echo = true end
rename_file(source="my-file.md", target="my-new-file.md")
click to toggle source
# File lib/gitmethere.rb, line 66 def rename_file(source="my-file.md", target="my-new-file.md") File.rename("#{@name}/#{source}", "#{@name}/#{target}") end
replace_in_file(name="my-file.md", content="Adding a bit more content", new_content="Replaced content")
click to toggle source
# File lib/gitmethere.rb, line 59 def replace_in_file(name="my-file.md", content="Adding a bit more content", new_content="Replaced content") text = File.read("#{@name}/#{name}") File.open("#{@name}/#{name}", 'w') do | f | f.puts text.gsub(content, new_content) end end
stage_changes()
click to toggle source
# File lib/gitmethere.rb, line 41 def stage_changes @g.add end