Skip to content

Instantly share code, notes, and snippets.

@duykhoa
Created January 18, 2018 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duykhoa/80513f54d69bdfe85b5c1be11b3e2655 to your computer and use it in GitHub Desktop.
Save duykhoa/80513f54d69bdfe85b5c1be11b3e2655 to your computer and use it in GitHub Desktop.
test
class ImportParticipant
def initialize(source:, :target)
@source = source
@target = target
end
attr_reader :source, :target
def call
data = @source.read_and_parse
@target.bulk_create(data)
end
end
# Implement a Source class
class XlsSource
def initialize(file_reader)
@file_reader = file_reader
end
attr_reader :file_reader
def read_and_parse
data = file_reader.read
parse(data)
end
def parse(data)
end
end
class XlsReader
def initialize(file)
@file = file
end
def read
# call Roo
end
end
class CreateParticipant
def bulk_create(data)
end
end
@duykhoa
Copy link
Author

duykhoa commented Jan 18, 2018

 def call
    data = @source.read_and_parse
    @target.bulk_create(data) if valid?(data)
 end

def valid?(data)
  validators.each { |validator| validator.validate?(data) }
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment