Class: ActivePress::Post

Inherits:
Base
  • Object
show all
Defined in:
lib/active_press/models/post.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.by_day(d) ⇒ Object



28
29
30
# File 'lib/active_press/models/post.rb', line 28

def self.by_day(d)
  where(:post_date_gmt => (d.beginning_of_day..d.end_of_day))
end

.by_month(d) ⇒ Object



24
25
26
# File 'lib/active_press/models/post.rb', line 24

def self.by_month(d)
  where(:post_date_gmt => (d.beginning_of_month..d.end_of_month))
end

.by_year(d) ⇒ Object



20
21
22
# File 'lib/active_press/models/post.rb', line 20

def self.by_year(d)
  where(:post_date_gmt => (d.beginning_of_year..d.end_of_year))
end

Instance Method Details

#metaObject



50
51
52
53
54
55
# File 'lib/active_press/models/post.rb', line 50

def meta
  .inject({}) do |hash, |
    hash[.meta_key.to_sym] = .meta_value
    hash
  end
end

#next_postObject



32
33
34
35
36
37
# File 'lib/active_press/models/post.rb', line 32

def next_post
  self.class.published.where(['id != ?', self.id])\
    .where(:post_type => self.post_type)\
    .where(['post_date_gmt >= ?', self.])\
    .order('post_date_gmt ASC').limit(1)
end

#previous_postObject



39
40
41
42
43
44
# File 'lib/active_press/models/post.rb', line 39

def previous_post
  self.class.published.where(['id != ?', self.id])\
    .where(:post_type => self.post_type)\
    .where(['post_date_gmt <= ?', self.])\
    .order('post_date_gmt DESC').limit(1)
end

#to_paramObject



46
47
48
# File 'lib/active_press/models/post.rb', line 46

def to_param
  post_name
end