-
-
Save siassaj/b4f0164b68f190e738a5 to your computer and use it in GitHub Desktop.
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
RSpec.describe ApplicationController do | |
it_behaves_like "JsonRepresenterConcern" | |
end |
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 JsonRepresenterConcern | |
extend ActiveSupport::Concern | |
included do | |
private | |
def represent(record) | |
return nil if record.blank? | |
klass_name = record.class.name | |
"#{klass_name}Presenter".constantize.new(record) | |
end | |
def represent_collection(records) | |
return [] if records.empty? | |
klass_name = record.class.name | |
records.map do |record| | |
"#{klass_name}Presenter".constantize.new(record) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment