Module: ActsAsPublished::ActiveRecord::InstanceMethods

Defined in:
lib/acts_as_published/active_record.rb

Instance Method Summary collapse

Instance Method Details

#publishObject



54
55
56
# File 'lib/acts_as_published/active_record.rb', line 54

def publish
  self.published = true
end

#publishedObject Also known as: published?



27
28
29
# File 'lib/acts_as_published/active_record.rb', line 27

def published
  !!self.published_at
end

#published=(published) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/acts_as_published/active_record.rb', line 32

def published=(published)
  if Rails.version < '4.2'
    boolean_published = ::ActiveRecord::ConnectionAdapters::Column.value_to_boolean(published)
  else
    boolean_published = ::ActiveRecord::Type::Boolean.new.type_cast_from_user(published)
  end
  self.published_at = boolean_published ? Time.zone.now : nil
end

#toggle_publishedObject



41
42
43
44
45
46
47
# File 'lib/acts_as_published/active_record.rb', line 41

def toggle_published
  if self.published_at.nil?
    self.published_at = Time.zone.now
  else
    self.published_at = nil
  end
end

#toggle_published!Object



49
50
51
52
# File 'lib/acts_as_published/active_record.rb', line 49

def toggle_published!
  toggle_published
  save!
end

#unpublishObject



58
59
60
# File 'lib/acts_as_published/active_record.rb', line 58

def unpublish
  self.published = false
end