AddIdProperty¶
Constants¶
Methods¶
#default_path
def default_path Rails.root if defined? Rails end
#initialize
def initialize(path = default_path) @models_filename = File.join(joined_path(path), 'add_id_property.yml') end
#joined_path
def joined_path(path) File.join(path.to_s, 'db', 'neo4j-migrate') end
#migrate
def migrate models = ActiveSupport::HashWithIndifferentAccess.new(YAML.load_file(models_filename))[:models] output 'This task will add an ID Property every node in the given file.' output 'It may take a significant amount of time, please be patient.' models.each do |model| output output output "Adding IDs to #{model}" add_ids_to model.constantize end end
- #models_filename
Returns the value of attribute models_filename
def models_filename @models_filename end
#output
def output(string = '') puts string unless !!ENV['silenced'] end
#print_output
def print_output(string) print string unless !!ENV['silenced'] end
#setup
def setup FileUtils.mkdir_p('db/neo4j-migrate') return if File.file?(models_filename) File.open(models_filename, 'w') do |file| message = <<MESSAGE # Provide models to which IDs should be added. # # It will only modify nodes that do not have IDs. There is no danger of overwriting data. # # models: [Student,Lesson,Teacher,Exam]\nmodels: [] MESSAGE file.write(message) end end