Class: GH::NestedResources
- Defined in:
- lib/gh/nested_resources.rb
Overview
Public: …
Instance Attribute Summary
Attributes inherited from Wrapper
Instance Method Summary collapse
- #add(hash, link, name, path = name) ⇒ Object
-
#modify_hash(hash, loaded = false) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter.
- #nested(link, path) ⇒ Object
- #set_links(hash, link) ⇒ Object
Methods inherited from Wrapper
#[], [], double_dispatch, #generate_response, #initialize, #inspect, #load, #prefixed, #reset, wraps
Constructor Details
This class inherits a constructor from GH::Wrapper
Instance Method Details
#add(hash, link, name, path = name) ⇒ Object
18 19 20 |
# File 'lib/gh/nested_resources.rb', line 18 def add(hash, link, name, path = name) hash['_links'][name] ||= { 'href' => nested(link, path) } end |
#modify_hash(hash, loaded = false) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter
11 12 13 14 15 16 |
# File 'lib/gh/nested_resources.rb', line 11 def modify_hash(hash, loaded = false) # rubocop:disable Style/OptionalBooleanParameter hash = super(hash) link = hash['_links']['self'] unless loaded || hash['_links'].nil? set_links hash, Addressable::URI.parse(link['href']) if link hash end |
#nested(link, path) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/gh/nested_resources.rb', line 22 def nested(link, path) new_link = link.dup if path.start_with? '/' new_link.path = path else new_link.path += path end new_link end |
#set_links(hash, link) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gh/nested_resources.rb', line 32 def set_links(hash, link) case link.path when '/gists' add hash, link, 'public' add hash, link, 'starred' when %r{^/repos/[^/]+/[^/]+$} add hash, link, 'commits', 'git/commits' add hash, link, 'refs', 'git/refs' add hash, link, 'tags', 'git/tags' add hash, link, 'issues' when %r{^/repos/[^/]+/[^/]+/issues/\d+$} add hash, link, 'comments' add hash, link, 'events' when '/user' add hash, link, 'gists', '/gists' add hash, link, 'issues', '/issues' end end |