Class: Ridgepole::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ridgepole/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn_spec, options = {}) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ridgepole/client.rb', line 5

def initialize(conn_spec, options = {})
  @options = options

  ActiveRecord::Base.establish_connection(conn_spec)

  # XXX: If the required processing in class method?
  @options[:index_removed_drop_column] = true if !@options.key?(:index_removed_drop_column) && (Ridgepole::DefaultsLimit.adapter == :postgresql)

  Ridgepole::ExecuteExpander.expand_execute(ActiveRecord::Base.connection)
  @dumper = Ridgepole::Dumper.new(@options)
  @parser = Ridgepole::DSLParser.new(@options)
  @diff = Ridgepole::Diff.new(@options)

  require 'ridgepole/ext/abstract_mysql_adapter/dump_auto_increment' if @options[:mysql_dump_auto_increment]
end

Class Method Details

.diff(dsl_or_config1, dsl_or_config2, options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ridgepole/client.rb', line 49

def diff(dsl_or_config1, dsl_or_config2, options = {})
  logger = Ridgepole::Logger.instance

  logger.verbose_info('# Parse DSL1')
  definition1, _execute1 = load_definition(dsl_or_config1, options)
  logger.verbose_info('# Parse DSL2')
  definition2, _execute2 = load_definition(dsl_or_config2, options)

  logger.verbose_info('# Compare definitions')
  diff = Ridgepole::Diff.new(options)
  diff.diff(definition1, definition2)
end

.dump(conn_spec, options = {}, &block) ⇒ Object



62
63
64
65
# File 'lib/ridgepole/client.rb', line 62

def dump(conn_spec, options = {}, &block)
  client = new(conn_spec, options)
  client.dump(&block)
end

Instance Method Details

#diff(dsl, opts = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ridgepole/client.rb', line 27

def diff(dsl, opts = {})
  logger = Ridgepole::Logger.instance

  logger.verbose_info('# Parse DSL')
  expected_definition, expected_execute = @parser.parse(dsl, opts)
  expected_definition.each_value do |definition|
    merge_table_options(definition)
  end
  logger.verbose_info('# Load tables')
  current_definition, _current_execute = @parser.parse(@dumper.dump, opts)
  logger.verbose_info('# Compare definitions')
  @diff.diff(current_definition, expected_definition, execute: expected_execute)
end

#dump(&block) ⇒ Object



21
22
23
24
25
# File 'lib/ridgepole/client.rb', line 21

def dump(&block)
  logger = Ridgepole::Logger.instance
  logger.verbose_info('# Load tables')
  @dumper.dump(&block)
end