Module: ArchiveTree

Defined in:
lib/archive_tree.rb,
lib/archive_tree/core.rb,
lib/archive_tree/action_view_extensions.rb

Overview

ArchiveTree is responsible for the creation of hashes that cronologically represent your model based on a provided field

If you wish to take advantage of its functionalities, please use the acts_as_archive method in your ActiveRecord Model.

Examples

class Post < ActiveRecord::Base
  acts_as_archive # uses +created_at+ by default
end

class Post < ActiveRecord::Base
  acts_as_archive :published_at # uses +published_at+ instead of +created_at+ (default)
end

Post.archive_tree(:years_and_months => { 2010 => [1] }) #=> { 2010 => { 1 => [Post] } }

TODO: This module should undergo a query optimization. Furthermore, an ORM abstraction.

Defined Under Namespace

Modules: ActionViewExtensions, Core

Instance Method Summary collapse

Instance Method Details

#acts_as_archive(date_field = :created_at) ⇒ Object

Raises:

  • (::ArgumentError)


25
26
27
28
29
30
31
32
# File 'lib/archive_tree.rb', line 25

def acts_as_archive(date_field = :created_at)
  raise ::ArgumentError, "undefined parameter #{date_field.to_s}" unless column = columns_hash[date_field.to_s]
  raise ::ArgumentError, "invalid parameter #{date_field.to_s}"   unless column.type == :datetime

  self.date_field = date_field # Stores the date column

  extend Core
end