Module: IncludeDateScopes::DateScopes::ClassMethods

Instance Method Summary collapse

Methods included from IncludeDateScopes::DefineCommonScopes

#define_common_scopes

Methods included from IncludeDateScopes::DefineDateScopes

#define_date_scopes_for

Methods included from IncludeDateScopes::DefineTimestampScopes

#define_timestamp_scopes_for

Instance Method Details

#column_type_for(column) ⇒ Object



58
59
60
# File 'lib/include_date_scopes/date_scopes.rb', line 58

def column_type_for(column)
  columns_hash[column.to_s].type
end

#include_date_scopesObject



36
37
38
# File 'lib/include_date_scopes/date_scopes.rb', line 36

def include_date_scopes
  include_date_scopes_for :created_at
end

#include_date_scopes_for(column, prepend_name = false, column_type = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/include_date_scopes/date_scopes.rb', line 40

def include_date_scopes_for(column,
                            prepend_name = false,
                            column_type = nil)
  column_type ||= column_type_for(column)
  return unless self.table_exists?
  if column_type == :datetime
    define_timestamp_scopes_for column, prepend_name
  elsif column_type == :date
    define_date_scopes_for column, prepend_name
  end
rescue
  warn "Not including date scopes for #{column} because of an error: #{$!.message}"
end

#include_named_date_scopes_for(column) ⇒ Object



54
55
56
# File 'lib/include_date_scopes/date_scopes.rb', line 54

def include_named_date_scopes_for(column)
  include_date_scopes_for column, true
end