Sha256: e59a2471944ddcbb5f9593ff13b56991b384010a0c523ebf01ad77dfabe48377

Contents?: true

Size: 863 Bytes

Versions: 1

Compression:

Stored size: 863 Bytes

Contents

module Governor
  module Article
    def self.included(base)
      base.belongs_to :author, :polymorphic => true
      Governor::PluginManager.resources(:child_resources).each_key do |resource|
        base.has_many resource
      end
      
      def base.find_all_by_date(year, month = nil, day = nil, page = 1)
        from, to = self.time_delta(year, month, day)
        conditions = ['created_at BETWEEN ? AND ?', from, to]
        paginate :page => page, :conditions => conditions, :order => 'created_at DESC'
      end

      private
      def base.time_delta(year, month = nil, day = nil)
        from = Time.mktime(year, month || 1, day || 1)
        to = if day.present?
          from.end_of_day
        elsif month.present?
          from.end_of_month
        else
          from.end_of_year
        end
        [from, to]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
governor-0.2.0 lib/governor/article.rb