Class: Janky::GitHub::Mock
- Inherits:
-
Object
- Object
- Janky::GitHub::Mock
- Defined in:
- lib/janky/github/mock.rb
Defined Under Namespace
Classes: Response
Instance Method Summary collapse
- #branch(nwo, branch) ⇒ Object
- #commit(nwo, sha) ⇒ Object
- #create(nwo, secret, url) ⇒ Object
- #delete(url) ⇒ Object
- #get(url) ⇒ Object
-
#initialize(user, password) ⇒ Mock
constructor
A new instance of Mock.
- #make_private(nwo) ⇒ Object
- #make_public(nwo) ⇒ Object
- #make_unauthorized(nwo) ⇒ Object
- #repo_get(nwo) ⇒ Object
- #set_branch_head(nwo, branch, sha) ⇒ Object
Constructor Details
#initialize(user, password) ⇒ Mock
Returns a new instance of Mock.
6 7 8 9 |
# File 'lib/janky/github/mock.rb', line 6 def initialize(user, password) @repos = {} @branch_shas = {} end |
Instance Method Details
#branch(nwo, branch) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/janky/github/mock.rb', line 55 def branch(nwo, branch) data = { "sha" => @branch_shas[[nwo, branch]] } Response.new("200", Yajl.dump(data)) end |
#commit(nwo, sha) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/janky/github/mock.rb', line 62 def commit(nwo, sha) data = { "commit" => { "author" => { "name" => "Test Author", "email" => "[email protected]" }, "message" => "Test Message" } } Response.new("200", Yajl.dump(data)) end |
#create(nwo, secret, url) ⇒ Object
27 28 29 30 |
# File 'lib/janky/github/mock.rb', line 27 def create(nwo, secret, url) data = {"url" => "https://api.github.com/hooks/#{Time.now.to_f}"} Response.new("201", Yajl.dump(data)) end |
#delete(url) ⇒ Object
36 37 38 |
# File 'lib/janky/github/mock.rb', line 36 def delete(url) Response.new("204") end |
#get(url) ⇒ Object
32 33 34 |
# File 'lib/janky/github/mock.rb', line 32 def get(url) Response.new("200") end |
#make_private(nwo) ⇒ Object
11 12 13 |
# File 'lib/janky/github/mock.rb', line 11 def make_private(nwo) @repos[nwo] = :private end |
#make_public(nwo) ⇒ Object
15 16 17 |
# File 'lib/janky/github/mock.rb', line 15 def make_public(nwo) @repos[nwo] = :public end |
#make_unauthorized(nwo) ⇒ Object
19 20 21 |
# File 'lib/janky/github/mock.rb', line 19 def (nwo) @repos[nwo] = :unauthorized end |
#repo_get(nwo) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/janky/github/mock.rb', line 40 def repo_get(nwo) repo = { "name" => nwo.split("/").last, "private" => (@repos[nwo] == :private), "git_url" => "git://github.com/#{nwo}", "ssh_url" => "[email protected]:#{nwo}" } if @repos[nwo] == :unauthorized Response.new("404", Yajl.dump({})) else Response.new("200", Yajl.dump(repo)) end end |
#set_branch_head(nwo, branch, sha) ⇒ Object
23 24 25 |
# File 'lib/janky/github/mock.rb', line 23 def set_branch_head(nwo, branch, sha) @branch_shas[[nwo, branch]] = sha end |