Class: Refinery::Jobs::Job

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/refinery/jobs/job.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.latest(number = 5) ⇒ Object



23
24
25
# File 'app/models/refinery/jobs/job.rb', line 23

def self.latest(number = 5)
  limit(number).order('created_at DESC')
end

.published_before(date = DateTime.now) ⇒ Object Also known as: live



56
57
58
59
60
# File 'app/models/refinery/jobs/job.rb', line 56

def published_before(date=DateTime.now)
  where(arel_table[:published_at].lt(date))
    .where(draft: false)
    .with_globalize
end

.with_globalize(conditions = {}) ⇒ Object

Wrap up the logic of finding the pages based on the translations table.



43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/refinery/jobs/job.rb', line 43

def with_globalize(conditions = {})
  conditions = {:locale => ::Globalize.locale}.merge(conditions)
  globalized_conditions = {}
  conditions.keys.each do |key|
    if (translated_attribute_names.map(&:to_s) | %w(locale)).include?(key.to_s)
      globalized_conditions["#{self.translation_class.table_name}.#{key}"] = conditions.delete(key)
    end
  end
  # A join implies readonly which we don't really want.
  where(conditions).joins(:translations).where(globalized_conditions)
                   .readonly(false)
end

Instance Method Details

#friendly_id_sourceObject



33
34
35
# File 'app/models/refinery/jobs/job.rb', line 33

def friendly_id_source
  title
end

#live?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/models/refinery/jobs/job.rb', line 37

def live?
  !draft && published_at <= DateTime.now
end

#should_generate_new_friendly_id?Boolean

If title changes tell friendly_id to regenerate slug when saving record

Returns:

  • (Boolean)


29
30
31
# File 'app/models/refinery/jobs/job.rb', line 29

def should_generate_new_friendly_id?
  title_changed?
end