Module: Lifetime

Extended by:
ActiveSupport::Concern
Defined in:
lib/lifetime.rb,
lib/lifetime/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
"0.1.1"

Instance Method Summary collapse

Instance Method Details

#lifetimeObject



61
62
63
# File 'lib/lifetime.rb', line 61

def lifetime
  lifetime_start_at..lifetime_end_at
end

#lifetime_active?(time = Time.now) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/lifetime.rb', line 33

def lifetime_active?(time = Time.now)
  lifetime_start_at <= time && lifetime_end_at >= time
end

#lifetime_end_atObject



29
30
31
# File 'lib/lifetime.rb', line 29

def lifetime_end_at
  send(self.class.lifetime_end_field)
end

#lifetime_expired?(time = Time.now) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/lifetime.rb', line 41

def lifetime_expired?(time = Time.now)
  lifetime_end_at < time
end

#lifetime_future?(time = Time.now) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/lifetime.rb', line 45

def lifetime_future?(time = Time.now)
  lifetime_start_at > time
end

#lifetime_inactive?(time = Time.now) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/lifetime.rb', line 37

def lifetime_inactive?(time = Time.now)
  !lifetime_active?
end

#lifetime_last_expired(time = Time.now) ⇒ Object



53
54
55
# File 'lib/lifetime.rb', line 53

def lifetime_last_expired(time = Time.now)
  self.class.lifetime_expired(time).first
end

#lifetime_next_future(time = Time.now) ⇒ Object



49
50
51
# File 'lib/lifetime.rb', line 49

def lifetime_next_future(time = Time.now)
  self.class.lifetime_future(time).first
end

#lifetime_overlaps?(another) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/lifetime.rb', line 57

def lifetime_overlaps?(another)
  lifetime.overlaps? another.lifetime
end

#lifetime_start_atObject



25
26
27
# File 'lib/lifetime.rb', line 25

def lifetime_start_at
  send(self.class.lifetime_start_field)
end