Class: Avatar::Source::Wrapper::AbstractSourceWrapper

Inherits:
Object
  • Object
show all
Includes:
AbstractSource
Defined in:
lib/avatar/source/wrapper/abstract_source_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(underlying_source) ⇒ AbstractSourceWrapper

Create a new Wrapper

Raises:

  • (ArgumentError)


12
13
14
15
# File 'lib/avatar/source/wrapper/abstract_source_wrapper.rb', line 12

def initialize(underlying_source)
  raise ArgumentError.new("underlying_source must be Source") unless underlying_source.kind_of?(Avatar::Source::AbstractSource)
  @underlying_source = underlying_source
end

Instance Attribute Details

#underlying_sourceObject (readonly)

Returns the value of attribute underlying_source.



9
10
11
# File 'lib/avatar/source/wrapper/abstract_source_wrapper.rb', line 9

def underlying_source
  @underlying_source
end

Instance Method Details

#avatar_url_for(person, options = {}) ⇒ Object

Return nil if the underlying_source does; otherwise, calls wrap, passing the returned URL and the person and options passed.



19
20
21
22
# File 'lib/avatar/source/wrapper/abstract_source_wrapper.rb', line 19

def avatar_url_for(person, options = {})
  url = @underlying_source.avatar_url_for(person, options)
  url.nil? ? nil : wrap(url, person, options)
end

#wrap(url, person, options) ⇒ Object

Apply appropriate wrapping of the url returned by underlying_source. Will never be called with a nil url.



26
27
28
# File 'lib/avatar/source/wrapper/abstract_source_wrapper.rb', line 26

def wrap(url, person, options)
  raise NotImplementedError('subclasses must override wrap(url, person, options)')
end