Sha256: 4dcbd3baa394b1f7dab52c3227b25b30ae1c3c00be139867f656bf83b2ce0e84
Contents?: true
Size: 1.07 KB
Versions: 3
Compression:
Stored size: 1.07 KB
Contents
module KirguduBase module Concerns::Models::CreatedAt extend ActiveSupport::Concern included do before_query :query_add_created_at base.scope :with_created_at_me, lambda { |value| base.where { created_at >= value } if value } base.scope :with_created_at_le, lambda { |value| base.where { created_at <= value } if value } base.scope :with_created_at_m, lambda { |value| base.where { created_at > value } if value } base.scope :with_created_at_l, lambda { |value| base.where { created_at < value } if value } end def created_at_formatted #time_ago_in_words() time_distance_in_words = distance_of_time_in_words(self.created_at, DateTime.now.utc, true) time_dt_format = self.created_at.strftime("%d.%m.%Y %H:%M") #"#{time_distance_in_words} (#{time_dt_format})" end module ClassMethods def query_add_created_at(query, filters) query .with_created_at_me(filters[:created_at_me]) .with_created_at_le(filters[:created_at_le]) .with_created_at_m(filters[:created_at_m]) .with_created_at_l(filters[:created_at_l]) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems