File: link_follower.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 (25 lines) | stat: -rw-r--r-- 497 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
# frozen_string_literal: true

module GH
  class LinkFollower < Wrapper
    wraps GH::Normalizer
    double_dispatch

    def modify_hash(hash)
      hash = super(hash)
      setup_lazy_loading(hash) if hash['_links']
      hash
    rescue StandardError => e
      raise Error.new(e, hash)
    end

    private

    def lazy_load(hash, key)
      link = hash['_links'][key]
      { key => self[link['href']] } if link
    rescue StandardError => e
      raise Error.new(e, hash)
    end
  end
end