Skip to content

Instantly share code, notes, and snippets.

View ignacio-chiazzo's full-sized avatar
👋
wave

Ignacio Chiazzo Cardarello ignacio-chiazzo

👋
wave
View GitHub Profile
class B < Minitest::Test
test "test 1" do
#.... # runs twice
end
class A < B
test "test 2" do
#....
end
end
module Middleware
class BasicMiddleware
def initialize(app)
@app = app
end
def call(env)
# Before the app is called.
status, headers, response = @app.call(env)
# After the app is called.
@ignacio-chiazzo
ignacio-chiazzo / measure_logs.rb
Created October 4, 2021 01:05
measure_logs.rb
module Middleware
class MeasureLogs
def initialize(app)
@app = app
end
def call(env)
start_time = Time.now
status, headers, response = @app.call(env)
end_time = Time.now
require 'securerandom'
module Middleware
class LogRequestId
REQUEST_ID = "X-Request-Id"
def initialize(app)
@app = app
end
# ----------------------------- Gem -----------------------------
module PricingEngine
module PricingRepositoryInterface
extend T::Sig
extend T::Helpers
interface!
sig { abstract.params(ids: T::Array[Integer]).returns(T::Array[Schema::Variant]) }
def variants_by_ids(ids);end
# ----------------------------- Gem -----------------------------
module PricingEngine
class PricingRepositoryInterface
def variants_by_ids(ids)
raise NotImplemented
end
def variants_by_titles(titles)
raise NotImplemented
end
module PricingEngine
class Engine
# @param repository [PricingEngine::PricingRepositoryInterface] environment specific functions to
# access db and cache data.
#
# @return [void]
def initialize(repository)
@repository = repository
end
# Consumer 2 Logic
require 'pricing_engine'
module StorefrontRenderer
class PricingRepository < PricingEngine::PricingRepositoryInterface
def variants_by_ids(ids)
variants = DataStoreConnection.execute("SELECT title, price FROM variants WHERE id in (?)", ids).limit(50)
variants.map { |variant| PricingEngine::Schema::Variant.new(title: variant.title, price: variant.price) }
# Consumer 1 Logic
require 'pricing_engine'
module ShopifyCore
class PricingRepository < PricingEngine::PricingRepositoryInterface
def variants_by_ids(ids)
variants = ProductVariant.where(id: ids).select(:title, :price).limit(50)
variants.map { |variant| PricingEngine::Schema::Variant.new(title: variant.title, price: variant.price) }
end
module PricingEngine
class PricingRepositoryInterface
def variants_by_ids(ids)
raise NotImplemented
end
def variants_by_titles(titles)
raise NotImplemented
end
end