class IziLightup::AssetInfo

Attributes

environment[R]
manifest[R]
name[R]

Public Class Methods

new(name, manifest: nil, environment: nil) click to toggle source
# File lib/izi_lightup/asset_info.rb, line 9
def initialize(name, manifest: nil, environment: nil)
  @name = name
  @manifest = manifest
  @environment = environment
end

Public Instance Methods

content_type() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 24
def content_type
  @content_type ||= detect_content_type
end
dimentions()
Alias for: size
exist?() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 15
def exist?
  @exist ||= check_existence
end
Also aliased as: exists?
exists?()
Alias for: exist?
path() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 20
def path
  @path ||= detect_path
end
size() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 34
def size
  @size ||= detect_size
end
Also aliased as: dimentions
type() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 28
def type
  return unless exist?

  @type ||= FastImage.type(path)
end

Private Instance Methods

assets_output_dir() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 90
def assets_output_dir
  @assets_output_dir ||= Pathname.new(manifest&.dir.presence || Rails.root.join('public', assets_prefix))
end
assets_prefix() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 94
def assets_prefix
  Rails.application.config.assets.prefix.presence&.gsub(%r{^/}, '') || 'assets'
end
check_existence() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 41
def check_existence
  env_asset.present? || manifest&.assets&.key?(name)
end
detect_content_type() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 51
def detect_content_type
  return unless exist?

  env_asset&.content_type.presence ||
    Mime::Type.lookup_by_extension(FastImage.type(path)).to_s
end
detect_path() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 45
def detect_path
  return unless exist?

  env_pathname.presence || assets_output_dir.join(final_asset_name)
end
detect_size() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 58
def detect_size
  return unless exist?

  FastImage.size(path)
end
env_asset() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 72
def env_asset
  @env_asset ||= environment&.find_asset(name)
end
env_pathname() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 64
def env_pathname
  return unless env_asset
  return env_asset.pathname if env_asset.respond_to?(:pathname)
  return Pathname.new(env_asset.filename) if env_asset.respond_to?(:filename)

  nil
end
environment?() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 76
def environment?
  environment.present?
end
final_asset_name() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 84
def final_asset_name
  return name if environment?

  manifest.assets[name] if manifest.assets.present?
end
manifest?() click to toggle source
# File lib/izi_lightup/asset_info.rb, line 80
def manifest?
  manifest.present?
end