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
# frozen_string_literal: true | |
module Storage | |
class RemoteFileRenamer < ApplicationService | |
attr_reader :file_blob, :new_name, :file | |
# @param file [ActiveStorage::File] | |
# @param new_name [String] | |
# @param variation [Symbol] Sample: :thumbnail | |
def initialize(file, new_name, variation = nil) |
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
class CommentsController < ApplicationController | |
def users_comments | |
# SOLUTION 1: a bit complicated to add pagination and its sql performance is bad when there is a lot of comments, | |
# because the sql query is returning all matched comments | |
@user_comments = Post.all.includes(:comments).eager_load(comments: :author) | |
.where(author: {username: params[:username]}).map(&:comments) | |
.flatten | |
# SOLUTION 2: easy to add pagination and its sql performance is much better | |
@user_comments = Comment.joins(:post, :author).where(author: {username: params[:username]}) |
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
# Enable sidekiq auto quit feature (Allows to enable/disable this feature) | |
# ENV['SIDEKIQ_QUIT_WHEN_EMPTY'] = true/false | |
# Apply manager patch | |
require_relative '../lib/sidekiq_manager_patch' | |
require 'sidekiq/manager' | |
Sidekiq::Manager.send :prepend, SidekiqManagerPatch | |
# Add auto quit middleware | |
require_relative '../lib/sidekiq_quit_when_empty' |
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
# config/initializers/activestorage.rb | |
# Ability to auto apply :default variant (if defined) before uploading original image | |
Rails.application.config.after_initialize do | |
ActiveStorage::Blob.class_eval do | |
alias_method :upload_without_unfurling_orig, :upload_without_unfurling | |
def upload_without_unfurling(io) | |
variant = attachments.first.send(:variants) | |
default_variant = variant[:default] |
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
class DelayedUploaderJob < ApplicationJob | |
queue_as :default | |
attr_reader :model, :attr_name | |
def perform(model_klass, id, attr_name) | |
@model = model_klass.constantize.find(id) | |
@attr_name = attr_name | |
upload_photo if tmp_file_data | |
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
# == Schema Information | |
# | |
# Table name: photos | |
# | |
# id :integer not null, primary key | |
# position :integer | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
class Photo < ApplicationRecord |
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
#!/usr/bin/env node | |
const fs = require('fs'); | |
const path = require('path'); | |
const esbuild = require('esbuild') | |
// Scan entrypoints | |
function scanFiles(dir, options = {}, result = []) { | |
let { recursive = false, ext = null } = options; | |
fs.readdirSync(dir).forEach(file => { |
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 Themes::PerspectiveTheme::MainHelper | |
def self.included(klass) | |
klass.helper_method [:perspective_social_networks] rescue "" # here your methods accessible from views | |
end | |
def perspective_theme_settings(theme) | |
# callback to save custom values of fields added in my_theme/views/admin/settings.html.erb | |
end | |
# callback called after theme installed |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | |
<meta name="description" content="Html5 encode using bootstrap, Lesscss"/> | |
<meta name="keywords" content="Bootstrap, Lesscss, HTML5, CSS3, Crossbrowser"/> | |
<meta name="author" content="Owen Peredo Diaz"/> | |
<meta charset="utf-8"/> | |
<link rel="icon" href="img/favicon.ico" /> | |
<title>Cruceros</title> |
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
#// .github/actions/ruby.yml => Google actions | |
# Note: Includes error silence to avoid invalid "exit 0" when opening cypress service (cypress bug) | |
- name: E2e tests | |
run: docker-compose run test_content_service bash -c "CI=true foreman start -f Procfile-test-e2e 2> /dev/null" | |
if: ${{env.FRONTEND_CHANGED}} | |
#// Procfile-e2e ==> Start all required services (rails, react app and then init cypress awaiting for react port) | |
test_api_server: rm -f tmp/pids/server-test.pid; bundle exec rails s -e test -p 3031 -b '0.0.0.0' --pid tmp/pids/server-test.pid | |
frontend: cd frontend/ && PORT=3030 BROWSER=none RAILS_PORT=3031 yarn start test --silent |
NewerOlder