Module: Postable::ClassMethods

Defined in:
app/models/postable.rb

Instance Method Summary collapse

Instance Method Details

#chronologicalObject



70
71
72
# File 'app/models/postable.rb', line 70

def chronological
  order "#{quoted_table_name}.posted_at ASC"
end

#postable_nowObject



48
49
50
51
52
53
54
# File 'app/models/postable.rb', line 48

def postable_now
  if postable_type == :date
    Date.today
  else
    Time.now
  end
end

#postable_typeObject



56
57
58
59
60
# File 'app/models/postable.rb', line 56

def postable_type
  type = columns_hash["posted_at"].type
  raise "Postable's posted_at column type should be :date or :datetime!" unless [:date, :datetime].include?(type)
  type
end

#postedObject



62
63
64
# File 'app/models/postable.rb', line 62

def posted
  where "#{quoted_table_name}.posted_at IS NOT NULL AND #{quoted_table_name}.posted_at <= ?", postable_now
end

#reverse_chronologicalObject



74
75
76
# File 'app/models/postable.rb', line 74

def reverse_chronological
  order "#{quoted_table_name}.posted_at DESC"
end

#unpostedObject



66
67
68
# File 'app/models/postable.rb', line 66

def unposted
  where "#{quoted_table_name}.posted_at IS NULL OR #{quoted_table_name}.posted_at > ?", postable_now
end