Class: Engineer::Database::AppendEnginePaths
- Inherits:
-
Object
- Object
- Engineer::Database::AppendEnginePaths
- Defined in:
- lib/engineer/database/append_engine_paths.rb
Overview
Add db/migrate, db/views, db/triggers and db/functions folders to app.config.paths so they can be resolved during migration Be sure sure to append to any existing entries in #paths, because other engines, and the app itself, will add their paths too. This step is especially important for the Scenic gem; sql view definitions in db/views are referenced by filename from migrations, and we need to be able to locate those files. The Scenic issue is a bit more too it see scenic.rb for more info. Note that a common but way more kludgy approach to this problem is to copy the migrations views etc from each gen into the host app with a rake task. This is a slicker a less error-proone solution.
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#engine_config ⇒ Object
readonly
Returns the value of attribute engine_config.
Instance Method Summary collapse
- #add_engine_db_path_to_app(sub_folder) ⇒ Object
-
#append_migration_paths ⇒ Object
db/migrate paths are handled rather differently.
- #append_other_paths ⇒ Object
- #call ⇒ Object
-
#initialize(app:, engine_config:) ⇒ AppendEnginePaths
constructor
A new instance of AppendEnginePaths.
- #running_in_dummy_app? ⇒ Boolean
- #running_outside_of_engine? ⇒ Boolean
Constructor Details
#initialize(app:, engine_config:) ⇒ AppendEnginePaths
Returns a new instance of AppendEnginePaths.
20 21 22 23 |
# File 'lib/engineer/database/append_engine_paths.rb', line 20 def initialize(app:, engine_config:) @app = app @engine_config = engine_config end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
18 19 20 |
# File 'lib/engineer/database/append_engine_paths.rb', line 18 def app @app end |
#engine_config ⇒ Object (readonly)
Returns the value of attribute engine_config.
18 19 20 |
# File 'lib/engineer/database/append_engine_paths.rb', line 18 def engine_config @engine_config end |
Instance Method Details
#add_engine_db_path_to_app(sub_folder) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/engineer/database/append_engine_paths.rb', line 45 def add_engine_db_path_to_app(sub_folder) key = "db/#{sub_folder}" path_to_db_things_in_engine = Rails.root.join(engine_config.root, "db", sub_folder) app_config = app.config app_config.paths[key] ||= [] app_config.paths[key] << path_to_db_things_in_engine end |
#append_migration_paths ⇒ Object
db/migrate paths are handled rather differently. Prevent duplicate migrations if we are db:migrating at the engine level (eg when running tests) rather than the host app.
33 34 35 36 37 |
# File 'lib/engineer/database/append_engine_paths.rb', line 33 def append_migration_paths if running_in_dummy_app? || running_outside_of_engine? add_engine_db_path_to_app("migrate") end end |
#append_other_paths ⇒ Object
39 40 41 42 43 |
# File 'lib/engineer/database/append_engine_paths.rb', line 39 def append_other_paths %w(views functions triggers).each do |sub_folder| add_engine_db_path_to_app(sub_folder) end end |
#call ⇒ Object
25 26 27 28 |
# File 'lib/engineer/database/append_engine_paths.rb', line 25 def call append_migration_paths append_other_paths end |
#running_in_dummy_app? ⇒ Boolean
53 54 55 |
# File 'lib/engineer/database/append_engine_paths.rb', line 53 def running_in_dummy_app? Dir.pwd.ends_with?("dummy") end |
#running_outside_of_engine? ⇒ Boolean
57 58 59 |
# File 'lib/engineer/database/append_engine_paths.rb', line 57 def running_outside_of_engine? app.root.to_s.match(engine_config.root.to_s + File::SEPARATOR).nil? end |