File: lazy_loader.rb

package info (click to toggle)
ruby-gh 0.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,644 kB
  • sloc: ruby: 1,793; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 641 bytes parent folder | download
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