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 | |
# ... | |
require_relative "../lib/middleware/marcelo" | |
# ... | |
module CoolName | |
class Application < Rails::Application | |
#... | |
# Before anything you get me |
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 | |
# This pattern is often useful in situations where a class cannot anticipate the type of objects it | |
# will need to create, or in situations where a class wants to delegate the responsibility of | |
# creating objects to one of its expert subclasses. | |
# Base class that defines the interface of the object to be created | |
class Car | |
def drive | |
raise NotImplementedError, 'This is an abstract class check one if its subclasses' |
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 | |
# The command pattern is useful in situations where you want to decouple the requester of an action | |
# from the object that performs the action, need to support undo/redo functionality, require | |
# flexibility to dynamically change or extend commands, or aim to encapsulate requests as objects | |
# for easier management and organization in a software system. | |
# This pattern can be split in three main components: The receiver, the invoker and the command |
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 | |
require 'ostruct' | |
# Command "Interface" | |
class Command | |
attr_accessor :errors, :input, :output | |
def initialize(**input) | |
@errors = [] |
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 | |
require 'singleton' | |
class Log | |
include Singleton | |
attr_reader :list | |
def append(text) |
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 | |
# The singleton pattern is used when you need to ensure that only one instance of a class exists | |
# and provide a global point of access to it. | |
# | |
# The most common reason to use this design pattern is to control access to some shared resource, | |
# for example a database or a file. | |
# The second most common reason is to create a global variable whose change is more controlled. | |
class TicketDispenserMachine | |
private_class_method :new |
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
#!/bin/bash | |
chruby 2.7.0 | |
export RUBYOPT=-W:no-deprecated | |
# Install all gem dependencies | |
bundle install | |
# Just to prevent showing many "error" messages | |
dirty_bit=0 |
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 BatchCreate | |
class << self | |
def perform(active_records:, conflict_fields:) | |
return if active_records.empty? | |
ActiveRecord::Base.connection.execute( | |
<<-SQL.squish | |
#{insert_statement(active_records.first)} | |
#{values(active_records)} | |
#{on_conflict_statement(conflict_fields)} |
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 BatchCreate | |
class << self | |
def perform(active_records:, conflict_fields:) | |
return if active_records.empty? | |
ActiveRecord::Base.connection.execute( | |
<<-SQL.squish | |
#{insert_statement(active_records.first)} | |
#{values(active_records)} | |
#{on_conflict_statement(active_records.first, conflict_fields)} |
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
if Rails.env.development? | |
class MarcelosController < ApplicationController | |
def method | |
require 'pry-byebug' ; binding.pry | |
end | |
end | |
get '/marcelos_method/:id', to: 'marcelos#method' | |
end |
NewerOlder