Skip to content
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

Merged
merged 2 commits into from
Nov 22, 2018
Merged

Pusher factories #2

merged 2 commits into from
Nov 22, 2018

Conversation

dim
Copy link
Member

@dim dim commented Nov 22, 2018

Fixes #1

@dim dim merged commit 99c2243 into master Nov 22, 2018
Copy link
Contributor

@mxmCherry mxmCherry left a 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)
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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).

@dim dim deleted the feature/pusher-factories branch June 12, 2019 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants