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
# = AggregateField | |
# | |
# This module allows to create a virtual field from multiple fields | |
# | |
# Example: | |
# | |
# class DummyClass | |
# include AggregateField | |
# | |
# attr_accessor :first_name, :last_name |
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 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 |
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 SMSNotification < Notification | |
def send | |
# sends a sms notification | |
end | |
end | |
class EmailNotification < Notification | |
def send | |
# sends an email with the notification | |
end |
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
# 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 |
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 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 |
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
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 |
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
# 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 |
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
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' |
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
require 'fileutils' | |
require 'logger' | |
require 'erb' | |
# Pdf generation service based on wkhtmltopdf. | |
class PdfGenerator | |
class WkhtmltopdfError < RuntimeError; end | |
DPI = 96 # Pixels in inch |
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
# 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 |