Class: Archive2s::Model

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/archive_2s/model.rb

Instance Method Summary collapse

Instance Method Details

#modelObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/archive_2s/model.rb', line 7

def model
  archived_model = model_class.new()
  archived_model.id = self.model_id
  #can't use self in the instance_eval/define method so make a local variable first
  return_value = self.archived_value

  archived_model.instance_eval do
    singleton = class << self; self; end
    singleton.send(:define_method, self.class.archive_2s_args[:method_name]) do
      return_value
    end
  end
  
  archived_model.readonly!
  archived_model
end

#model_classObject



24
25
26
# File 'lib/archive_2s/model.rb', line 24

def model_class
  @model_class ||= eval(self.model_type.classify)
end