Class: Arql::Definition
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Definition
constructor
A new instance of Definition.
Constructor Details
#initialize(options) ⇒ Definition
Returns a new instance of Definition.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/arql/definition.rb', line 122 def initialize() @@options = @@models = [] ActiveRecord::Base.connection.tap do |conn| conn.tables.each do |table_name| conn.primary_key(table_name).tap do |pkey| table_name.camelize.tap do |const_name| const_name = 'Modul' if const_name == 'Module' const_name = 'Clazz' if const_name == 'Class' Class.new(ActiveRecord::Base) do include Arql::Extension self.primary_key = pkey self.table_name = table_name self.inheritance_column = nil self.default_timezone = :local if [:created_at].present? define_singleton_method :timestamp_attributes_for_create do [:created_at] end end if [:updated_at].present? define_singleton_method :timestamp_attributes_for_update do [:updated_at] end end end.tap do |clazz| Object.const_set(const_name, clazz).tap do |const| const_name.gsub(/[a-z]*/, '').tap do |abbr| unless Object.const_defined?(abbr) Object.const_set abbr, const abbr_const = abbr end @@models << { model: const, abbr: abbr_const, table: table_name } end end end end end end end end |
Class Method Details
.models ⇒ Object
65 66 67 |
# File 'lib/arql/definition.rb', line 65 def models @@models ||= [] end |
.redefine ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/arql/definition.rb', line 69 def redefine = @@options @@models.each do |model| Object.send :remove_const, model[:model].name.to_sym if model[:model] Object.send :remove_const, model[:abbr].to_sym if model[:abbr] end @@models = [] ActiveRecord::Base.connection.tap do |conn| conn.tables.each do |table_name| conn.primary_key(table_name).tap do |pkey| table_name.camelize.tap do |const_name| const_name = 'Modul' if const_name == 'Module' const_name = 'Clazz' if const_name == 'Class' Class.new(ActiveRecord::Base) do include Arql::Extension self.primary_key = pkey self.table_name = table_name self.inheritance_column = nil self.default_timezone = :local if [:created_at].present? define_singleton_method :timestamp_attributes_for_create do [:created_at] end end if [:updated_at].present? define_singleton_method :timestamp_attributes_for_update do [:updated_at] end end end.tap do |clazz| Object.const_set(const_name, clazz).tap do |const| const_name.gsub(/[a-z]*/, '').tap do |abbr| unless Object.const_defined?(abbr) Object.const_set abbr, const abbr_const = abbr end @@models << { model: const, abbr: abbr_const, table: table_name } end end end end end end end end |