Module: ConcernsOnRails::Models::Publishable

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

Instance Method Summary collapse

Instance Method Details

#publish!Object

Instance methods Publish the record Example:

record.publish!


32
33
34
# File 'lib/concerns_on_rails/models/publishable.rb', line 32

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

#published?Boolean

Check if the record is published Example:

record.published?

Returns:

  • (Boolean)


46
47
48
49
50
51
# File 'lib/concerns_on_rails/models/publishable.rb', line 46

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!


39
40
41
# File 'lib/concerns_on_rails/models/publishable.rb', line 39

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

#unpublished?Boolean

Check if the record is unpublished Example:

record.unpublished?

Returns:

  • (Boolean)


56
57
58
# File 'lib/concerns_on_rails/models/publishable.rb', line 56

def unpublished?
  !published?
end