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 OneConnectionBeforeConfirm | |
extend ActiveSupport::Concern | |
included do | |
before_create :generate_confirmation_token | |
after_create :send_on_create_confirmation_instructions | |
end | |
# This actions are not properly trigerred because of the rest of our modifications. | |
before_create :generate_confirmation_token |
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 Concerns | |
module CreatedAtScopes | |
extend ActiveSupport::Concern | |
included do | |
%w(created_at updated_at).each do |prop| | |
verb = prop.gsub('_at', '') | |
scope "#{verb}_last_h", lambda { where("#{prop} >= ?", (Time.now-1.hour).to_s(:db)) } | |
scope "#{verb}_last_6h", lambda { where("#{prop} >= ?", (Time.now-6.hour).to_s(:db)) } |
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 ActiveRecord | |
module PgJsonStore | |
extend ActiveSupport::Concern | |
module ClassMethods | |
# | |
# Store (JSON) using Postgres | |
# JSON data type. | |
# |
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 SamyRoad | |
module FeedsEntryStatus | |
extend ActiveSupport::Concern | |
STATES = { | |
ignored: 1, | |
pending: 0, | |
published: 2, | |
erased: 3 | |
} |
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 States | |
extend ActiveSupport::Concern | |
included do | |
state_machine :status, :initial => :new do | |
event :confirm do | |
transition :new => :confirmed #, :if => lambda {|order| order.email.present?} | |
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/models/item.rb | |
class Item < ActiveRecord::Base | |
include ItemSearch | |
... | |
end | |
# /app/models/concerns/item_search.rb | |
module ItemSearch | |
extend ActiveSupport::Concern |
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 RenderError | |
extend ActiveSupport::Concern | |
included do | |
rescue_from HTTPError do |e| | |
render_error e.status_code, e.message | |
end | |
end | |
class HTTPError < StandardError |
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 'active_support/concern' | |
module ActiveModel | |
module DatetimeAttributes | |
extend ActiveSupport::Concern | |
included do | |
def self.attr_datetime(datetime_attribute, options = {}) | |
time_attr = options[:time_attr] || :"#{datetime_attribute}_time" | |
date_attr = options[:date_attr] || :"#{datetime_attribute}_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
# app/models/item.rb | |
require 'concerns/sortable' | |
class Item < ActiveRecord::Base | |
include Sortable | |
attr_accessible :title | |
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/models/concerns/followable.rb | |
module Followable | |
extend ActiveSupport::Concern | |
included do | |
has_many :reverse_relationships, :class_name => 'Relationship', | |
:as => :following, | |
:dependent => :destroy | |
has_many :followers, :through => :reverse_relationships, |