Class: AuditModel::Generators::AuditGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Defined in:
lib/generators/audit_model/audit/audit_generator.rb

Instance Method Summary collapse

Instance Method Details

#audited_propertiesObject



27
28
29
# File 'lib/generators/audit_model/audit/audit_generator.rb', line 27

def audited_properties
  klass.columns.select {|column| properties.include? column.name }
end

#create_audit_migrationObject



23
24
25
# File 'lib/generators/audit_model/audit/audit_generator.rb', line 23

def create_audit_migration
  migration_template "audit_migration.rb", "db/migrate/create_#{table_name}.rb"
end

#klassObject



9
10
11
12
13
14
15
# File 'lib/generators/audit_model/audit/audit_generator.rb', line 9

def klass
  begin
    class_name.constantize
  rescue
    raise "#{class_name} not defined"
  end
end

#migration_class_nameObject



35
36
37
# File 'lib/generators/audit_model/audit/audit_generator.rb', line 35

def migration_class_name
  "Create#{table_name.camelize}"
end

#table_nameObject



31
32
33
# File 'lib/generators/audit_model/audit/audit_generator.rb', line 31

def table_name
  "#{class_name}_audits".downcase
end

#valid_properties?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/generators/audit_model/audit/audit_generator.rb', line 17

def valid_properties?
  properties.each do |propertie|
    raise AuditModel::ColumnNotFoundError.new(klass: class_name, column: propertie) unless klass.attribute_names.include? propertie 
  end
end