Class: Rea::AspectType::DueDate::Aspect

Inherits:
Base
  • Object
show all
Defined in:
lib/rea/aspect_type/due_date.rb

Instance Attribute Summary

Attributes inherited from Base

#base

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Rea::AspectType::Base

Instance Method Details

#member(*names) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rea/aspect_type/due_date.rb', line 6

def member *names
  $options = names.extract_options!

  base.send :scope, :expired_on, lambda { |*names|
    $options = names.extract_options!
    $clause = (names.collect {|name| " #{name} < :now " }).join(" AND ")
    base.where($clause, :now=>DateTime.now )
  }
  base.send :scope, :active_on, lambda { |*names|
    $options = names.extract_options!
    $clause = (names.collect {|name| " #{name} > :now " }).join(" AND ")
    base.where($clause, :now=>DateTime.now )
  }

  names.each do |name|
    base.send :attr_accessible, name
    base.send :define_method, "#{name}_state" do
      (Time.now > self.send(name)) ? :expired : :active
    end

    base.send :define_method, "#{name}_expired?" do
      self.send("#{name}_state") == :expired
    end
  end
end