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/models/address.rb | |
class Address < ActiveRecord::Base | |
belongs_to :addressable, polymorphic: true | |
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 Expirable | |
extend ActiveSupport::Concern | |
included do | |
cattr_accessor :default_lifetime | |
self.default_lifetime = 6.hours | |
scope :valid, where('expires_at >= ?', Time.now) | |
before_validation :set_default_expiration, :on => :create | |
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 VirtualAttributes | |
extend ActiveSupport::Concern | |
class VirtualAttribute | |
attr_reader :name, :type | |
def initilaize(name, type = :string) | |
@name = name | |
@type = type | |
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 Reportable | |
extend ActiveSupport::Concern | |
module ClassMethods | |
# Chain on a scope and specify the fields to extract. | |
# Example: | |
# User.enabled.report %{ | |
# :email_opt_in, | |
# 'created_at as sign_up_date' | |
# } |
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 Ping | |
module Blockable | |
extend ActiveSupport::Concern | |
included do | |
belongs_to :blocker, class_name: 'User' | |
end | |
def blocked? |
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
# using active_support | |
require 'active_support/core_ext' | |
module Mixpanel | |
extend ActiveSupport::Concern | |
# class methods | |
included do | |
mixpanel | |
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
require 'iconv' | |
module ExportableControllerMethods | |
BOM = "\377\376" #Byte Order Mark | |
extend ActiveSupport::Concern | |
protected | |
def export_as_csv(collection, column_names, filename) |
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 ActsAsHistorical | |
extend ActiveSupport::Concern | |
included do | |
end | |
module ClassMethods | |
def acts_as_historical(options = {}) | |
has_many :histories, :as => :historical, :dependent => :destroy | |
include MyInstanceMethods |
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 SidekiqIndexing | |
module SearchableOverride | |
extend ActiveSupport::Concern | |
module InstanceOverrides | |
def solr_index | |
SunspotIndexer.perform_async(self.class.to_s, self.id) | |
end | |
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 Eventable | |
module Emitter | |
extend ActiveSupport::Concern | |
included do | |
def emit(event_name, payload = {}) | |
full_event = "#{self.class.to_s.underscore}:#{event_name}" | |
Eventable.emit full_event, self, payload | |
end | |
end |