#
#= target_dateカラム用共通named_scope群
# Authors:: Sumiyo Yamamoto
# Copyright:: Copyright (C) OrbusNeich Medical K.K.  2010.
#--
# date        name                   note
# 2010.6.11   Sumiyo Yamamoto        新規作成
#-------------------------------------------------------------------------------
#++
module Comm::Module::NamedScope
  #= target_dateカラムを持つモデルの共通named_scopeモジュール
  # target_dateカラムを使ったnamed_scope。
  #------------------------------------------------------------------------#++
  module TargetDate
    def self.included(base)
      base.class_eval do 
        named_scope :period, lambda {|p| {
          :conditions => [
            "target_date BETWEEN ? AND ?", p[:start].to_s, p[:end].to_s
          ]
        } }
        
        named_scope :date, lambda {|date| {
          :conditions => [
            "target_date = ?", date.to_s
          ]
        } }
        
        named_scope :date_sort, :order => 'target_date'
      end
    end
  end
end
