Module: ESA::Associations::FlagsExtension
- Defined in:
- app/models/esa/associations/flags_extension.rb
Instance Method Summary collapse
- #is_set?(nature, time = Time.zone.now, exclude = nil) ⇒ Boolean
- #most_recent(nature, time = Time.zone.now, exclude = nil) ⇒ Object
- #transition_for(flag) ⇒ Object
Instance Method Details
#is_set?(nature, time = Time.zone.now, exclude = nil) ⇒ Boolean
15 16 17 18 19 20 21 22 |
# File 'app/models/esa/associations/flags_extension.rb', line 15 def is_set?(nature, time=Time.zone.now, exclude=nil) most_recent = most_recent(nature, time, exclude) if most_recent.present? most_recent.is_set? # return the set bit of this flag else false end end |
#most_recent(nature, time = Time.zone.now, exclude = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'app/models/esa/associations/flags_extension.rb', line 4 def most_recent(nature, time=Time.zone.now, exclude=nil) query = where(nature: nature). where('esa_flags.time <= ?', time) if exclude.present? query = query.where('esa_flags.id not in (?)', exclude) end query.order('esa_flags.time DESC, esa_flags.created_at DESC').first end |
#transition_for(flag) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'app/models/esa/associations/flags_extension.rb', line 24 def transition_for(flag) if flag.state and not is_set?(flag.nature, flag.time, flag.id) 1 elsif not flag.state and is_set?(flag.nature, flag.time, flag.id) -1 else 0 end end |