Class: GH::Wrapper
- Inherits:
-
Object
- Object
- GH::Wrapper
- Extended by:
- Forwardable
- Includes:
- Case
- Defined in:
- lib/gh/wrapper.rb
Overview
Public: Simple base class for low level layers. Handy if you want to manipulate resources coming in from Github.
Examples
class IndifferentAccess
def [](key) super.tap { |r| r.data.with_indifferent_access! } end
end
gh = IndifferentAccess.new
gh['users/rkh'][:name] # => "Konstantin Haase"
# easy to use in the low level stack
gh = Github.build do
use GH::Cache
use IndifferentAccess
use GH::Normalizer
end
Direct Known Subclasses
Cache, CustomLimit, Instrumentation, LazyLoader, LinkFollower, MergeCommit, NestedResources, Normalizer, Pagination, Parallel, Remote, TokenCheck
Instance Attribute Summary collapse
-
#backend ⇒ Object
Public: Get wrapped layer.
-
#frontend ⇒ Object
Internal: …
-
#options ⇒ Object
readonly
Public: …
Class Method Summary collapse
-
.[](key) ⇒ Object
Public: Retrieves resources from Github.
- .double_dispatch ⇒ Object
-
.wraps(klass = nil) ⇒ Object
Internal: Get/set default layer to wrap when creating a new instance.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Public: Retrieves resources from Github.
-
#generate_response(key, resource) ⇒ Object
Internal: …
-
#initialize(backend = nil, options = {}) ⇒ Wrapper
constructor
Public: Initialize a new Wrapper.
-
#inspect ⇒ Object
Public: …
-
#load(data) ⇒ Object
Public: …
-
#prefixed(key) ⇒ Object
Internal: …
-
#reset ⇒ Object
Public: …
Constructor Details
#initialize(backend = nil, options = {}) ⇒ Wrapper
Public: Initialize a new Wrapper.
backend - layer to be wrapped options - config options
106 107 108 109 110 |
# File 'lib/gh/wrapper.rb', line 106 def initialize(backend = nil, = {}) backend, @options = (backend, ) @options.each_pair { |key, value| public_send("#{key}=", value) if respond_to? "#{key}=" } setup(backend, @options) end |
Instance Attribute Details
#backend ⇒ Object
Public: Get wrapped layer.
30 31 32 |
# File 'lib/gh/wrapper.rb', line 30 def backend @backend end |
#frontend ⇒ Object
Internal: …
123 124 125 |
# File 'lib/gh/wrapper.rb', line 123 def frontend @frontend ? @frontend.frontend : self end |
#options ⇒ Object (readonly)
Public: …
33 34 35 |
# File 'lib/gh/wrapper.rb', line 33 def @options end |
Class Method Details
.[](key) ⇒ Object
Public: Retrieves resources from Github.
79 80 81 |
# File 'lib/gh/wrapper.rb', line 79 def self.[](key) new[key] end |
.double_dispatch ⇒ Object
74 75 76 |
# File 'lib/gh/wrapper.rb', line 74 def self.double_dispatch define_method(:modify) { |data| double_dispatch(data) } end |
.wraps(klass = nil) ⇒ Object
Internal: Get/set default layer to wrap when creating a new instance.
97 98 99 100 |
# File 'lib/gh/wrapper.rb', line 97 def self.wraps(klass = nil) @wraps = klass if klass @wraps ||= Remote end |
Instance Method Details
#[](key) ⇒ Object
Public: Retrieves resources from Github.
By default, this method is delegated to the next layer on the stack and modify is called.
87 88 89 |
# File 'lib/gh/wrapper.rb', line 87 def [](key) generate_response key, fetch_resource(key) end |
#generate_response(key, resource) ⇒ Object
Internal: …
92 93 94 |
# File 'lib/gh/wrapper.rb', line 92 def generate_response(key, resource) modify backend.generate_response(key, resource) end |
#inspect ⇒ Object
Public: …
128 129 130 |
# File 'lib/gh/wrapper.rb', line 128 def inspect "#<#{self.class}: #{backend.inspect}>" end |
#load(data) ⇒ Object
Public: …
143 144 145 |
# File 'lib/gh/wrapper.rb', line 143 def load(data) modify backend.load(data) end |
#prefixed(key) ⇒ Object
Internal: …
133 134 135 |
# File 'lib/gh/wrapper.rb', line 133 def prefixed(key) "#{prefix}##{identifier(key)}" end |
#reset ⇒ Object
Public: …
138 139 140 |
# File 'lib/gh/wrapper.rb', line 138 def reset backend&.reset end |