Module: RailsHmvc::Generators::GeneratorHelpers
- Included in:
- ControllerGenerator, FormGenerator, OperationGenerator
- Defined in:
- lib/generators/hmvc/generator_helpers.rb
Instance Method Summary collapse
- #load_config ⇒ Object
- #load_config_for_type(type = nil) ⇒ Object
- #namespace_name ⇒ Object
- #namespace_path ⇒ Object
- #singular_human_name ⇒ Object
Instance Method Details
#load_config ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/generators/hmvc/generator_helpers.rb', line 8 def load_config config_path = File.join(destination_root, "config/rails_hmvc.yml") return {} unless File.exist?(config_path) # Read file and handle manually if there is an error with aliases begin # Try reading with aliases: true (Rails 7+) yaml_content = File.read(config_path) config = begin YAML.safe_load(yaml_content, aliases: true) rescue StandardError nil end # If error, try reading without aliases (Psych 4+) if config.nil? config = begin YAML.safe_load(yaml_content) rescue StandardError {} end end rescue StandardError => e Rails.logger.debug { "Warning: Error loading rails_hmvc.yml: #{e.}" } return {} end config || {} end |
#load_config_for_type(type = nil) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/generators/hmvc/generator_helpers.rb', line 38 def load_config_for_type(type = nil) config = load_config type ||= config["type"] || "api" base_config = config.except("api", "web") type_config = config[type.to_s] || {} base_config.merge(type_config) end |
#namespace_name ⇒ Object
51 52 53 |
# File 'lib/generators/hmvc/generator_helpers.rb', line 51 def namespace_name class_path.map(&:camelize).join("::") end |
#namespace_path ⇒ Object
47 48 49 |
# File 'lib/generators/hmvc/generator_helpers.rb', line 47 def namespace_path class_path.join("/") end |
#singular_human_name ⇒ Object
55 56 57 |
# File 'lib/generators/hmvc/generator_helpers.rb', line 55 def singular_human_name human_name.singularize end |