Class: GraphqlMigrateExecution::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql_migrate_execution/migration.rb

Overview

A run of this tool, called by ‘bin/graphql_migrate_execution`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(glob, dry_run: false, migrate: false, cleanup: false, implicit: nil, colorable: IRB::Color.colorable?) ⇒ Migration

Returns a new instance of Migration.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/graphql_migrate_execution/migration.rb', line 5

def initialize(glob, dry_run: false, migrate: false, cleanup: false, implicit: nil, colorable: IRB::Color.colorable?)
  @glob = glob
  if /\/[^.]*$/.match?(@glob)
    if !@glob.end_with?("/")
      @glob += "/"
    end
    @glob += "*.rb"
  end
  @dry_run = dry_run || (migrate == false && cleanup == false)
  @colorable = colorable
  @implicit = implicit
  @action_method = if migrate
    :migrate
  elsif cleanup
    :cleanup
  else
    :analyze
  end
end

Instance Attribute Details

#action_methodObject (readonly)

Returns the value of attribute action_method.



25
26
27
# File 'lib/graphql_migrate_execution/migration.rb', line 25

def action_method
  @action_method
end

#colorableObject (readonly)

Returns the value of attribute colorable.



25
26
27
# File 'lib/graphql_migrate_execution/migration.rb', line 25

def colorable
  @colorable
end

#implicitObject (readonly)

Returns the value of attribute implicit.



25
26
27
# File 'lib/graphql_migrate_execution/migration.rb', line 25

def implicit
  @implicit
end

Instance Method Details

#runObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/graphql_migrate_execution/migration.rb', line 27

def run
  files = Dir.glob(@glob)
  if files.size.zero?
    warn "No files found for #{@glob.inspect}"
  end
  files.each do |filepath|
    source = File.read(filepath)
    action = Action.new(self, filepath, source)
    action.run

    if !@dry_run
      File.write(filepath, action.result_source)
    end

    puts action.message
  end
end