Class: SimpleFeed::Providers::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/simplefeed/providers/proxy.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider_or_klass, *args, **options) ⇒ Proxy

Returns a new instance of Proxy.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/simplefeed/providers/proxy.rb', line 16

def initialize(provider_or_klass, *args, **options)
  if provider_or_klass.is_a?(::String)
    self.provider = ::Object.const_get(provider_or_klass).new(*args, **options)
  else
    self.provider = provider_or_klass
  end

  SimpleFeed::Providers::REQUIRED_METHODS.each do |m|
    raise ArgumentError, "Invalid provider #{provider.class}\nMethod '#{m}' is required." unless provider.respond_to?(m)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Forward all other method calls to Provider



29
30
31
32
33
34
35
# File 'lib/simplefeed/providers/proxy.rb', line 29

def method_missing(name, *args, &block)
  if self.provider && provider.respond_to?(name)
    self.provider.send(name, *args, &block)
  else
    super(name, *args, &block)
  end
end

Instance Attribute Details

#providerObject

Returns the value of attribute provider.



4
5
6
# File 'lib/simplefeed/providers/proxy.rb', line 4

def provider
  @provider
end

Class Method Details

.from(definition) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/simplefeed/providers/proxy.rb', line 6

def self.from(definition)
  if definition.is_a?(::Hash)
    ::SimpleFeed.symbolize!(definition)
    self.new(definition[:klass], *definition[:args], **definition[:opts])
  else
    self.new(definition)
  end

end