Sha256: e3db63c3853f85bc9670a3ad17fea0c59756a75b4e1809f5430afe704f7e465f

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

module Jail
  class Cdnjs
    attr_reader :github, :root_path, :package_path
    delegate    :name, :filename, :version, :description,
                :homepage, :repositories, :maintainers, :to => :package #etc

    def self.github
      @github ||= Jail::Github.find("cdnjs", "cdnjs", "ajax/libs")
    end

    def self.libs
      @libs ||= github.contents
    end
    libs # load & memoize cdnjs libraries

    def self.lib(path)
      github.where(path).contents
    end

    def self.find_path(name)
      hash = libs.find { |hashie| hashie.path.split("/").last == name }
      hash and hash.path # raise if not found ?
    end

    def self.find(name)
      path = find_path(name)
      lib = lib(path)

      self.new(path, lib)
    end

    def initialize(path, lib)
      @github       = self.class.github
      @root_path    = path
      @package_path = lib.find {|h| h.type == "file"}.path
    end

    def package
      @package ||= Hashie::Mash.new ActiveSupport::JSON.decode( github.where(package_path).read )
    end

    # gets the version from the package.json & returns a path
    def version_path
      Pathname(root_path).join(version)
    end

    def files
      @files ||= github.where(version_path).contents
    end

    def file(name)
      github.where(version_path.join(name))
    end

    def mapped_files
      files.map(&:name).group_by {|name| Pathname(name).extname }
    end

    def install(params)
      files_to_write = params.map {|file, num| file if num == "1"}.compact!

      files_to_write.each do |name|
        file(name).download()
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jail-0.1.1 app/models/jail/cdnjs.rb