Class: Insup::Insales::Asset
- 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
- #data ⇒ Object
- #dirname ⇒ Object
- #download_data_from_url ⇒ Object
- #filename ⇒ Object
- #get_full ⇒ Object
- #is_image? ⇒ Boolean
- #path ⇒ Object
- #theme_id ⇒ Object
- #url ⇒ Object
Methods inherited from Base
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
#data ⇒ Object
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 |
#dirname ⇒ Object
36 37 38 |
# File 'lib/insup/insales/asset.rb', line 36 def dirname TYPE_MAP.invert[type] end |
#download_data_from_url ⇒ Object
65 66 67 |
# File 'lib/insup/insales/asset.rb', line 65 def download_data_from_url Net::HTTP.get(URI(self.url)) end |
#filename ⇒ Object
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_full ⇒ Object
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
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 |
#path ⇒ Object
40 41 42 |
# File 'lib/insup/insales/asset.rb', line 40 def path "#{dirname}/#{filename}" end |
#theme_id ⇒ Object
53 54 55 |
# File 'lib/insup/insales/asset.rb', line 53 def theme_id [:theme_id] end |
#url ⇒ Object
61 62 63 |
# File 'lib/insup/insales/asset.rb', line 61 def url "#{self.class.site}#{self.asset_url}" end |