Class: Feedx::Producer
- Inherits:
-
Object
- Object
- Feedx::Producer
- Defined in:
- lib/feedx/producer.rb
Overview
Produces a relation as an encoded feed to a remote location.
Class Method Summary collapse
-
.perform(url, **opts, &block) ⇒ Object
See constructor.
Instance Method Summary collapse
-
#initialize(url, last_modified: nil, format_options: {}, enum: nil, **opts) { ... } ⇒ Producer
constructor
A new instance of Producer.
- #perform ⇒ Object
Constructor Details
#initialize(url, last_modified: nil, format_options: {}, enum: nil, **opts) { ... } ⇒ Producer
Returns a new instance of Producer.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/feedx/producer.rb', line 21 def initialize(url, last_modified: nil, format_options: {}, enum: nil, **opts, &block) @enum = enum || block raise ArgumentError, "#{self.class.name}.new expects an :enum option or a block factory" unless @enum @url = url @opts = opts.merge() @last_mod = last_modified return if .empty? || (defined?(Gem::Deprecate) && Gem::Deprecate.skip) warn "WARNING: passing format_options is deprecated; pass the options inline instead (called from #{caller(2..2).first})." end |
Class Method Details
.perform(url, **opts, &block) ⇒ Object
See constructor.
9 10 11 |
# File 'lib/feedx/producer.rb', line 9 def self.perform(url, **opts, &block) new(url, **opts, &block).perform end |
Instance Method Details
#perform ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/feedx/producer.rb', line 34 def perform Feedx::Stream.open(@url, **@opts) do |stream| enum = @enum.is_a?(Proc) ? @enum.call : @enum last_mod = @last_mod.is_a?(Proc) ? @last_mod.call(enum) : @last_mod local_rev = last_mod.is_a?(Integer) ? last_mod : (last_mod.to_f * 1000).floor begin = stream.blob.info. remote_rev = ([META_LAST_MODIFIED] || [META_LAST_MODIFIED_DC]).to_i return -1 unless local_rev > remote_rev rescue BFS::FileNotFound nil end if local_rev.positive? stream.create metadata: { META_LAST_MODIFIED => local_rev.to_s } do |fmt| iter = enum.respond_to?(:find_each) ? :find_each : :each enum.send(iter) {|rec| fmt.encode(rec, **@opts) } end stream.blob.info.size end end |