class PgRls::Generators::InstallGenerator
Installer Generator
Constants
- APPLICATION_CONTROLLER_LINE
- APPLICATION_CONTROLLER_PATH
- APPLICATION_RECORD_LINE
- APPLICATION_RECORD_PATH
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/generators/pg_rls/install_generator.rb, line 11 def initialize(*args) tenant_model_or_table = args.first if tenant_model_or_table.present? PgRls.table_name = tenant_model_or_table.first.pluralize PgRls.class_name = tenant_model_or_table.first.singularize end super end
Public Instance Methods
aplication_controller_already_included?()
click to toggle source
# File lib/generators/pg_rls/install_generator.rb, line 65 def aplication_controller_already_included? File.readlines(APPLICATION_CONTROLLER_PATH).grep(/include PgRls::MultiTenancy/).any? end
aplication_record_already_included?()
click to toggle source
# File lib/generators/pg_rls/install_generator.rb, line 69 def aplication_record_already_included? File.readlines(APPLICATION_RECORD_PATH).grep(/include PgRls::SecureConnection/).any? end
copy_initializer()
click to toggle source
# File lib/generators/pg_rls/install_generator.rb, line 41 def copy_initializer raise MissingORMError, orm_error_message unless options[:orm] inject_include_to_application_record inject_include_to_application_controller template 'pg_rls.rb.tt', 'config/initializers/pg_rls.rb' end
initialize_error_text()
click to toggle source
# File lib/generators/pg_rls/install_generator.rb, line 73 def initialize_error_text <<-ERROR.strip_heredoc ERROR end
inject_include_to_application_controller()
click to toggle source
# File lib/generators/pg_rls/install_generator.rb, line 57 def inject_include_to_application_controller return if aplication_controller_already_included? gsub_file(APPLICATION_CONTROLLER_PATH, /(#{Regexp.escape(APPLICATION_CONTROLLER_LINE)})/mi) do |match| "#{match}\n include PgRls::MultiTenancy\n" end end
inject_include_to_application_record()
click to toggle source
# File lib/generators/pg_rls/install_generator.rb, line 49 def inject_include_to_application_record return if aplication_record_already_included? gsub_file(APPLICATION_RECORD_PATH, /(#{Regexp.escape(APPLICATION_RECORD_LINE)})/mi) do |match| "#{match}\n include PgRls::SecureConnection\n" end end
orm_error_message()
click to toggle source
# File lib/generators/pg_rls/install_generator.rb, line 30 def orm_error_message <<-ERROR.strip_heredoc An ORM must be set to install PgRls in your application. Be sure to have an ORM like Active Record or loaded in your app or configure your own at `config/application.rb`. config.generators do |g| g.orm :your_orm_gem end ERROR end
show_readme()
click to toggle source
# File lib/generators/pg_rls/install_generator.rb, line 78 def show_readme readme 'README' if behavior == :invoke end