class SharedTasks::Generators::SharedTaskGenerator
Public Instance Methods
create_initializer_file()
click to toggle source
# File lib/generators/shared_tasks/shared_task_generator.rb, line 8 def create_initializer_file verify_name number = ActiveRecord::Migration.next_migration_number(1) full_name = "#{number}_#{file_name.underscore}" puts "Generating file #{full_name}" create_file "lib/shared_tasks/#{full_name}.rb", file_content end
Private Instance Methods
file_content()
click to toggle source
# File lib/generators/shared_tasks/shared_task_generator.rb, line 19 def file_content %(class #{file_name.camelize}Shared class << self def method_1 #Actions to execute end def destroy_actions #Actions before destroy end end end ) end
verify_name()
click to toggle source
# File lib/generators/shared_tasks/shared_task_generator.rb, line 38 def verify_name route = "#{Rails.root}/lib/shared_tasks" files = Dir.entries(route).select {|f| !File.directory? f}.map{|f| f.split("_").drop(1).join("_").split(".").remove_last(1)}.flatten if files.include?("#{file_name}") message = "There is a file with same name. -Change file name-" puts message.center(100, ".") raise message end end