Skip to content

Instantly share code, notes, and snippets.

View jessecurry's full-sized avatar

Jesse Curry jessecurry

View GitHub Profile
@jessecurry
jessecurry / report_builder.rb
Created June 11, 2015 13:57
Example of GlobalID in a custom class
class ReportBuilder
include GlobalID::Identification
def id
report.id
end
def self.find id
new(report_class.find(id))
end
@jessecurry
jessecurry / report_mailer.rb
Created June 11, 2015 14:03
Report Mailer
class ReportMailer < ApplicationMailer
def new_report_email recipient, report_builder
attachments['report.pdf'] = { mime_type: 'application/pdf', content: report_builder.generate_stream }
mail(to: recipient, subject: report_builder.title)
end
end
@jessecurry
jessecurry / email_report_job.rb
Created June 11, 2015 14:06
Job to email reports
class EmailReportJob < ActiveJob::Base
queue_as :mail
def perform recipients, report_builder
recipients.each do |recipient|
ReportMailer.new_report_email(recipient, report_builder).deliver
end
end
end
@jessecurry
jessecurry / base.rb
Last active December 17, 2015 18:55
Wrap JSON data with type-safe methods
module JsonWrapper
class Base
MAPPING_TYPES = {
array: :to_a,
boolean: :to_bool,
date: :to_date,
datetime: :to_datetime,
float: :to_f,
hash: :to_h,
integer: :to_i,
@jessecurry
jessecurry / keyMirror.js
Created May 7, 2019 17:03
keyMirror with namespaces
'use strict';
const keyMirror = (list, namespace) => {
let newList= {};
let prefix = namespace ? namespace + ":" : "";
Object.keys(list).map(element => {
var key = String(element);
newList[key] = prefix + element
});
@jessecurry
jessecurry / .rubocop.yml
Created July 22, 2019 15:24
Rubocop Setup
require:
- rubocop-rails
Rails:
Enabled: true
Metrics/ClassLength:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/LineLength: