Last active
March 9, 2020 20:17
-
-
Save tuwukee/b3424afff2218d3056edac1c18ab4057 to your computer and use it in GitHub Desktop.
Sample strategy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Template | |
class JsonInputStrategy < Template::InputStrategy | |
def parse_request_input | |
begin | |
JSON.parse(request_input) | |
rescue JSON::ParserError | |
{} | |
end | |
end | |
end | |
end | |
class InputProcessor | |
include ActiveModel::Model | |
attr_accessor :request_input, :input_type | |
def processor | |
@processor ||= case input_type | |
when Template::INPUT_TYPES[:csv] | |
Template::CsvInputStrategy.new(request_input: request_input) | |
when Template::INPUT_TYPES[:xml] | |
Template::XmlInputStrategy.new(request_input: request_input) | |
else | |
Template::JsonInputStrategy.new(request_input: request_input) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment