Module: AlmostHappy::Publishable::InstanceMethods

Defined in:
lib/almost_happy/publishable.rb

Instance Method Summary collapse

Instance Method Details

#publish!Object



26
27
28
# File 'lib/almost_happy/publishable.rb', line 26

def publish!
  update_attribute :published_at, Time.now
end

#published=(value) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/almost_happy/publishable.rb', line 7

def published=(value)
  # Sets the attribute, uses the ar conversion method)
  if defined?(ActiveRecord)
    value = ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
  else
    value = value.present? && !["0", "false"].include?(value.to_s)
  end
  if !published_at? && value
    self.published_at = Time.now
  elsif published_at? && !value
    self.published_at = nil
  end
end

#published?Boolean Also known as: published

Returns:

  • (Boolean)


21
22
23
# File 'lib/almost_happy/publishable.rb', line 21

def published?
  published_at.present? && published_at <= Time.now
end