1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
# frozen_string_literal: true
require 'gh'
module GH
# Public: ...
class LazyLoader < Wrapper
wraps GH::Normalizer
double_dispatch
def modify_hash(hash, loaded = false) # rubocop:disable Style/OptionalBooleanParameter
hash = super(hash)
link = hash['_links']['self'] unless loaded || hash['_links'].nil?
setup_lazy_loading(hash, link['href']) if link
hash
rescue StandardError => e
raise Error.new(e, hash)
end
private
def lazy_load(hash, _key, link)
modify_hash(backend[link].data, true)
rescue StandardError => e
raise Error.new(e, hash)
end
end
end
|