Class: Refinery::Jobs::Job
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Refinery::Jobs::Job
- Extended by:
- FriendlyId
- Defined in:
- app/models/refinery/jobs/job.rb
Class Method Summary collapse
- .latest(number = 5) ⇒ Object
- .published_before(date = DateTime.now) ⇒ Object (also: live)
-
.with_globalize(conditions = {}) ⇒ Object
Wrap up the logic of finding the pages based on the translations table.
Instance Method Summary collapse
- #friendly_id_source ⇒ Object
- #live? ⇒ Boolean
-
#should_generate_new_friendly_id? ⇒ Boolean
If title changes tell friendly_id to regenerate slug when saving record.
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_source ⇒ Object
33 34 35 |
# File 'app/models/refinery/jobs/job.rb', line 33 def friendly_id_source title end |
#live? ⇒ 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
29 30 31 |
# File 'app/models/refinery/jobs/job.rb', line 29 def should_generate_new_friendly_id? title_changed? end |