Class: Task

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::MassAssignmentSecurity, Model::MongoDb::Commentable, Model::MongoDb::Customizable, Mongoid::Document, Mongoid::Slug, Mongoid::Timestamps, StateMachines::Task
Defined in:
app/models/task.rb

Constant Summary collapse

PARENT_TYPES =

track_history on: [:user_id, :name, :text, :state]

['story']

Instance Method Summary collapse

Methods included from Model::MongoDb::Commentable

#comments

Instance Method Details

#after_transition(transition) ⇒ Object



90
91
92
93
94
95
96
97
98
99
# File 'app/models/task.rb', line 90

def after_transition(transition)
  case transition.event
  when :follow_up
    self.story.activate if self.story.completed?
  when :complete
    if self.story.tasks.complete.count == self.story.tasks.count
      self.story.complete
    end
  end
end

#authorObject



55
# File 'app/models/task.rb', line 55

def author; author_id ? User.find(author_id) : nil; end

#author=(value) ⇒ Object



56
# File 'app/models/task.rb', line 56

def author=(value); self.author_id = value.id; end

#before_transition(transition) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/models/task.rb', line 70

def before_transition(transition)
  self.event = transition.event.to_s
  self.state_before = transition.from
  
  case transition.event
  when :assign
    self.author_id = self.user_id
  when :cancel
    self.unassigned_user_ids ||= []
    self.unassigned_user_ids << self.user_id
    self.user_id = nil
    self.author_id = nil
    self.result.text = nil if self.result
  when :review
    self.user_id = self.offeror_id
  when :follow_up
    self.user_id = self.author_id
  end
end

#offerorObject

belongs_to (SQL)



49
# File 'app/models/task.rb', line 49

def offeror; offeror_id ? User.find(offeror_id) : nil; end

#offeror=(value) ⇒ Object



50
# File 'app/models/task.rb', line 50

def offeror=(value); self.offeror_id = value.id; end

#result_classObject



58
59
60
61
62
63
64
# File 'app/models/task.rb', line 58

def result_class
  if product_id.present?
    "#{product.class.name}::Result".constantize rescue Result
  else
    Result
  end
end

#to_jsonObject



101
102
103
104
105
106
107
# File 'app/models/task.rb', line 101

def to_json
  record = {
    id: id.to_s, offeror_id: offeror_id, user_id: user_id, author_id: author_id, name: name, text: text, state: state
  }
  record[:result] = result.to_json if result.present?
  record
end

#userObject



52
# File 'app/models/task.rb', line 52

def user; user_id ? User.find(user_id) : nil; end

#user=(value) ⇒ Object



53
# File 'app/models/task.rb', line 53

def user=(value); self.user_id = value.id; end

#with_result?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'app/models/task.rb', line 66

def with_result?
  true
end