Class: Resync::Augmented

Inherits:
Object
  • Object
show all
Defined in:
lib/resync/client/resync_extensions.rb

Overview

Injects a Client that subclasses can use to fetch resources and links

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#client ⇒ Client

Returns the injected Client. Defaults to a new Client instance.

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/resync/client/resync_extensions.rb', line 17

class Augmented
  attr_writer :client

  def client
    @client ||= Client.new
  end

  alias_method :base_links=, :links=
  private :base_links=

  # Adds a +:client+ method to each link, delegating
  # to {#client}
  def links=(value)
    self.base_links = value
    self.base_links = value
    parent = self
    links.each do |l|
      l.define_singleton_method(:client) do
        parent.client
      end
    end
  end
end

Instance Method Details

#links=(value) ⇒ Object

Adds a :client method to each link, delegating to #client



29
30
31
32
33
34
35
36
37
38
# File 'lib/resync/client/resync_extensions.rb', line 29

def links=(value)
  self.base_links = value
  self.base_links = value
  parent = self
  links.each do |l|
    l.define_singleton_method(:client) do
      parent.client
    end
  end
end