Class: Insup::Insales::Asset

Inherits:
Base
  • Object
show all
Defined in:
lib/insup/insales/asset.rb,
lib/insup/insales/theme.rb

Constant Summary collapse

TYPE_MAP =
{
  'media' => 'Asset::Media',
  'snippets' => 'Asset::Snippet',
  'templates' => 'Asset::Template',
  'config' => 'Asset::Configuration' 
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

configure

Class Method Details

.get_type(path) ⇒ Object



30
31
32
33
34
# File 'lib/insup/insales/asset.rb', line 30

def self.get_type(path)
  TYPE_MAP.each do |k,v|
    return v if path.start_with?("#{k}/")
  end
end

Instance Method Details

#dataObject



44
45
46
47
48
49
50
51
# File 'lib/insup/insales/asset.rb', line 44

def data
  if respond_to? (:asset_url)
    download_data_from_url
  elsif ['Asset::Snippet', 'Asset::Template'].include?(type)
    w = get_full
    w.content if w.respond_to?(:content)
  end
end

#dirnameObject



36
37
38
# File 'lib/insup/insales/asset.rb', line 36

def dirname
  TYPE_MAP.invert[type]
end

#download_data_from_urlObject



65
66
67
# File 'lib/insup/insales/asset.rb', line 65

def download_data_from_url
  Net::HTTP.get(URI(self.url))
end

#filenameObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/insup/insales/asset.rb', line 15

def filename
  fname_rex = /\..*+$/
  if name.match(fname_rex)
    name
  elsif human_readable_name.match(fname_rex)
    human_readable_name
  else
    nil
  end
end

#get_fullObject



57
58
59
# File 'lib/insup/insales/asset.rb', line 57

def get_full
  self.class.find(id, params: {theme_id: theme_id})
end

#is_image?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/insup/insales/asset.rb', line 26

def is_image?
  content_type =~ /image/ || content_type =~ /octet-stream/ || content_type =~ /flash/
end

#pathObject



40
41
42
# File 'lib/insup/insales/asset.rb', line 40

def path 
  "#{dirname}/#{filename}"
end

#theme_idObject



53
54
55
# File 'lib/insup/insales/asset.rb', line 53

def theme_id
  prefix_options[:theme_id]
end

#urlObject



61
62
63
# File 'lib/insup/insales/asset.rb', line 61

def url
  "#{self.class.site}#{self.asset_url}"
end