Module: CarrierWave::Qiniu::Url

Defined in:
lib/carrierwave/qiniu/url.rb

Instance Method Summary collapse

Instance Method Details

#stylesObject



48
49
50
# File 'lib/carrierwave/qiniu/url.rb', line 48

def styles
  self.class.get_qiniu_styles
end

#url(*args) ⇒ Object

Examples:

avatar.url(:version)
avatar.url(:version, inline: true)
avatar.url(style: 'imageView2/0/w/200')


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/carrierwave/qiniu/url.rb', line 12

def url(*args)
  return super if args.empty?

  # return nil if blank
  return if file.blank?

  # Usage: avatar.url(style: 'imageView/0/w/200')
  if args.first.is_a? Hash
    if style = args.first[:style]
      return file.url(style: style)
    end
  else
    # Usage: avatar.url(version, options)
    version = args.first.to_sym
    if styles.has_key? version
      options = args.last
      # Usage: avatar.url(:version, inline: true)
      url_options = if options.present? && options.is_a?(Hash) && options[:inline] && styles[version]
                      {style: styles[version]}
                    else
                      # global inline mode
                      if self.class.qiniu_style_inline && styles[version]
                        {style: styles[version]}
                      else
                        # Usage: avatar.url(:version)
                        {version: version}
                      end
                    end
      return file.url(url_options) if url_options
    end
  end

  # Fallback to original url
  super
end