Class: SprocketsCDN::Providers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sprockets_cdn/providers/base.rb

Direct Known Subclasses

Qiniu, Upyun

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opt) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
# File 'lib/sprockets_cdn/providers/base.rb', line 7

def initialize opt
  @access_key = opt[:access_key]
  @secret_key = opt[:secret_key]
  @asset_host = opt[:asset_host]
  @bucket     = opt[:bucket]
end

Instance Attribute Details

#access_keyObject

Returns the value of attribute access_key.



6
7
8
# File 'lib/sprockets_cdn/providers/base.rb', line 6

def access_key
  @access_key
end

#secret_keyObject

Returns the value of attribute secret_key.



6
7
8
# File 'lib/sprockets_cdn/providers/base.rb', line 6

def secret_key
  @secret_key
end

Instance Method Details

#generate_remote_url(path) ⇒ Object



28
29
30
# File 'lib/sprockets_cdn/providers/base.rb', line 28

def generate_remote_url path
  URI.join(@asset_host, path)
end

#get_key(full_path, base_dir) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/sprockets_cdn/providers/base.rb', line 14

def get_key full_path, base_dir
  if defined? Rails
    asset_root = Rails.root.join('public').to_s
    asset_root = base_dir unless base_dir.include?(asset_root)
    full_path.sub(asset_root, '')
  else
    full_path.sub(base_dir, '')
  end
end

#urlsafe_base64_encode(content) ⇒ Object



24
25
26
# File 'lib/sprockets_cdn/providers/base.rb', line 24

def urlsafe_base64_encode content
  Base64.encode64(content).strip.gsub('+', '-').gsub('/','_').gsub(/\r?\n/, '')
end