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 User < ActiveRecord::Base | |
| def self.my_where(key, value) | |
| # Normally with 2 arguments, you can easily do: | |
| where(key: value) | |
| end | |
| def self.where_preference(conditions) | |
| # But with a map and several k-v pairs, you'd have to do something like | |
| conditions.inject(self) do |scope, (k, v)| | |
| scope.where(k => v) |
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
| source 'https://rubygems.org' | |
| gem "pry" | |
| gem 'i18n', github: "svenfuchs/i18n", branch: "173-reset-load-path" | |
| gem "rspec" |
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
| defmodule Transaction do | |
| defstruct [:merchant_id, :financial_context_id] | |
| end | |
| defmodule Transactions do | |
| def process do | |
| transactions = [ | |
| %Transaction{merchant_id: "12345", financial_context_id: "1234"}, | |
| %Transaction{merchant_id: "12345", financial_context_id: "1234"}, | |
| %Transaction{merchant_id: "12345", financial_context_id: "1234"}, |
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
| h = { outer: { inner: [1, 2, 3] } } | |
| h[:outer][:inner] = h[:outer][:inner].map(&:to_s) |
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 Advert::UpsertVehicle | |
| def self.call(vehicle) | |
| @vehicle = vehicle | |
| @outdoria = OutdoriaAPIService.new(vehicle.retailer.api_key) | |
| return unless @request_body = VehicleData::ToRequestBody.(vehicle) | |
| @vehicle_code = vehicle.custom_id | |
| if @outdoria.advert_exists?(@vehicle_code) | |
| self.update_advert | |
| else |
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 UserHelpers | |
| def new_user | |
| user = Fabricate(:user) | |
| session[:user_id] = user.id | |
| end | |
| def current_user | |
| User.find(session[:user_id]) | |
| 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
| def create(conn, %{"user" => user_params}) do | |
| changeset = User.registration_changeset(%User{}, user_params) | |
| case Repo.insert(changeset) do | |
| { :ok, user } -> | |
| conn | |
| |> Rumbl.Auth.login(user) | |
| |> put_flash(:info, "#{user.name} created!") | |
| |> redirect(to: user_path(conn, :index)) | |
| { :error, changeset } -> |
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
| board = List.flatten(Enum.map(?a..?j, fn x -> | |
| Enum.map(?0..?9, fn y -> | |
| {String.to_atom(<< x, y >>), nil} | |
| end) | |
| 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
| before_action :configure_permitted_parameters, if: :devise_controller? | |
| protected | |
| def configure_permitted_parameters | |
| devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name,:password,:password_confirmation,:email) } | |
| devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:name,:password,:password_confirmation,:email) } | |
| 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
| module DashboardHelper | |
| def sedex_status(sedex) | |
| if sedex.ts_signature.nil? | |
| if Time.now - sedex.ts_print <= 1.hour | |
| "Cinza" | |
| else | |
| "Vermelho" | |
| end | |
| elsif sedex.ts_print - sedex.ts_signature > 1.hour | |
| "Amarela" |