Class: Feedx::Producer
- Inherits:
-
Object
- Object
- Feedx::Producer
- Defined in:
- lib/feedx/producer.rb
Overview
Produces a relation as am encoded stream to a remote location.
Class Method Summary collapse
-
.perform(url, opts = {}, &block) ⇒ Object
See constructor.
Instance Method Summary collapse
-
#initialize(url, opts = {}) { ... } ⇒ Producer
constructor
A new instance of Producer.
- #perform ⇒ Object
Constructor Details
#initialize(url, opts = {}) { ... } ⇒ Producer
Returns a new instance of Producer.
21 22 23 24 25 26 27 28 29 |
# File 'lib/feedx/producer.rb', line 21 def initialize(url, opts={}, &block) @enum = opts[:enum] || block raise ArgumentError, "#{self.class.name}.new expects an :enum option or a block factory" unless @enum @blob = BFS::Blob.new(url) @format = detect_format(opts[:format]) @compress = detect_compress(opts[:compress]) @last_mod = opts[:last_modified] 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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/feedx/producer.rb', line 31 def perform enum = @enum.is_a?(Proc) ? @enum.call : @enum last_mod = @last_mod.is_a?(Proc) ? @last_mod.call(enum) : @last_mod current = (last_mod.to_f * 1000).floor begin previous = @blob.info.[META_LAST_MODIFIED].to_i return -1 unless current > previous rescue BFS::FileNotFound # rubocop:disable Lint/HandleExceptions end if current.positive? @blob.create metadata: { META_LAST_MODIFIED => current.to_s } do |io| @compress.wrap(io) {|w| write_all(enum, w) } end @blob.info.size end |