Class: AwesomeAnnotate::Model

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/awesome_annotate/model.rb

Instance Method Summary collapse

Instance Method Details

#annotate(model_name) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/awesome_annotate/model.rb', line 9

def annotate(model_name)
  abort "Rails application path is required" unless env_file_path.exist?

  apply env_file_path.to_s

  klass = klass_name(model_name)

  return say 'This model does not inherit activerecord' unless klass < ActiveRecord::Base

  column_names = column_names(klass)
  file_path = model_file_path(model_name)

  insert_file_before_class(file_path, klass, "# Columns: #{column_names.join(', ')}\n")

  say "annotate #{model_name.pluralize} table columns in #{file_path}"
end