Class: AwesomeAnnotate::Model
- Inherits:
-
Thor
- Object
- Thor
- AwesomeAnnotate::Model
- Includes:
- Thor::Actions
- Defined in:
- lib/awesome_annotate/model.rb
Instance Method Summary collapse
- #annotate(model_name) ⇒ Object
-
#initialize(params = {}) ⇒ Model
constructor
A new instance of Model.
Constructor Details
#initialize(params = {}) ⇒ Model
Returns a new instance of Model.
9 10 11 12 13 |
# File 'lib/awesome_annotate/model.rb', line 9 def initialize(params = {}) super() @env_file_path = Pathname.new(params[:env_file_path] || 'config/environment.rb') @model_dir = Pathname.new(params[:model_dir] || 'app/models') end |
Instance Method Details
#annotate(model_name) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/awesome_annotate/model.rb', line 16 def annotate(model_name) raise "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 |