Module: Apollo::ActiveRecordExtensions::InstanceMethods

Defined in:
lib/apollo/active_record_extensions.rb

Instance Method Summary collapse

Instance Method Details

#current_state=(new_value) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/apollo/active_record_extensions.rb', line 15

def current_state=(new_value)
  if self.class.persist_string_state_name?
    self[self.class.current_state_column] = new_value
  else
    self[self.class.current_state_id_column] = self.class.state_name_to_id(new_value)
 end
 self.save! unless self.new_record?
end

#load_current_stateObject



4
5
6
7
8
9
10
11
12
13
# File 'lib/apollo/active_record_extensions.rb', line 4

def load_current_state
  result = if self.class.persist_string_state_name?
    read_attribute(self.class.current_state_column)
  else
    id = read_attribute(self.class.current_state_id_column)
    self.class.state_id_to_name(id) if id
  end

  result || self.default_state
end