Module: ConcernsOnRails::Publishable

Extended by:
ActiveSupport::Concern
Defined in:
lib/concerns_on_rails/publishable.rb

Instance Method Summary collapse

Instance Method Details

#publish!Object

Instance methods Publish the record Example:

record.publish!


30
31
32
# File 'lib/concerns_on_rails/publishable.rb', line 30

def publish!
  update(self.class.publishable_field => Time.zone.now)
end

#published?Boolean

Check if the record is published Example:

record.published?

Returns:

  • (Boolean)


44
45
46
47
48
# File 'lib/concerns_on_rails/publishable.rb', line 44

def published?
  value = self[self.class.publishable_field]
  return false unless value.present?
  value.respond_to?(:<=) ? value <= Time.zone.now : true
end

#unpublish!Object

Unpublish the record Example:

record.unpublish!


37
38
39
# File 'lib/concerns_on_rails/publishable.rb', line 37

def unpublish!
  update(self.class.publishable_field => nil)
end

#unpublished?Boolean

Check if the record is unpublished Example:

record.unpublished?

Returns:

  • (Boolean)


53
54
55
# File 'lib/concerns_on_rails/publishable.rb', line 53

def unpublished?
  !published?
end