Benchmarking two ways of checking if module is defined using its name in string.
begin
'ModuleName'.constantize
rescue NameError
# ignored
end
Object.const_defined?('ModuleName')
# frozen_string_literal: true | |
class CreateSignedCloudfrontUrl < Service | |
attr_reader :url, :expires_at | |
def initialize(url:, expires_in:) | |
@url = url | |
@expires_at = expires_in.from_now.to_i | |
end |
import AWS from 'aws-sdk'; | |
export default class AwsS3MultipartHelper { | |
constructor(options) { | |
this.options = { | |
bucket: options.bucket, | |
acl: options.acl || 'public-read', | |
expires: options.expires || 5 * 60, | |
}; |
module MonkeyPatches | |
# | |
# Monkey patch ActionView::CollectionCaching#cache_collection_render included in ActionView::PartialRenderer. | |
# This helps prevent N+1 for uncached entries when rendering cached collection. | |
# This patch allows us to specify modify_uncached_collection Proc. The Proc is called with collection of uncached entries as argument. Its result should be Array. It is used as new collection for rendering. | |
# | |
# Setup: | |
# | |
# Add this line to monkey_patches.rb initializer. | |
# ActionView::PartialRenderer.prepend(MonkeyPatches::ActionViewPartialRendererCollectionCaching) |
Benchmarking two ways of checking if module is defined using its name in string.
begin
'ModuleName'.constantize
rescue NameError
# ignored
end
Object.const_defined?('ModuleName')