Main Avalanche Network server application. Built with Ruby on Rails.

mission_agent.rb 1.0KB

    class MissionAgent < ActiveRecord::Base extend FriendlyId friendly_id :role, use: :slugged validates_presence_of :role, :slug belongs_to :mission belongs_to :user belongs_to :instance_source, :class_name => "MissionAgent", :foreign_key => "instance_source_id" has_many :agent_steps, -> { order("position ASC") }, :dependent => :destroy has_many :mission_candidates, :dependent => :destroy has_and_belongs_to_many :rewards accepts_nested_attributes_for :agent_steps, allow_destroy:true accepts_nested_attributes_for :mission_candidates def is_assigned if self.user == nil return false else return true end end def incomplete_step_count steps = 0 self.agent_steps.each do |step| if step.completed steps = steps + 1 end end return steps end def has_completed_steps if self.incomplete_step_count == 0 && self.agent_steps.count > 0 && self.user != nil return true else return false end end end