Class: Ticket

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
AASM, PublicActivity::Common
Defined in:
app/models/ticket.rb

Direct Known Subclasses

Bug, Project, Story, Task

Defined Under Namespace

Classes: InvalidTypeError, UnknownEventError

Constant Summary collapse

ALLOWED_TYPES =
%w(story task bug)
ACTIVE_STATES =
[:open, :current, :current, :completed]
ARCHIVED_STATES =
[:rejected, :verified]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#old_ancestor_idsObject

Returns the value of attribute old_ancestor_ids.



13
14
15
# File 'app/models/ticket.rb', line 13

def old_ancestor_ids
  @old_ancestor_ids
end

Class Method Details

.filtered_type_class(type) ⇒ Object

Raises:



72
73
74
75
# File 'app/models/ticket.rb', line 72

def self.filtered_type_class(type)
  raise InvalidTypeError unless ALLOWED_TYPES.include?(type)
  type.classify.constantize
end

.orderedObject



77
78
79
# File 'app/models/ticket.rb', line 77

def self.ordered
  order("position ASC") 
end

Instance Method Details

#assignment_usersObject



100
101
102
# File 'app/models/ticket.rb', line 100

def assignment_users
  assignments.map{|assignment| [assignment.user.display_name, assignment.user.id]}
end

#assignment_users_hashObject



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

def assignment_users_hash
  assignments.each_with_object([]) do |assignment, array|
    array << {
      id: assignment.user.id,
      name: assignment.user.display_name,
    }
  end

end

#reorder!(options) ⇒ Object



113
114
115
116
117
118
119
120
121
# File 'app/models/ticket.rb', line 113

def reorder!(options)
  if options[:parent_id]
    self.old_ancestor_ids = self.ancestor_ids
    self.parent_id = options[:parent_id]
    self.save
  end
  self.insert_at options[:position].to_i
  self.save
end

#short_title(num_words = 2) ⇒ Object



81
82
83
84
85
86
87
# File 'app/models/ticket.rb', line 81

def short_title(num_words = 2)
  words = title.split
  short = words[0..num_words].join(" ")
  short += "..." if words.count > num_words

  short
end

#tagsObject



104
105
106
# File 'app/models/ticket.rb', line 104

def tags
  ""
end

#touch_ancestryObject



123
124
125
126
# File 'app/models/ticket.rb', line 123

def touch_ancestry
  self.old_ancestor_ids ||= []
  Ticket.where(id: (ancestor_ids + old_ancestor_ids).uniq).update_all(updated_at: Time.now)
end

#trigger_event!(event) ⇒ Object

Raises:



108
109
110
111
# File 'app/models/ticket.rb', line 108

def trigger_event!(event)
  raise UnknownEventError unless self.aasm.events.include?(event.to_sym)
  self.send("#{event}!")
end