Module: Commander::Patches::PrioritySort

Included in:
Command
Defined in:
lib/commander/patches/priority_sort.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#priorityObject

Returns the value of attribute priority.



6
7
8
# File 'lib/commander/patches/priority_sort.rb', line 6

def priority
  @priority
end

Instance Method Details

#<=>(other) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/commander/patches/priority_sort.rb', line 8

def <=>(other)
  # Different classes can not be compared and thus are considered
  # equal in priority
  return 0 unless self.class == other.class

  # Sort firstly based on the commands priority
  comp = (self.priority || 0) <=> (other.priority || 0)

  # Fall back on name comparison if priority is equal
  comp == 0 ? self.name <=> other.name : comp
end