Module: Citier4::RootInstanceMethods
- Includes:
- InstanceMethods
- Defined in:
- lib/citier4/root_instance_methods.rb
Instance Method Summary collapse
-
#acts_as_citier? ⇒ Boolean
For testing whther we are using the framework or not.
-
#as_child ⇒ Object
Instantiates the instance as it’s lowest root class.
-
#as_root ⇒ Object
Access the root class if ever you need.
- #is_root? ⇒ Boolean
- #root_initialize ⇒ Object
Methods included from InstanceMethods
#attributes_for_current, #attributes_for_parent, #changed_attributes_for_current, #changed_attributes_for_parent, included
Instance Method Details
#acts_as_citier? ⇒ Boolean
For testing whther we are using the framework or not
37 38 39 |
# File 'lib/citier4/root_instance_methods.rb', line 37 def acts_as_citier? true end |
#as_child ⇒ Object
Instantiates the instance as it’s lowest root class. Used when destroying a root class to make sure we’re not leaving children behind
10 11 12 13 |
# File 'lib/citier4/root_instance_methods.rb', line 10 def as_child #instance_class = Object.const_get(self.type) return bottom_class_instance = Kernel.const_get(self.type).where(:id => self.id).first end |
#as_root ⇒ Object
Access the root class if ever you need.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/citier4/root_instance_methods.rb', line 16 def as_root if !self.is_root? root_class = self.class.base_class #get the attributes of the class which are inherited from it's parent. attributes_for_parent = self.attributes.reject{|key,value| !root_class.column_names.include?(key) } #create a new instance of the superclass, passing the inherited attributes. parent = root_class.new(attributes_for_parent) parent.id = self.id parent.type = self.type parent.is_new_record(new_record?) parent else self #just return self if we are the root end end |
#is_root? ⇒ Boolean
41 42 43 44 45 |
# File 'lib/citier4/root_instance_methods.rb', line 41 def is_root? ! self.class.superclass.acts_as_citier? # self.class.superclass==ActiveRecord::Base # eoz # self.class.superclass==Refinery::Core::BaseModel end |
#root_initialize ⇒ Object
47 48 49 |
# File 'lib/citier4/root_instance_methods.rb', line 47 def root_initialize @attributes = self.class._default_attributes.dup end |