Module: HasAlterEgo::ActiveRecordAdapater::InstanceMethods

Defined in:
lib/has_alter_ego.rb

Instance Method Summary collapse

Instance Method Details

#alter_ego_stateObject


102
103
104
# File 'lib/has_alter_ego.rb', line 102

def alter_ego_state
  self.alter_ego.state if self.alter_ego
end

#destroyObject


121
122
123
124
125
126
127
# File 'lib/has_alter_ego.rb', line 121

def destroy
  if self.alter_ego
    self.alter_ego.state = 'destroyed'
    self.alter_ego.save
  end
  destroy_without_alter_ego
end

#has_alter_ego?Boolean

Returns:

  • (Boolean)

98
99
100
# File 'lib/has_alter_ego.rb', line 98

def has_alter_ego?
  return self.alter_ego.present?
end

#on_seed(attributes) ⇒ Object


142
143
144
# File 'lib/has_alter_ego.rb', line 142

def on_seed attributes
  # Not implemented
end

#pin!Object


129
130
131
132
# File 'lib/has_alter_ego.rb', line 129

def pin!
  self.alter_ego.state = 'pinned'
  self.alter_ego.save
end

#resetObject


134
135
136
137
138
139
140
# File 'lib/has_alter_ego.rb', line 134

def reset
  self.alter_ego.state = 'default'
  self.alter_ego.save

  self.class.parse_yml_for self.id, true
  self.reload
end

#save(perform_validation = true) ⇒ Object


106
107
108
109
110
111
112
113
114
115
# File 'lib/has_alter_ego.rb', line 106

def save perform_validation = true
  if self.alter_ego
    self.alter_ego.state = 'modified'
    self.alter_ego.save
  end
  if ActiveRecord::VERSION::MAJOR == 3 and !perform_validation.is_a?(Hash)
    perform_validation = {:validate => perform_validation}
  end
  save_without_alter_ego perform_validation
end

#save!Object


117
118
119
# File 'lib/has_alter_ego.rb', line 117

def save!
  save || raise(RecordNotSaved)
end