This file contains hidden or 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
| import { isNonEmptyString, isUuidV4, UuidV4 } from './typeguards'; | |
| export function assertNonEmptyString( | |
| value: unknown, | |
| msgOrExceptionFactory?: string | (() => Error) | Error, | |
| /** auto-trim, default true */ | |
| trim?: boolean | |
| ): asserts value is string { | |
| const autoTrim = trim ?? true; | |
| if (isNonEmptyString(value, autoTrim)) { |
This file contains hidden or 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
| import is from '@sindresorhus/is'; | |
| import { validate as uuidValidate } from 'uuid'; | |
| import { version as uuidVersion } from 'uuid'; | |
| export function assertNever(value: never, msg?: string): never { | |
| throw new Error(isNonEmptyString(msg) ? msg : `Unexpected value: ${value}`); | |
| } | |
| export function isString(value: unknown): value is string { | |
| return typeof value === 'string'; |
This file contains hidden or 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
| myPage(); |
This file contains hidden or 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
| function myPage() { | |
| console.log("My page function"); | |
| } |
This file contains hidden or 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
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>My Page</title> | |
| </head> | |
| <body> | |
| <script type="text/javascript" src="./src/index.js"></script> | |
| <script type="text/javascript" src="./src/my-page.js"></script> | |
| </body> |
This file contains hidden or 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 DuplicateActiveStorage | |
| extend ActiveSupport::Concern | |
| included do | |
| after_commit do | |
| duplicate_active_storage unless @is_migration | |
| end | |
| after_destroy :duplicate_active_storage | |
| end |
This file contains hidden or 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
| namespace :paperclip do | |
| task migrate: :environment do | |
| arr = Array.new | |
| ApplicationRecord.descendants.reject(&:abstract_class?).each { |klass| arr.push(klass) } | |
| while model = arr.pop | |
| begin | |
| attachments = model.column_names.filter { |column| column.match?(/(.+)_file_name$/) }.map { |column| column[/(?<name>\w*)_file_name/, :name] } | |
| next if attachments.blank? |
This file contains hidden or 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
| SELECT blobs.storage_url | |
| FROM active_storage_blobs AS blobs | |
| INNER JOIN active_storage_attachments AS attachments ON attachments.blob_id = blobs.id | |
| WHERE attachments.record_type = 'Model1' | |
| AND attachments.name = 'logo' | |
| LIMIT 10 |
This file contains hidden or 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
| class RemovePaperclipColumnsFromModels < ActiveRecord::Migration[5.2] | |
| def up | |
| remove_column :model, :logo_content_type | |
| remove_column :model, :logo_file_name | |
| remove_column :model, :logo_file_size | |
| remove_column :model, :logo_fingerprint | |
| remove_column :model, :logo_updated_at | |
| end | |
| def down |
This file contains hidden or 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
| class BlobObserver < ActiveRecord::Observer | |
| observe ActiveStorage::Blob | |
| def after_save(blob) | |
| blob.update_columns(storage_url: "https://s3-#{ENV['AWS_AS_S3_REGION']}.amazonaws.com/#{ENV['AWS_AS_S3_BUCKET']}/" + blob.key) | |
| end | |
| end |
NewerOlder