Sha256: 18c2b0d54b37243d2bb0a51ab8797eb6643074015dfb4bbe715f7853244603e0

Contents?: true

Size: 828 Bytes

Versions: 3

Compression:

Stored size: 828 Bytes

Contents

module Monocle
  module Views
    extend ActiveSupport::Concern

    included do
      has_one :overall_view, :as => :viewable, :dependent => :destroy, :class_name => "Monocle::OverallView"

      %w( daily weekly monthly yearly ).each do |time_span|
        has_many "#{time_span}_views".to_sym, :as => :viewable, :dependent => :destroy, :class_name => "Monocle::#{time_span.classify}View"
      end
    end

    module ClassMethods
      def viewed_since(since, options = {})
        View.since(since, { :viewable_type => self }.merge(options))
      end
    end

    delegate :views, :to => :overall_view, :prefix => :overall, :allow_nil => true

    def view!
      view = DailyView.find_or_create_by_viewable_type_and_viewable_id_and_viewed_on_start_date(self.class.name, id, Date.today)
      view.view!
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
monocle-0.1.1 lib/monocle/views.rb
monocle-0.1.0 lib/monocle/views.rb
monocle-0.0.1 lib/monocle/views.rb