Module: AttrPublish

Extended by:
ActiveSupport::Concern
Defined in:
lib/attr_publish/version.rb,
lib/attr_publish/attr_publish.rb

Defined Under Namespace

Modules: Version

Query scopes added to publishable models collapse

Instance methods added to publishable models collapse

Class Method Details

.publishedObject

Query scope added to publishables that can be used to find published records. For Date/DateTime publishables, you can pass a specific date on which the results should be published.

Examples:

Find only records that are currently published

published_posts = Post.published

Find only records that will be published in two days

future_posts = Post.published(Date.current + 2.days)

Parameters:

  • when (Date, Time, nil)

    Specify a date/time for Date/DateTime publishables - defaults to the current date/time



# File 'lib/attr_publish/attr_publish.rb', line 151

.recentObject

Query scope added to publishables that can be used to lookup records which are currently published. The results are returned in descending order based on the published date/time.

Examples:

Get the 10 most recently-published records

recent_posts = Post.recent(10)

Parameters:

  • how_many (Integer, nil)

    Specify how many records to return



# File 'lib/attr_publish/attr_publish.rb', line 169

.unpublishedObject

Query scope added to publishables that can be used find records which are not published. For Date/DateTime publishables, you can pass a specific date on which the results should not have been published.

Examples:

Find only records that are not currently published

unpublished_posts = Post.unpublished

Parameters:

  • when (Date, Time, nil)

    Specify a date/time for Date/DateTime publishables - defaults to the current date/time



# File 'lib/attr_publish/attr_publish.rb', line 161

.upcomingObject

Query scope added to publishables that can be used to lookup records which are not currently published. The results are returned in ascending order based on the published date/time.

Examples:

Get all posts that will be published in the future

upcoming_posts = Post.upcoming

Parameters:

  • how_many (Integer, nil)

    Specify how many records to return



# File 'lib/attr_publish/attr_publish.rb', line 177

Instance Method Details

#publishObject

Publish this object. For a Boolean publish field, the field is set to true; for a Date/DateTime field, the field is set to the given Date/Time or to the current date/time.

Parameters:

  • when (Date, Time, nil)

    For Date/DateTime publishables, a date/time can be passed to specify when the record will be published. Defaults to Date.current or Time.now.



# File 'lib/attr_publish/attr_publish.rb', line 203

#publish!Object

Publish this object, then immediately save it to the database.

Parameters:

  • when (Date, Time, nil)


# File 'lib/attr_publish/attr_publish.rb', line 210

#published?Boolean

Is this object published?

Parameters:

  • when (Date, Time, nil)

    For Date/DateTime publishables, a date/time can be passed to determine if the object was / will be published on the given date.

Returns:

  • (Boolean)

    true if published, false if not published.



# File 'lib/attr_publish/attr_publish.rb', line 189

#unpublishObject

Un-publish this object, i.e. set it to not be published. For a Boolean publish field, the field is set to false; for a Date/DateTime field, the field is cleared.



# File 'lib/attr_publish/attr_publish.rb', line 215

#unpublish!Object

Un-publish this object, then immediately save it to the database.



# File 'lib/attr_publish/attr_publish.rb', line 220

#unpublished?Boolean

Is this object not published?

Parameters:

  • when (Date, Time, nil)

    For Date/DateTime publishables, a date/time can be passed to determine if the object was not / will not be published on the given date.

Returns:

  • (Boolean)

    false if published, true if not published.



# File 'lib/attr_publish/attr_publish.rb', line 196