Class: AuditModel::Generators::AuditGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- AuditModel::Generators::AuditGenerator
- Defined in:
- lib/generators/audit_model/audit/audit_generator.rb
Instance Method Summary collapse
- #audited_properties ⇒ Object
- #create_audit_migration ⇒ Object
- #klass ⇒ Object
- #migration_class_name ⇒ Object
- #table_name ⇒ Object
- #valid_properties? ⇒ Boolean
Instance Method Details
#audited_properties ⇒ Object
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_migration ⇒ Object
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 |
#klass ⇒ Object
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_name ⇒ Object
35 36 37 |
# File 'lib/generators/audit_model/audit/audit_generator.rb', line 35 def migration_class_name "Create#{table_name.camelize}" end |
#table_name ⇒ Object
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
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 |