Class: Jail::Github

Inherits:
Object
  • Object
show all
Defined in:
app/models/jail/github.rb

Overview

This is a wrapper around ::Github

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGithub

Sets github attr which holds the Github (API) instance used by repo, contents, readme etc



32
33
34
35
36
# File 'app/models/jail/github.rb', line 32

def initialize
  @github = defined?(Jail::LOGIN) ? 
              ::Github.new({ :basic_auth => Jail::LOGIN }) :
              ::Github.new
end

Instance Attribute Details

#githubObject

Returns the value of attribute github.



4
5
6
# File 'app/models/jail/github.rb', line 4

def github
  @github
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'app/models/jail/github.rb', line 4

def name
  @name
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'app/models/jail/github.rb', line 4

def path
  @path
end

#repoObject

Returns the value of attribute repo.



4
5
6
# File 'app/models/jail/github.rb', line 4

def repo
  @repo
end

#specObject

Returns the value of attribute spec.



4
5
6
# File 'app/models/jail/github.rb', line 4

def spec
  @spec
end

Class Method Details

.add_githublist(yaml_path) ⇒ Object



7
8
9
10
# File 'app/models/jail/github.rb', line 7

def self.add_githublist(yaml_path)
  hash = YAML.load_file(yaml_path).to_hash
  self.githublist= self.githublist.merge(hash)
end

.allObject

TODO : raise if missing descr:



16
17
18
# File 'app/models/jail/github.rb', line 16

def self.all
  githublist.group_by {|k, v| v[:descr].match(/\w+:/).to_s if v[:descr]}
end

.find(aname, arepo, apath = nil) ⇒ Object

Use this to initialize Github



21
22
23
24
25
26
27
28
# File 'app/models/jail/github.rb', line 21

def self.find(aname, arepo, apath = nil)
  self.new.tap do |yo|
    yo.name= aname
    yo.repo= arepo
    yo.path= apath
    yo.spec= githublist["#{yo.name}/#{yo.repo}"]
  end
end

Instance Method Details

#contentsObject



42
43
44
45
# File 'app/models/jail/github.rb', line 42

def contents
  self.path ||= "/"
  github.repos.contents.get(name, repo, path)
end

#installObject



59
60
61
62
63
64
# File 'app/models/jail/github.rb', line 59

def install
  #contents._links[:git]
  download(:js)
  download(:css)
  download(:img)
end

#read(apath) ⇒ Object

TODO : raise error if path’s not a file



54
55
56
57
# File 'app/models/jail/github.rb', line 54

def read(apath)
  self.path= apath
  text = Base64.decode64 contents.content
end

#readmeObject

TODO : split in 2 methods for consistency



48
49
50
51
# File 'app/models/jail/github.rb', line 48

def readme
  text = Base64.decode64 github.repos.contents.readme(name, repo).content
  github.markdown.render :text => text
end

#removeObject



66
67
68
69
70
# File 'app/models/jail/github.rb', line 66

def remove
  delete_file(:js)
  delete_file(:css)
  delete_file(:img)
end

#reposObject



38
39
40
# File 'app/models/jail/github.rb', line 38

def repos
  github.repos.get(name, repo)
end