Class: Jail::Cdnjs
- Inherits:
-
Object
- Object
- Jail::Cdnjs
- Defined in:
- app/models/jail/cdnjs.rb
Instance Attribute Summary collapse
-
#github ⇒ Object
readonly
Returns the value of attribute github.
-
#package_path ⇒ Object
readonly
Returns the value of attribute package_path.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
Class Method Summary collapse
Instance Method Summary collapse
- #file(path) ⇒ Object
-
#initialize(path, lib) ⇒ Cdnjs
constructor
A new instance of Cdnjs.
- #install(params) ⇒ Object
- #mapped_files ⇒ Object
- #package ⇒ Object
-
#tree ⇒ Object
build a depth first tree.
- #version_files ⇒ Object
-
#version_path ⇒ Object
gets the version from the package.json & returns a path.
Constructor Details
#initialize(path, lib) ⇒ Cdnjs
Returns a new instance of Cdnjs.
32 33 34 35 36 |
# File 'app/models/jail/cdnjs.rb', line 32 def initialize(path, lib) @github = self.class.github @root_path = path @package_path = lib.find {|h| h.type == "file"}.path end |
Instance Attribute Details
#github ⇒ Object (readonly)
Returns the value of attribute github.
3 4 5 |
# File 'app/models/jail/cdnjs.rb', line 3 def github @github end |
#package_path ⇒ Object (readonly)
Returns the value of attribute package_path.
3 4 5 |
# File 'app/models/jail/cdnjs.rb', line 3 def package_path @package_path end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
3 4 5 |
# File 'app/models/jail/cdnjs.rb', line 3 def root_path @root_path end |
Class Method Details
.find(name) ⇒ Object
25 26 27 28 29 30 |
# File 'app/models/jail/cdnjs.rb', line 25 def self.find(name) path = find_path(name) lib = lib(path) self.new(path, lib) end |
.find_path(name) ⇒ Object
20 21 22 23 |
# File 'app/models/jail/cdnjs.rb', line 20 def self.find_path(name) hash = libs.find { |hashie| hashie.path.split("/").last == name } hash and hash.path # raise if not found ? end |
.github ⇒ Object
7 8 9 |
# File 'app/models/jail/cdnjs.rb', line 7 def self.github @github ||= Jail::Github.find("cdnjs", "cdnjs", "ajax/libs") end |
.lib(path) ⇒ Object
16 17 18 |
# File 'app/models/jail/cdnjs.rb', line 16 def self.lib(path) github.where(path).contents end |
.libs ⇒ Object
11 12 13 |
# File 'app/models/jail/cdnjs.rb', line 11 def self.libs @libs ||= github.contents end |
Instance Method Details
#file(path) ⇒ Object
68 69 70 |
# File 'app/models/jail/cdnjs.rb', line 68 def file(path) github.where(path) end |
#install(params) ⇒ Object
76 77 78 79 80 81 82 |
# File 'app/models/jail/cdnjs.rb', line 76 def install(params) files_to_write = params.map {|file, checkbox_val| file if checkbox_val == "1"}.compact files_to_write.each do |name| file(name).download() end end |
#mapped_files ⇒ Object
72 73 74 |
# File 'app/models/jail/cdnjs.rb', line 72 def mapped_files files.map(&:name).group_by {|name| Pathname(name).extname } end |
#package ⇒ Object
38 39 40 |
# File 'app/models/jail/cdnjs.rb', line 38 def package @package ||= Hashie::Mash.new ActiveSupport::JSON.decode( github.where(package_path).read ) end |
#tree ⇒ Object
build a depth first tree
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/jail/cdnjs.rb', line 52 def tree @tree and return @tree @tree = [] file_set = version_files while child = file_set.shift tree << child #if child.dir? if child.type == "dir" file_set.unshift( github.where(child.path).contents ).flatten! end end @tree end |
#version_files ⇒ Object
47 48 49 |
# File 'app/models/jail/cdnjs.rb', line 47 def version_files @version_files ||= github.where(version_path).contents end |
#version_path ⇒ Object
gets the version from the package.json & returns a path
43 44 45 |
# File 'app/models/jail/cdnjs.rb', line 43 def version_path Pathname(root_path).join(version) end |