Module: Citier4::ActsAsCitier4::ClassMethods
- Defined in:
- lib/citier4/acts_as_citier4.rb
Constant Summary collapse
- @@first_call =
true
Instance Method Summary collapse
Instance Method Details
#acts_as_citier4(options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/citier4/acts_as_citier4.rb', line 22 def acts_as_citier4( = {}) # your code will go here # First call, in the root class, then in a child, then in a child of child, etc ... set_acts_as_citier(true) # SomesOptions are authorize only in root class, not in child # but is_root? is not yet implemented # but due to the inheritance cascade, the first call of "acts_as_citier" is perform in the root class #:table_name = option for setting the name of the current class table_name, default value = 'tableized(current class name)' # option table_name is authorised in root and child table_name = ([:table_name] || self.name.tableize.gsub(/\//,'_')).to_s # if @@first_call # Unfortunatly, first_call is not a good solution when we are in developpement : acts_as_citier4 could be reload for the root class ... if ! superclass.acts_as_citier? # Root class # Option for setting the inheritance columns, default value = 'type' # authorized only in root db_type_field = ([:db_type_field] || :type).to_s puts "DODO : In Citier, we have to verify the presence of inheritance_column : #{db_type_field}" self.inheritance_column = "#{db_type_field}" # Option for setting the super_class. Only in root # maby it is not usefull any more ? TODO remove super_class super_class = ([:super_class] || ActiveRecord::Base) # add citier_debug("Root Class, in home directory") self.table_name = "#{table_name}" citier_debug("table_name -> #{self.table_name}") # Add the functions required for root classes only # include is for adding methods to an instance of a class # extend is for adding class methods. send :extend, Citier4::RootClassMethods send :include, Citier4::RootInstanceMethods else citier_debug("In Child Class, not Root Class") # setting the inheritance columns in the child. # do we have to do_it ? # - in the writeable part ? # - in the readable part ? # debugger self.inheritance_column = superclass.inheritance_column citier_debug("table_name, writable -> #{table_name}") # Set up the table which contains ALL attributes we want for this class self.table_name = "view_#{table_name}" citier_debug("tablename (view), readable -> #{self.table_name}") # The the Writeable. References the write-able table for the class because # save operations etc can't take place on the views self.const_set("Writeable", create_class_writable(self)) # pour access : self.const_get :Writeable after_initialize do self.id = nil if self.new_record? && self.id == 0 end # Add the functions required for children only send :include, Citier4::ChildInstanceMethods end @@first_call = false end |