Module: ActsAsStatusFor::InstanceMethods

Defined in:
lib/acts_as_status_for.rb

Instance Method Summary collapse

Instance Method Details

#statusObject Also known as: current_status



133
134
135
# File 'lib/acts_as_status_for.rb', line 133

def status
  statuses.split(' ').first or ''
end

#status=(event_string) ⇒ Object Also known as: current_status=, statuses=



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/acts_as_status_for.rb', line 139

def status=(event_string)
  case event_string
  when nil
    raise UnsupportedStatus.new("nil status") 
  else
    event_string.split(' ').each do | event |
      if self.class.all_at_events.include?(event.to_sym)
        self.send("#{event}!") if self.respond_to?("#{event}!")
	else
		raise UnsupportedStatus.new("#{event} is not a status_at field")
      end
    end
  end
end

#statusesObject



157
158
159
160
161
162
163
164
# File 'lib/acts_as_status_for.rb', line 157

def statuses
  status_time = {}
  get_on_at_events.each do | event |
    time = self.send("#{event}_at")
    status_time[event] = time unless time.nil?
  end
  status_time.sort { |a,b| b.last <=> a.last }.collect(&:first).join(' ')
end