Class: Voynich::ModelAttributeGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/voynich/model_attribute_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_voynich_attributeObject



16
17
18
19
20
21
# File 'lib/generators/voynich/model_attribute_generator.rb', line 16

def add_voynich_attribute
  inject_into_file(model_file_path, after: "include Voynich::ActiveModel::Model\n",) do <<-RUBY
  voynich_attribute :#{attribute_name}
RUBY
  end
end

#generate_migrationObject



23
24
25
# File 'lib/generators/voynich/model_attribute_generator.rb', line 23

def generate_migration
  generate "migration", "AddVoynich#{attribute_name.classify}ValueIdTo#{model_class_name.pluralize} voynich_#{attribute_name}_value_id:integer"
end

#include_moduleObject



9
10
11
12
13
14
# File 'lib/generators/voynich/model_attribute_generator.rb', line 9

def include_module
  inject_into_file(model_file_path, after: %r{class\s+#{model_class_name}\s+<\s+ActiveRecord::Base\n}) do <<-'RUBY'
  include Voynich::ActiveModel::Model
RUBY
  end
end