Class: Api::Image
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- Api::Image
- Includes:
- Models::Imageable
- Defined in:
- app/models/api/image.rb
Overview
An activeresource wrapper to load up image asset from an API endpoint
Constant Summary
Constants included from Models::Imageable
Models::Imageable::STANDARD_SIZES, Models::Imageable::STANDARD_THUMBNAIL_SIZE, Models::Imageable::VALID_IMAGE_URL_OPTIONS
Class Method Summary collapse
-
._cr_find ⇒ Object
Wrap cached_resource's find with per-key mutex coalescing.
- .find(*args) ⇒ Api::Image
Instance Method Summary collapse
-
#ik_path ⇒ String
ImageKit path for the asset.
Methods included from Models::Imageable
#aspect_ratio, #aspect_ratio_label, #human_size, #ik_file_name, #ik_file_name_with_extension, #ik_get_file_details, #ik_get_metadata, #ik_get_metadata_by_url, #ik_raw_url, #ik_url, #image_info, #image_url, #info, #presets_hash, #sourceset, suggested_sources_for_select, #thumbnail_url, #to_s
Class Method Details
._cr_find ⇒ Object
Wrap cached_resource's find with per-key mutex coalescing.
alias_method captures cached_resource's patched find at class load time.
28 |
# File 'app/models/api/image.rb', line 28 alias _cr_find find |
.find(*args) ⇒ Api::Image
32 33 34 35 36 |
# File 'app/models/api/image.rb', line 32 def find(*args, **) key = args.first.to_s lock = FETCH_LOCKS.compute_if_absent(key) { Mutex.new } lock.synchronize { _cr_find(*args, **) } end |
Instance Method Details
#ik_path ⇒ String
Returns ImageKit path for the asset.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/api/image.rb', line 40 def ik_path # ImageKit 4.0 returns snake_case keys: file_path instead of filePath # Handle both hash access and method access for API responses path = if asset.respond_to?(:attributes) && asset.attributes.is_a?(Hash) # ActiveResource objects store data in attributes hash asset.attributes['file_path'] || asset.attributes['filePath'] elsif asset.respond_to?(:file_path) asset.file_path || asset.filePath elsif asset.is_a?(Hash) asset['file_path'] || asset['filePath'] || asset[:file_path] || asset[:filePath] end # Only fall back to slug-based path if we couldn't get a path from asset # Use slug without extension since ImageKit handles format dynamically path.presence || "/img/#{slug}" end |