Class: GH::Wrapper

Inherits:
Object
  • Object
show all
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, LazyLoader, LinkFollower, Normalizer, Remote

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend = nil, options = {}) ⇒ Wrapper

Public: Initialize a new Wrapper.

backend - layer to be wrapped options - config options



56
57
58
59
# File 'lib/gh/wrapper.rb', line 56

def initialize(backend = nil, options = {})
  setup(*normalize_options(backend, options))
  options.each_pair { |key, value| public_send("#{key}=", value) if respond_to? "#{key}=" }
end

Instance Attribute Details

#backendObject

Public: Get wrapped layer.



28
29
30
# File 'lib/gh/wrapper.rb', line 28

def backend
  @backend
end

Class Method Details

.[](key) ⇒ Object

Public: Retrieves resources from Github.



34
35
36
# File 'lib/gh/wrapper.rb', line 34

def self.[](key)
  new[key]
end

.wraps(klass = nil) ⇒ Object

Internal: Get/set default layer to wrap when creating a new instance.



47
48
49
50
# File 'lib/gh/wrapper.rb', line 47

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.



42
43
44
# File 'lib/gh/wrapper.rb', line 42

def [](key)
  modify backend[key]
end

#frontendObject

Internal: …



74
75
76
# File 'lib/gh/wrapper.rb', line 74

def frontend
  @frontend ? @frontend.frontend : self
end

#frontend=(value) ⇒ Object

Internal: …



69
70
71
# File 'lib/gh/wrapper.rb', line 69

def frontend=(value)
  @frontend = value
end

#inspectObject

Public: …



79
80
81
# File 'lib/gh/wrapper.rb', line 79

def inspect
  "#<#{self.class}: #{backend.inspect}>"
end

#load(data) ⇒ Object

Public: …



94
95
96
# File 'lib/gh/wrapper.rb', line 94

def load(data)
  modify backend.load(data)
end

#prefixed(key) ⇒ Object

Internal: …



84
85
86
# File 'lib/gh/wrapper.rb', line 84

def prefixed(key)
  prefix + "#" + identifier(key)
end

#resetObject

Public: …



89
90
91
# File 'lib/gh/wrapper.rb', line 89

def reset
  backend.reset if backend
end