Class: CDNio::CDN

Inherits:
Object
  • Object
show all
Defined in:
lib/cdnio.rb

Constant Summary collapse

PROVIDERS =
[:cdnjs, :google, :microsoft]

Instance Method Summary collapse

Constructor Details

#initializeCDN

Returns a new instance of CDN.



10
11
12
# File 'lib/cdnio.rb', line 10

def initialize
  @providers = {}
end

Instance Method Details

#latest(library, provider = :all) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cdnio.rb', line 14

def latest(library, provider = :all)
  provider = provider.downcase.to_sym
  raise UnsupportedProviderException, provider unless (PROVIDERS.include?(provider) || provider == :all)

  if provider == :all
    get_missing

    Hash[*PROVIDERS.map do |prov|
      lib = @providers[prov].latest(library)
      [prov, lib] if lib
    end.flatten.compact]
  else
    get_provider(provider) unless @providers.include?(provider)

    @providers[provider].latest(library)
  end
end

#libraries(provider = :all) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cdnio.rb', line 32

def libraries(provider = :all)
  provider = provider.to_sym
  raise UnsupportedProviderException, provider unless (PROVIDERS.include?(provider) || provider == :all)
  if provider == :all
    get_missing 

    Hash[*PROVIDERS.map do |prov|
      libraries = @providers[prov].libraries
      [prov, libraries] unless libraries.empty?
    end.flatten(1).compact]
  else
    get_provider(provider)

    @providers[provider].libraries
  end
end