lib/request_log_analyzer/database/base.rb in request-log-analyzer-1.12.0 vs lib/request_log_analyzer/database/base.rb in request-log-analyzer-1.12.1

- old
+ new

@@ -7,21 +7,30 @@ lineno <=> other.lineno else source_comparison end end + + # Handle format manually, because it is prohibidado in Rails 3.2.1 + def format=(arg) + self.attributes[:format] = arg + end + + def format(arg) + self.attributes[:format] + end def line_type self.class.name.underscore.gsub(/_line$/, '').to_sym end - class_inheritable_accessor :line_definition + class_attribute :line_definition cattr_accessor :database def self.subclass_from_line_definition(definition) klass = Class.new(RequestLogAnalyzer::Database::Base) - klass.set_table_name("#{definition.name}_lines") + klass.table_name = "#{definition.name}_lines" klass.line_definition = definition # Set relations with requests and sources table klass.belongs_to :request, :class_name => RequestLogAnalyzer::Database::Request.name @@ -40,11 +49,11 @@ def self.subclass_from_table(table) raise "Table #{table} not found!" unless database.connection.table_exists?(table) klass = Class.new(RequestLogAnalyzer::Database::Base) - klass.set_table_name(table) + klass.table_name = table if klass.column_names.include?('request_id') klass.belongs_to :request, :class_name => RequestLogAnalyzer::Database::Request.name RequestLogAnalyzer::Database::Request.has_many table.to_sym end @@ -73,11 +82,13 @@ t.column :request_id, :integer t.column :source_id, :integer t.column :lineno, :integer line_definition.captures.each do |capture| + column_name = capture[:name] + column_name = 'file_format' if column_name == 'format' # Add a field for every capture - t.column(capture[:name], column_type(capture[:type])) + t.column(column_name, column_type(capture[:type])) # If the capture provides other field as well, create columns for them, too capture[:provides].each { |field, field_type| t.column(field, column_type(field_type)) } if capture[:provides].kind_of?(Hash) end end \ No newline at end of file