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
readonly
Returns the value of attribute github.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
Class Method Summary collapse
- .add_githublist(yaml_path) ⇒ Object
-
.all ⇒ Object
TODO : raise if missing descr:.
-
.find(name, repo, path = nil) ⇒ Object
Uhh useless ? Or AR Sexy ?.
Instance Method Summary collapse
- #contents ⇒ Object
- #delete(type = nil) ⇒ Object
- #delete_all ⇒ Object (also: #remove)
- #download(type = nil) ⇒ Object
- #extract_type(filename) ⇒ Object
-
#initialize(name, repo) ⇒ Github
constructor
A new instance of Github.
- #read ⇒ Object
-
#readme ⇒ Object
TODO : split in 2 methods for consistency.
-
#repos ⇒ Object
do I need this method ?.
- #target(type = nil) ⇒ Object
-
#where(path) ⇒ Object
another AR alike for chaining.
-
#write_all ⇒ Object
(also: #install)
Depends on yaml files: dont use elsewhere.
Constructor Details
#initialize(name, repo) ⇒ Github
Returns a new instance of Github.
28 29 30 31 32 33 34 35 |
# File 'app/models/jail/github.rb', line 28 def initialize(name, repo) @name= name @repo= repo @spec= self.class.githublist["#{@name}/#{@repo}"] @github = defined?(Jail::LOGIN) ? ::Github.new({ :basic_auth => Jail::LOGIN }) : ::Github.new end |
Instance Attribute Details
#github ⇒ Object (readonly)
Returns the value of attribute github.
4 5 6 |
# File 'app/models/jail/github.rb', line 4 def github @github end |
#name ⇒ Object (readonly)
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.
5 6 7 |
# File 'app/models/jail/github.rb', line 5 def path @path end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
4 5 6 |
# File 'app/models/jail/github.rb', line 4 def repo @repo end |
#spec ⇒ Object (readonly)
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
8 9 10 11 |
# File 'app/models/jail/github.rb', line 8 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:
17 18 19 |
# File 'app/models/jail/github.rb', line 17 def self.all githublist.group_by {|k, v| v[:descr].match(/\w+:/).to_s if v[:descr]} end |
.find(name, repo, path = nil) ⇒ Object
Uhh useless ? Or AR Sexy ?
22 23 24 25 26 |
# File 'app/models/jail/github.rb', line 22 def self.find(name, repo, path = nil) new(name, repo).tap do |yo| yo.path= path end end |
Instance Method Details
#contents ⇒ Object
48 49 50 51 |
# File 'app/models/jail/github.rb', line 48 def contents self.path ||= "/" github.repos.contents.get(name, repo, path) end |
#delete(type = nil) ⇒ Object
69 70 71 |
# File 'app/models/jail/github.rb', line 69 def delete(type = nil) t = target(type) and t.exist? and t.delete end |
#delete_all ⇒ Object Also known as: remove
102 103 104 105 106 |
# File 'app/models/jail/github.rb', line 102 def delete_all [:js, :css, :img].each do |type| where(spec[type]).delete(type) if spec[type] end end |
#download(type = nil) ⇒ Object
64 65 66 67 |
# File 'app/models/jail/github.rb', line 64 def download(type = nil) t = target(type) and t.parent.mkpath t.open('w') {|f| f.write( read ) } end |
#extract_type(filename) ⇒ Object
87 88 89 90 |
# File 'app/models/jail/github.rb', line 87 def extract_type(filename) type = Pathname(filename).extname type = type.gsub(/\./, "").to_sym end |
#read ⇒ Object
59 60 61 62 |
# File 'app/models/jail/github.rb', line 59 def read #raise "blah" unless contents.type == "file" text = Base64.decode64 contents.content end |
#readme ⇒ Object
TODO : split in 2 methods for consistency
54 55 56 57 |
# File 'app/models/jail/github.rb', line 54 def readme text = Base64.decode64 github.repos.contents.readme(name, repo).content github.markdown.render :text => text end |
#repos ⇒ Object
do I need this method ?
44 45 46 |
# File 'app/models/jail/github.rb', line 44 def repos @repos ||= github.repos.get(name, repo) end |
#target(type = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/jail/github.rb', line 73 def target(type=nil) filename= Pathname(path).basename type = type || extract_type(filename) case type when :js, :coffee Rails.root.join("vendor/assets/javascripts/#{filename}") when :css, :scss, :less Rails.root.join("vendor/assets/stylesheets/#{filename}") when :img, :png, :gif, :jpeg Rails.root.join("vendor/assets/images/#{filename}") end end |
#where(path) ⇒ Object
another AR alike for chaining
38 39 40 41 |
# File 'app/models/jail/github.rb', line 38 def where(path) self.path= path self end |
#write_all ⇒ Object Also known as: install
Depends on yaml files: dont use elsewhere
95 96 97 98 99 |
# File 'app/models/jail/github.rb', line 95 def write_all [:js, :css, :img].each do |type| where(spec[type]).download(type) if spec[type] end end |