Class: Pakyow::Data::Adapters::Sql::Differ Private

Inherits:
Object
  • Object
show all
Defined in:
lib/pakyow/data/adapters/sql/differ.rb

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

Instance Method Summary collapse

Constructor Details

#initialize(connection:, source:, attributes: source.attributes) ⇒ Differ

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.

Returns a new instance of Differ.



9
10
11
# File 'lib/pakyow/data/adapters/sql/differ.rb', line 9

def initialize(connection:, source:, attributes: source.attributes)
  @connection, @source, @attributes = connection, source, attributes
end

Instance Method Details

#attributes ⇒ Object

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.



25
26
27
28
29
# File 'lib/pakyow/data/adapters/sql/differ.rb', line 25

def attributes
  Hash[@attributes.map { |attribute_name, attribute|
    [attribute_name, @connection.adapter.finalized_attribute(attribute)]
  }]
end

#attributes_to_add ⇒ Object

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.



31
32
33
34
35
36
37
38
39
# File 'lib/pakyow/data/adapters/sql/differ.rb', line 31

def attributes_to_add
  {}.tap { |attributes|
    self.attributes.each do |attribute_name, attribute_type|
      unless schema.find { |column| column[0] == attribute_name }
        attributes[attribute_name] = attribute_type
      end
    end
  }
end

#changes? ⇒ Boolean

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.

Returns:

  • (Boolean)


17
18
19
# File 'lib/pakyow/data/adapters/sql/differ.rb', line 17

def changes?
  attributes_to_add.any? || columns_to_remove.any? || column_types_to_change.any?
end

#column_types_to_change ⇒ Object

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.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pakyow/data/adapters/sql/differ.rb', line 51

def column_types_to_change
  {}.tap { |attributes|
    self.attributes.each do |attribute_name, attribute_type|
      if found_column = schema.find { |column| column[0] == attribute_name }
        column_name, column_info = found_column
        unless column_info[:type] == attribute_type.meta[:column_type] && (!attribute_type.meta.include?(:native_type) || column_info[:db_type] == attribute_type.meta[:native_type])
          attributes[column_name] = attribute_type.meta[:migration_type]
        end
      end
    end
  }
end

#columns_to_remove ⇒ Object

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.



41
42
43
44
45
46
47
48
49
# File 'lib/pakyow/data/adapters/sql/differ.rb', line 41

def columns_to_remove
  {}.tap { |columns|
    schema.each do |column_name, column_info|
      unless @source.attributes.keys.find { |attribute_name| attribute_name == column_name }
        columns[column_name] = column_info
      end
    end
  }
end

#exists? ⇒ Boolean

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.

Returns:

  • (Boolean)


13
14
15
# File 'lib/pakyow/data/adapters/sql/differ.rb', line 13

def exists?
  raw_connection.table_exists?(table_name)
end

#table_name ⇒ Object

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.



21
22
23
# File 'lib/pakyow/data/adapters/sql/differ.rb', line 21

def table_name
  @source.dataset_table
end