Class: Kanal::Plugins::ActiveRecord::ActiveRecordPlugin

Inherits:
Core::Plugins::Plugin
  • Object
show all
Defined in:
lib/kanal/plugins/active_record/active_record_plugin.rb

Constant Summary collapse

@@migration_directories =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_options) ⇒ ActiveRecordPlugin

<Description>

Parameters:

  • connection_data (Hash<String, Object>)

    <description>



22
23
24
25
26
27
28
# File 'lib/kanal/plugins/active_record/active_record_plugin.rb', line 22

def initialize(connection_options)
  super()

  @connection_options = connection_options

  clear_migration_directories
end

Instance Attribute Details

#connection_optionsObject (readonly)

Returns the value of attribute connection_options.



13
14
15
# File 'lib/kanal/plugins/active_record/active_record_plugin.rb', line 13

def connection_options
  @connection_options
end

Class Method Details

.connected?Boolean

Check if ActiveRecord connected

Returns:

  • (Boolean)

    <description>



90
91
92
# File 'lib/kanal/plugins/active_record/active_record_plugin.rb', line 90

def self.connected?
  ::ActiveRecord::Base.connected?
end

.migrateObject



105
106
107
108
109
110
111
112
113
114
# File 'lib/kanal/plugins/active_record/active_record_plugin.rb', line 105

def self.migrate
  @@migration_directories.each do |project_name, dir_path|
    # Kanal::Plugins::ActiveRecord::Overriden::VersionSuffixMigrationContext.new(
    #   project_name,
    ::ActiveRecord::MigrationContext.new(
      dir_path,
      ::ActiveRecord::Base.connection.schema_migration
    ).migrate
  end
end

.migration_directoriesArray<String>

This class method allows for Rakefile to access migration directories NOTE: there maaaay be problems when somebody uses this plugin several times within one project, I guess? Not sure this will be the use case in the future.

Returns:

  • (Array<String>)

    list of migration directories



101
102
103
# File 'lib/kanal/plugins/active_record/active_record_plugin.rb', line 101

def self.migration_directories
  @@migration_directories
end

Instance Method Details

#add_migrations_directory(dir_path, project_name: "default") ⇒ void

This method returns an undefined value.

Add migrations directory to the list of migrations for specific project

Parameters:

  • dir (String)

    <description>

  • project_name (String) (defaults to: "default")

    name of project which will migrations belong to. NOT USED right now



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/kanal/plugins/active_record/active_record_plugin.rb', line 60

def add_migrations_directory(dir_path, project_name: "default")
  raise "Directory path #{dir_path} for migrations does not exist!" unless Dir.exist? dir_path

  if !@@migration_directories.keys.include? project_name
    @@migration_directories[project_name] = []
  end

  return if @@migration_directories[project_name].include? dir_path

  @@migration_directories[project_name] << dir_path
end

#clear_migration_directoriesvoid

This method returns an undefined value.

Just in case



48
49
50
# File 'lib/kanal/plugins/active_record/active_record_plugin.rb', line 48

def clear_migration_directories
  @@migration_directories = {}
end

#migratevoid

This method returns an undefined value.

Migrating all the added migrations



77
78
79
# File 'lib/kanal/plugins/active_record/active_record_plugin.rb', line 77

def migrate
  self.class.migrate
end

#nameObject



30
31
32
# File 'lib/kanal/plugins/active_record/active_record_plugin.rb', line 30

def name
  :active_record
end

#rake_tasksObject



81
82
83
# File 'lib/kanal/plugins/active_record/active_record_plugin.rb', line 81

def rake_tasks
  [Kanal::Plugins::ActiveRecord::Tasks::MigrateTask.new]
end

#setup(core) ⇒ void

This method returns an undefined value.

Returns <description>.

Parameters:

  • core (Kanal::Core::Core)

    <description>



39
40
41
# File 'lib/kanal/plugins/active_record/active_record_plugin.rb', line 39

def setup(core)
  ::ActiveRecord::Base.establish_connection(**@connection_options)
end