Class: Scheman::Diff

Inherits:
Object
  • Object
show all
Defined in:
lib/scheman/diff.rb

Instance Method Summary collapse

Constructor Details

#initialize(before: nil, after: nil, type: nil, before_type: nil, after_type: nil, output_type: nil) ⇒ Diff

Returns a new instance of Diff.

Parameters:

  • before (String) (defaults to: nil)

    The previous schema

  • after (String) (defaults to: nil)

    The next schema

  • type (String) (defaults to: nil)

    The type of schema syntax, default types of the both schemata (e.g. “mysql”)

  • before_type (String) (defaults to: nil)

    Specify the type of the previous schema if needed

  • after_type (String) (defaults to: nil)

    Specify the type of the next schema if needed

  • output_type (String) (defaults to: nil)

    Specify the type of the output schema if needed

Raises:



10
11
12
13
14
15
16
17
18
# File 'lib/scheman/diff.rb', line 10

def initialize(before: nil, after: nil, type: nil, before_type: nil, after_type: nil, output_type: nil)
  @before = before
  @after = after
  @type = type
  @before_type = before_type
  @after_type = after_type
  @output_type = output_type
  validate!
end

Instance Method Details

#to_hashHash

Note:

Passed to Parslet::Transform to convert into SQL string

Returns A hash representation of this diff.

Returns:

  • (Hash)

    A hash representation of this diff



27
28
29
30
31
32
33
# File 'lib/scheman/diff.rb', line 27

def to_hash
  {
    alter_tables: alter_tables,
    create_tables: create_tables,
    drop_tables: drop_tables,
  }
end

#to_sString

Returns A string representation of this diff.

Returns:

  • (String)

    A string representation of this diff



21
22
23
# File 'lib/scheman/diff.rb', line 21

def to_s
  view_class.new(to_hash).to_s
end