Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom paths for scenic views #385

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/scenic/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,23 @@ def full_path
end

def path
File.join("db", "views", filename)
default_view_path = File.join("db", "views")
view_filename = filename
# in version7 of ActiveRecord was removed ActiveRecord::Base.connection_config
AlexeyAfrosin marked this conversation as resolved.
Show resolved Hide resolved
custom_paths = if ActiveRecord::VERSION::MAJOR < 7
ActiveRecord::Base.connection_config[:scenic_views_paths]
else
ActiveRecord::Base.connection_db_config.configuration_hash[:scenic_views_paths]
AlexeyAfrosin marked this conversation as resolved.
Show resolved Hide resolved
end
view_paths = Array(custom_paths)
view_paths = [default_view_path] if view_paths.empty?

full_view_path = nil
view_paths.each do |path|
full_view_path = File.join(path, view_filename)
break if File.exist?(full_view_path)
end
full_view_path
end

def version
Expand Down
2 changes: 1 addition & 1 deletion lib/scenic/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Scenic
VERSION = "1.7.0".freeze
VERSION = "1.7.3".freeze
end
3 changes: 3 additions & 0 deletions spec/dummy/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ development: &default
test:
<<: *default
database: dummy_test
# set custom paths for scenic views
# scenic_views_paths:
# - '/db/views/postges'