Class: SimpleFeed::Providers::Base::Provider

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

Direct Known Subclasses

Hash::Provider, Redis::Provider

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#feedObject

Returns the value of attribute feed


13
14
15
# File 'lib/simplefeed/providers/base/provider.rb', line 13

def feed
  @feed
end

Class Method Details

.class_to_registry(klass) ⇒ Object


15
16
17
# File 'lib/simplefeed/providers/base/provider.rb', line 15

def self.class_to_registry(klass)
  klass.name.split('::').delete_if { |n| %w(SimpleFeed Providers Provider).include?(n) }.compact.last.downcase.to_sym
end

Instance Method Details

#batch(user_ids) ⇒ Object (protected)


56
57
58
59
60
61
62
# File 'lib/simplefeed/providers/base/provider.rb', line 56

def batch(user_ids)
  to_array(user_ids).each_slice(batch_size) do |batch|
    batch.each do |user_id|
      yield(key(user_id))
    end
  end
end

#batch_sizeObject (protected)


44
45
46
# File 'lib/simplefeed/providers/base/provider.rb', line 44

def batch_size
  feed.batch_size
end

#key(user_id) ⇒ Object (protected)


36
37
38
# File 'lib/simplefeed/providers/base/provider.rb', line 36

def key(user_id)
  feed.key(user_id)
end

#tap(value) ⇒ Object (protected)


31
32
33
34
# File 'lib/simplefeed/providers/base/provider.rb', line 31

def tap(value)
  yield
  value
end

#to_array(user_ids) ⇒ Object (protected)


40
41
42
# File 'lib/simplefeed/providers/base/provider.rb', line 40

def to_array(user_ids)
  user_ids.is_a?(Array) ? user_ids : [user_ids]
end

#with_response(response = nil) {|response| ... } ⇒ Object (protected)

Yields:

  • (response)

64
65
66
67
68
69
70
71
72
73
74
# File 'lib/simplefeed/providers/base/provider.rb', line 64

def with_response(response = nil)
  response ||= SimpleFeed::Response.new
  yield(response)
  if self.respond_to?(:transform_response)
    response.transform do |user_id, result|
      # calling into a subclass
      transform_response(user_id, result)
    end
  end
  response
end

#with_response_batched(user_ids, external_response = nil) ⇒ Object (protected)


48
49
50
51
52
53
54
# File 'lib/simplefeed/providers/base/provider.rb', line 48

def with_response_batched(user_ids, external_response = nil)
  with_response(external_response) do |response|
    batch(user_ids) do |key|
      response.for(key.user_id) { yield(key, response) }
    end
  end
end

#with_resultObject (protected)


76
77
78
79
80
# File 'lib/simplefeed/providers/base/provider.rb', line 76

def with_result
  result = yield
  result = transform_response(nil, result) if self.respond_to?(:transform_response)
  result
end