class ESA::Flag

The Flag class represents a change of known state of an Accountable and it is used record differences of state caused by Events.

A Flag with an UP transition creates normal Transactions according to the rules specified in a Ruleset. Flags with a DOWN transition revert Transactions created earlier by the corresponding UP transition.

@author Lenno Nagel

Public Instance Methods

became_set?() click to toggle source
# File app/models/esa/flag.rb, line 45
def became_set?
  self.transition == 1
end
became_unset?() click to toggle source
# File app/models/esa/flag.rb, line 49
def became_unset?
  self.transition == -1
end
is_set?() click to toggle source
# File app/models/esa/flag.rb, line 37
def is_set?
  self.state == true
end
is_unset?() click to toggle source
# File app/models/esa/flag.rb, line 41
def is_unset?
  self.state == false
end
matches_spec?(spec) click to toggle source
# File app/models/esa/flag.rb, line 53
def matches_spec?(spec)
  self.nature == spec[:nature].to_s and
  self.state == spec[:state]
end
transactions_match_specs?(specs) click to toggle source
# File app/models/esa/flag.rb, line 58
def transactions_match_specs?(specs)
  if self.transactions.count == specs.count
    self.transactions.map do |tx|
      tx_spec = specs.find{|a| a[:description] == tx.description} || {}
      tx.matches_spec?(tx_spec)
    end.all?
  else
    false
  end
end

Private Instance Methods

initialize_defaults() click to toggle source
# File app/models/esa/flag.rb, line 80
def initialize_defaults
  if not self.event_id.nil?
    self.time ||= self.event.time if self.time.nil?
    self.accountable ||= self.event.accountable if self.accountable_id.nil?
    self.ruleset ||= self.event.ruleset if self.ruleset_id.nil?
  end

  self.processed ||= false
  self.adjusted ||= false
end
validate_transition() click to toggle source
# File app/models/esa/flag.rb, line 71
def validate_transition
  if self.processed and not self.transition.in? [-1, 0, 1]
    errors[:processed] = "The transition must be in? [-1, 0, 1] before processed can be set to true"
  end
  if self.adjusted and not self.transition.in? [-1, 0, 1]
    errors[:adjusted] = "The transition must be in? [-1, 0, 1] before adjusted can be set to true"
  end
end