class Uploadcare::Rails::Group

Public Instance Methods

as_json(_options = {}) click to toggle source
# File lib/uploadcare/rails/objects/group.rb, line 56
def as_json(_options = {})
  marshal_dump
end
cache_data() click to toggle source
# File lib/uploadcare/rails/objects/group.rb, line 34
def cache_data
  return unless UPLOADCARE_SETTINGS.cache_groups
  ::Rails.cache.write(cdn_url, marshal_dump)
  self
end
load()
Alias for: load_data
load!()
Alias for: load_data!
load_data() click to toggle source
# File lib/uploadcare/rails/objects/group.rb, line 19
def load_data
  load_data! unless is_loaded?
  self
end
Also aliased as: load
load_data!() click to toggle source
# File lib/uploadcare/rails/objects/group.rb, line 26
def load_data!
  set_data(@api.get("/groups/#{ uuid }/"))
  cache_data
  self
end
Also aliased as: load!
marshal_dump() click to toggle source
# File lib/uploadcare/rails/objects/group.rb, line 40
def marshal_dump
  table = @table.deep_dup.stringify_keys!

  if table['files']
    table['files'].map! do |file|
      file.marshal_dump.stringify_keys
    end
  end

  table
end
to_json() click to toggle source
# File lib/uploadcare/rails/objects/group.rb, line 52
def to_json
  marshal_dump
end
to_s() click to toggle source

override default to string method for group we just will return the uuid

# File lib/uploadcare/rails/objects/group.rb, line 62
def to_s
  uuid
end
urls(operations = nil) click to toggle source

warkaround to build images urls without API request builds array of image urls including operations

# File lib/uploadcare/rails/objects/group.rb, line 7
def urls(operations = nil)
  (0..files_count.to_i - 1).to_a.map do |i|
    [
      @api.options[:static_url_base],
      uuid,
      'nth',
      i,
      Operations.new(operations).to_s
    ].join('/')
  end
end

Private Instance Methods

map_files(data) click to toggle source
# File lib/uploadcare/rails/objects/group.rb, line 68
def map_files(data)
  data.stringify_keys!
  data['files'].map! do |file|
    if file.nil?
      file
    else
      Uploadcare::Rails::File.new(@api, file['uuid'], file)
    end
  end

  data
end