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
# Usage: | |
# This module adds single scoped sequential id on AR model. | |
# In your model, include this module like: | |
# include SequentialId[:number, scope: :user_id] | |
module SequentialId | |
def self.[](column_name, scope:) | |
options = Struct.new(:column_name, :scope) | |
Module.new do | |
extend ActiveSupport::Concern | |
include SequentialId |
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 Commentable | |
extend ActiveSupport::Concern | |
included do | |
has_many :comments | |
define_model_callbacks :comment_update, only: :after | |
end | |
end | |
class Post |
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 "date" | |
# Days from day one to first saturday are result in index 1 | |
def week_index_in_month(date) | |
first_day_of_month = Date.new(date.year, date.month, 1) | |
((date.day + first_day_of_month.wday) / 7.0).ceil | |
end | |
# Days from day one to seven are result in index 1 | |
def week_index_in_month(date) |
OlderNewer