-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pusher factories #2
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some suggestions to simplify API - what about leaving the only option - block/yield?
@@ -4,13 +4,22 @@ | |||
module Feedx | |||
# Pushes a relation as a protobuf encoded stream to an S3 location. | |||
class Pusher | |||
# @param [Enumerable,ActiveRecord::Relation] relation to stream. | |||
# See constructor. | |||
def self.perform(url, opts={}, &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, doesn't add much value (doesn't save much code)
# @param [String] url the destination URL. | ||
# @param [Hash] opts options | ||
# @option opts [Enumerable,ActiveRecord::Relation] :enum relation or enumerator to stream. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, just another option to know/remember about, but doesn't actually add much value. I think accepting block is more than enough.
enum = @relation.respond_to?(:find_each) ? :find_each : :each | ||
@relation.send(enum) {|rec| stream.write(rec) } | ||
stream = @format.new(io) | ||
relation = @enum.is_a?(Proc) ? @enum.call : @enum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just check @enum.respond_to?(:call)
(really doesn't matter, but would allow not only Proc passed but also some custom class/object with call method; though t makes sense only if :enum
option is going to be kept).
Fixes #1