Class: Nandi::Config

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

Constant Summary collapse

DEFAULT_COMPILE_FILES =
"all"
DEFAULT_LOCKFILE_DIRECTORY =
File.join(Dir.pwd, "db")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(renderer: Renderers::ActiveRecord) ⇒ Config

Returns a new instance of Config.



35
36
37
38
39
40
# File 'lib/nandi/config.rb', line 35

def initialize(renderer: Renderers::ActiveRecord)
  @renderer = renderer
  @custom_methods = {}
  @compile_files = DEFAULT_COMPILE_FILES
  @lockfile_directory = DEFAULT_LOCKFILE_DIRECTORY
end

Instance Attribute Details

#compile_filesString

The files to compile when the compile generator is run. Default: ‘all` May be one of the following:

  • ‘all’ compiles all files

  • ‘git-diff’ only files changed since last commit

  • a full or partial version timestamp, eg ‘20190101010101’, ‘20190101’

  • a timestamp range , eg ‘>=20190101010101’

Returns:

  • (String)


25
26
27
# File 'lib/nandi/config.rb', line 25

def compile_files
  @compile_files
end

#custom_methodsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
# File 'lib/nandi/config.rb', line 33

def custom_methods
  @custom_methods
end

#lockfile_directory=(value) ⇒ String

Directory where .nandilock.yml will be stored Defaults to project root

Returns:

  • (String)


30
31
32
# File 'lib/nandi/config.rb', line 30

def lockfile_directory=(value)
  @lockfile_directory = value
end

#post_processorObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
# File 'lib/nandi/config.rb', line 33

def post_processor
  @post_processor
end

#rendererClass

The rendering backend used to produce output. The only supported option at current is Nandi::Renderers::ActiveRecord, which produces ActiveRecord migrations.

Returns:

  • (Class)


16
17
18
# File 'lib/nandi/config.rb', line 16

def renderer
  @renderer
end

Instance Method Details

#access_exclusive_lock_timeout(database_name = nil) ⇒ Object



75
# File 'lib/nandi/config.rb', line 75

def access_exclusive_lock_timeout(database_name = nil) = config(database_name).access_exclusive_lock_timeout

#access_exclusive_lock_timeout_limit(database_name = nil) ⇒ Object



76
# File 'lib/nandi/config.rb', line 76

def access_exclusive_lock_timeout_limit(database_name = nil) = config(database_name).access_exclusive_lock_timeout_limit

#access_exclusive_statement_timeout(database_name = nil) ⇒ Object



77
# File 'lib/nandi/config.rb', line 77

def access_exclusive_statement_timeout(database_name = nil) = config(database_name).access_exclusive_statement_timeout

#access_exclusive_statement_timeout_limit(database_name = nil) ⇒ Object



78
# File 'lib/nandi/config.rb', line 78

def access_exclusive_statement_timeout_limit(database_name = nil) = config(database_name).access_exclusive_statement_timeout_limit

#concurrent_lock_timeout_limit(database_name = nil) ⇒ Object



79
# File 'lib/nandi/config.rb', line 79

def concurrent_lock_timeout_limit(database_name = nil) = config(database_name).concurrent_lock_timeout_limit

#concurrent_statement_timeout_limit(database_name = nil) ⇒ Object



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

def concurrent_statement_timeout_limit(database_name = nil) = config(database_name).concurrent_statement_timeout_limit
# rubocop:enable Layout/LineLength

#databasesObject



98
99
100
101
102
# File 'lib/nandi/config.rb', line 98

def databases
  # If we've never registered any databases, use a single database with
  # default values for backwards compatibility.
  @multi_db_config.nil? ? single_db_config : @multi_db_config
end

#lockfile_path(database_name = nil) ⇒ Object



67
68
69
# File 'lib/nandi/config.rb', line 67

def lockfile_path(database_name = nil)
  File.join(lockfile_directory, databases.config(database_name).lockfile_name)
end

#migration_directory(database_name = nil) ⇒ Object

Explicitly define getters for backwards compatibility when the database isnt specified. rubocop:disable Layout/LineLength



73
# File 'lib/nandi/config.rb', line 73

def migration_directory(database_name = nil) = config(database_name).migration_directory

#output_directory(database_name = nil) ⇒ Object



74
# File 'lib/nandi/config.rb', line 74

def output_directory(database_name = nil) = config(database_name).output_directory

#post_process {|migration| ... } ⇒ Object

Register a block to be called on output, for example a code formatter. Whatever is returned will be written to the output file.

Yield Parameters:

  • migration (string)

    The text of a compiled migration.



45
46
47
# File 'lib/nandi/config.rb', line 45

def post_process(&block)
  @post_processor = block
end

#register_database(name, config = {}) ⇒ Object

Register a database to compile migrations for.



63
64
65
# File 'lib/nandi/config.rb', line 63

def register_database(name, config = {})
  multi_db_config.register(name, config)
end

#register_method(name, klass) ⇒ Object

Register a custom DDL method.

Parameters:

  • name (Symbol)

    The name of the method to create. This will be monkey-patched into Nandi::Migration.

  • klass (Class)

    The class to initialise with the arguments to the method. It should define a ‘template` instance method which will return a subclass of Cell::ViewModel from the Cells templating library and a `procedure` method that returns the name of the method. It may optionally define a `mixins` method, which will return an array of `Module`s to be mixed into any migration that uses this method.



58
59
60
# File 'lib/nandi/config.rb', line 58

def register_method(name, klass)
  custom_methods[name] = klass
end

#validate!Object



104
105
106
107
108
109
110
# File 'lib/nandi/config.rb', line 104

def validate!
  if @single_db_config && @multi_db_config
    raise ArgumentError, "Cannot use multi and single database config. Config setters are now deprecated, " \
                         "use only `register_database(name, config)` to configure Nandi."
  end
  databases.validate!
end