module RailsRbs::MigrationHelpers
This module of helpers is utilized by the RailsRbs
generators to detect model and migration files at their correct path
Public Instance Methods
default_rule_migrations_exist?()
click to toggle source
Detect if the migrations for the default rule types exist. @return true if date_range and location rule migration files exist
# File lib/generators/rails_rbs/migration_helpers.rb, line 18 def default_rule_migrations_exist? %w[add_date_range add_location].all? do |name| Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_#{name}_rule.rb$/).first end end
migration_path()
click to toggle source
@return [String] The relative path to the directory where migration files are stored
# File lib/generators/rails_rbs/migration_helpers.rb, line 37 def migration_path if self.respond_to?(:db_migrate_path) # Rails 5.0.3 and up db_migrate_path else File.join("db", "migrate") end end
model_exists?(name: )
click to toggle source
Detect if a specific model exists by singular name @return true if the a file is found in app/models that matches the name provided
# File lib/generators/rails_rbs/migration_helpers.rb, line 26 def model_exists?(name: ) File.exists?(File.join(destination_root, model_path(name: name))) end
model_path(name: )
click to toggle source
Return the file path for a model using the name as the singular file name @return [String] The relative path of the model file (app/models/rule.rb for name: rule)
# File lib/generators/rails_rbs/migration_helpers.rb, line 32 def model_path(name: ) File.join("app", "models", "#{name}.rb") end
rule_migrations_exist?()
click to toggle source
Detect if the rules and rule_sets table migrations exist. @return true if the rules and rule_sets migration files exist
# File lib/generators/rails_rbs/migration_helpers.rb, line 10 def rule_migrations_exist? %w[add_rules add_rule_sets add_rule_actions].any? do |name| Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_#{name}.rb$/).first end end