Module: Citier4::InstanceMethods::ForcedWriters

Defined in:
lib/citier4/instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#becomes_super_oldObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/citier4/instance_methods.rb', line 55

def becomes_super_old
 #  debugger
  keys = self.class.superclass.attribute_names.dup  # car sinon, c'est la même référence
  keys.delete(self.class.inheritance_column)
  became = self.class.superclass.new self.attributes.slice(*keys)
  became.id = self.id
  became[self.class.inheritance_column] = self[self.class.inheritance_column]
  became.clear_changes_information 
  #became.instance_variable_set("@changed_attributes", @changed_attributes.slice(*keys)) if defined?(@changed_attributes)
  became.force_attributes(attributes_for_parent)
  became.force_changed_attributes(changed_attributes_for_parent)      
  became.instance_variable_set("@new_record", new_record?)
  became.instance_variable_set("@destroyed", destroyed?)
  became.instance_variable_set("@errors", errors)
  became
end

#becomes_super_old1Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/citier4/instance_methods.rb', line 72

def becomes_super_old1
  #keys = self.class.superclass.attribute_names.dup  # car sinon, c'est la même référence
  #keys.delete(self.class.inheritance_column)
  became = self.class.superclass.new  # self.attributes.slice(*keys)
  became.id = self.id # nul if create, a real id otherwise
  became.clear_changes_information 
  became.force_attributes(attributes_for_parent)
  became.is_new_record(self.new_record?)
  became.force_changed_attributes(changed_attributes_for_parent) 
  became
end

#force_attributes(new_attributes, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/citier4/instance_methods.rb', line 31

def force_attributes(new_attributes, options = {})
  # TODO  new_attributes = @attributes.merge(new_attributes) if options[:merge]
  new_attributes = self.attributes.merge(new_attributes) if options[:merge]
  
  # TODO @attributes = new_attributes
  self.attributes = new_attributes
  # remplace la valeur d'un attribut par celle fournie,
  # Ne change pas la liste des attributs.
  
  if options[:clear_caches] != false
    @aggregation_cache = {}
    @association_cache = {}
    @attributes_cache = {}
  end
end

#force_changed_attributes(new_changed_attributes, options = {}) ⇒ Object

TODO : Is is still usefull ? Can we remove by using ActiveRecord::Dirty ? see api.rubyonrails.org/classes/ActiveModel/Dirty.html



49
50
51
52
# File 'lib/citier4/instance_methods.rb', line 49

def force_changed_attributes(new_changed_attributes, options = {})
  new_changed_attributes = @attributes.merge(new_changed_attributes) if options[:merge]
  @changed_attributes = new_changed_attributes
end