Class: Jail::Github
- Inherits:
-
Object
- Object
- Jail::Github
- Defined in:
- app/models/jail/github.rb
Overview
This is a wrapper around ::Github
Instance Attribute Summary collapse
-
#github ⇒ Object
Returns the value of attribute github.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#repo ⇒ Object
Returns the value of attribute repo.
-
#spec ⇒ Object
Returns the value of attribute spec.
Class Method Summary collapse
- .add_githublist(yaml_path) ⇒ Object
-
.all ⇒ Object
TODO : raise if missing descr:.
-
.find(aname, arepo, apath = nil) ⇒ Object
Use this to initialize Github.
Instance Method Summary collapse
- #contents ⇒ Object
-
#initialize ⇒ Github
constructor
Sets github attr which holds the Github (API) instance used by repo, contents, readme etc.
- #install ⇒ Object
-
#read(apath) ⇒ Object
TODO : raise error if path’s not a file.
-
#readme ⇒ Object
TODO : split in 2 methods for consistency.
- #remove ⇒ Object
- #repos ⇒ Object
Constructor Details
Instance Attribute Details
#github ⇒ Object
Returns the value of attribute github.
4 5 6 |
# File 'app/models/jail/github.rb', line 4 def github @github end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'app/models/jail/github.rb', line 4 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'app/models/jail/github.rb', line 4 def path @path end |
#repo ⇒ Object
Returns the value of attribute repo.
4 5 6 |
# File 'app/models/jail/github.rb', line 4 def repo @repo end |
#spec ⇒ Object
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 |
.all ⇒ Object
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
#contents ⇒ Object
42 43 44 45 |
# File 'app/models/jail/github.rb', line 42 def contents self.path ||= "/" github.repos.contents.get(name, repo, path) end |
#install ⇒ Object
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 |
#readme ⇒ Object
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 |
#remove ⇒ Object
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 |
#repos ⇒ Object
38 39 40 |
# File 'app/models/jail/github.rb', line 38 def repos github.repos.get(name, repo) end |