Skip to content

Instantly share code, notes, and snippets.

View kivanio's full-sized avatar
🏠
Working from home

Kivanio Barbosa kivanio

🏠
Working from home
View GitHub Profile
# = AggregateField
#
# This module allows to create a virtual field from multiple fields
#
# Example:
#
# class DummyClass
# include AggregateField
#
# attr_accessor :first_name, :last_name
@kivanio
kivanio / event.rb
Created June 23, 2014 02:20 — forked from delba/event.rb
class Event < ActiveRecord::Base
attr_reader :start_date, :end_date, :days
has_many :performances
def build_performances
(start_date..end_date).each do |date|
next unless days.include? date.wday
self.performances << Performance.new(date: date)
end
class SMSNotification < Notification
def send
# sends a sms notification
end
end
class EmailNotification < Notification
def send
# sends an email with the notification
end
# app/serializers/customer_serializer_spec.rb
class CustomerSerializer < ActiveModel::Serializer
attributes :customer_number, :email, :username
def customer_number
object.account_number
end
def merchant_id
class ApplicationController < ActionController::Base
# so all actions get some basic logging
# this also makes the :log_metrics_for class macro method available to all controllers
include MetricLoggable
end
module DelayedValidations
extend ActiveSupport::Concern
module ClassMethods
def validation_level(identifier, &block)
with_options if: Proc.new { |a| a.validation_levels.include?(identifier) }, &block
end
end
def validation_levels
# Expirable is a module that lets you easily cache
# groups of records, either across an entire record:
# cache(Snippet) => cache(Snippet.cache_key)
# or, across a scope:
# cache(page.blocks) => cache(page.blocks.cache_key)
#
# Why not just use `maximum(:updated_at)`?
# Because it requires 2 queries: the total count,
# and the updated_at timestamp
require 'sinatra'
require 'oauth2'
require 'json'
require 'logger'
require 'pp'
set :port, 3000
site = ARGV[0] || 'http://paszport.epf.org.pl/'
callback_host = ARGV[1] || 'http://localhost:3000'
require 'fileutils'
require 'logger'
require 'erb'
# Pdf generation service based on wkhtmltopdf.
class PdfGenerator
class WkhtmltopdfError < RuntimeError; end
DPI = 96 # Pixels in inch
# Copy of Paranoia gem without default_scope, which cannot be removed for assotiations
# in Rails 3.0. Refactored to use ActiveSupport::Concern, as it's only one file and don't need
# separate vendor/plugin.
module Paranoia
extend ::ActiveSupport::Concern
included do
scope :deleted, ->{ where.not(deleted_at: nil) }
scope :visible, ->{ where(deleted_at: nil) }
end