Class: DataMigration::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/data_migration/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#data_migrations_full_pathObject



13
14
15
# File 'lib/data_migration/config.rb', line 13

def data_migrations_full_path
  @data_migrations_full_path ||= Rails.root.join(data_migrations_path)
end

#data_migrations_pathObject



8
9
10
# File 'lib/data_migration/config.rb', line 8

def data_migrations_path
  @data_migrations_path ||= "db/data_migrations"
end

#default_jobs_limitObject



80
81
82
# File 'lib/data_migration/config.rb', line 80

def default_jobs_limit
  @default_jobs_limit ||= 10
end

#generate_spec=(value) ⇒ Object (writeonly)

Sets the attribute generate_spec

Parameters:

  • value

    the value to set the attribute generate_spec to.



21
22
23
# File 'lib/data_migration/config.rb', line 21

def generate_spec=(value)
  @generate_spec = value
end

#job_classObject



27
28
29
# File 'lib/data_migration/config.rb', line 27

def job_class
  @job_class ||= DataMigration::Job
end

#job_queue_nameObject



75
76
77
# File 'lib/data_migration/config.rb', line 75

def job_queue_name
  @job_queue_name ||= :default
end

#monitoring_context(&block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/data_migration/config.rb', line 52

def monitoring_context(&block)
  if block.present?
    @monitoring_context = block
  else
    @monitoring_context ||= ->(migration) do
      context = {
        data_migration_name: migration.name,
        data_migration_id: migration.try(:to_global_id) || migration.id,
        data_migration_operator_id: migration.operator&.try(:to_global_id) || migration.operator&.id
      }
      if Object.const_defined?(:ActionReporter)
        ActionReporter.current_user ||= migration.operator
        ActionReporter.context(**context)
      elsif Object.const_defined?(:Audited)
        Audited.store[:audited_user] ||= migration.operator
      else
        Rails.logger.info("Data migration context: #{context.inspect}")
      end
    end
  end
end

#operator_resolver(&block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/data_migration/config.rb', line 37

def operator_resolver(&block)
  if block.present?
    @operator_resolver = block
  else
    @operator_resolver ||= -> do
      if Object.const_defined?(:ActionReporter)
        ActionReporter.current_user
      elsif Object.const_defined?(:Audited)
        Audited.store[:audited_user]
      end
    end
  end
end

#task_classObject



32
33
34
# File 'lib/data_migration/config.rb', line 32

def task_class
  @task_class ||= DataMigration::Task
end

Instance Method Details

#data_migrations_path_globObject



17
18
19
# File 'lib/data_migration/config.rb', line 17

def data_migrations_path_glob
  "#{data_migrations_full_path}/*.rb"
end

#generate_spec?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/data_migration/config.rb', line 22

def generate_spec?
  @generate_spec.nil? ? true : @generate_spec
end

#schema_migrations_pathObject



3
4
5
# File 'lib/data_migration/config.rb', line 3

def schema_migrations_path
  @schema_migrations_path ||= "db/migrate"
end