Class: Kanal::Plugins::ActiveRecord::ActiveRecordPlugin
- Inherits:
-
Core::Plugins::Plugin
- Object
- Core::Plugins::Plugin
- Kanal::Plugins::ActiveRecord::ActiveRecordPlugin
- Defined in:
- lib/kanal/plugins/active_record/active_record_plugin.rb
Constant Summary collapse
- @@migration_directories =
[]
Instance Attribute Summary collapse
-
#connection_options ⇒ Object
readonly
Returns the value of attribute connection_options.
Class Method Summary collapse
-
.connected? ⇒ Boolean
Check if ActiveRecord connected.
- .migrate ⇒ Object
-
.migration_directories ⇒ Array<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.
Instance Method Summary collapse
-
#add_migrations_directory(dir_path, project_name: "default") ⇒ void
Add migrations directory to the list of migrations for specific project.
-
#clear_migration_directories ⇒ void
Just in case.
-
#initialize(connection_options) ⇒ ActiveRecordPlugin
constructor
<Description>.
-
#migrate ⇒ void
Migrating all the added migrations.
- #name ⇒ Object
- #rake_tasks ⇒ Object
-
#setup(core) ⇒ void
<description>.
Constructor Details
#initialize(connection_options) ⇒ ActiveRecordPlugin
<Description>
22 23 24 25 26 27 28 |
# File 'lib/kanal/plugins/active_record/active_record_plugin.rb', line 22 def initialize() super() @connection_options = clear_migration_directories end |
Instance Attribute Details
#connection_options ⇒ Object (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 end |
Class Method Details
.connected? ⇒ Boolean
Check if ActiveRecord connected
90 91 92 |
# File 'lib/kanal/plugins/active_record/active_record_plugin.rb', line 90 def self.connected? ::ActiveRecord::Base.connected? end |
.migrate ⇒ Object
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_directories ⇒ Array<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.
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
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_directories ⇒ void
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 |
#migrate ⇒ void
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 |
#name ⇒ Object
30 31 32 |
# File 'lib/kanal/plugins/active_record/active_record_plugin.rb', line 30 def name :active_record end |
#rake_tasks ⇒ Object
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>.
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 |