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.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/simplefeed/providers/proxy.rb', line 19

def initialize(provider_or_klass, *args, **options)
  self.provider = if provider_or_klass.is_a?(::String) || provider_or_klass.is_a?(::Symbol)
                    ::Object.const_get(provider_or_klass).new(*args, **options)
                  else
                    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



33
34
35
36
37
38
39
# File 'lib/simplefeed/providers/proxy.rb', line 33

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

Instance Attribute Details

#providerObject

Returns the value of attribute provider.



8
9
10
# File 'lib/simplefeed/providers/proxy.rb', line 8

def provider
  @provider
end

Class Method Details

.from(definition) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/simplefeed/providers/proxy.rb', line 10

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