Class: Rails::Crud::Tools::CrudConfig
- Inherits:
-
Object
- Object
- Rails::Crud::Tools::CrudConfig
- Includes:
- Singleton
- Defined in:
- lib/rails/crud/tools/crud_config.rb
Overview
The CrudConfig class is a singleton class responsible for loading and managing configuration settings from a YAML file (.crudconfig.yml). It ensures that the configuration is reloaded if the file is updated.
Constant Summary collapse
- CONFIG_PATH =
File.(".crudconfig.yml", Dir.pwd)
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize ⇒ CrudConfig
constructor
A new instance of CrudConfig.
- #load_config ⇒ Object
Constructor Details
#initialize ⇒ CrudConfig
Returns a new instance of CrudConfig.
16 17 18 |
# File 'lib/rails/crud/tools/crud_config.rb', line 16 def initialize @last_loaded_time = Time.at(0) end |
Class Method Details
.config_path ⇒ Object
20 21 22 |
# File 'lib/rails/crud/tools/crud_config.rb', line 20 def self.config_path CONFIG_PATH end |
Instance Method Details
#config ⇒ Object
24 25 26 27 |
# File 'lib/rails/crud/tools/crud_config.rb', line 24 def config load_config if @config.nil? || config_file_updated? @config end |
#load_config ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/rails/crud/tools/crud_config.rb', line 29 def load_config @config = deep_convert_to_struct(YAML.load_file(CONFIG_PATH)) @last_loaded_time = File.mtime(CONFIG_PATH) rescue Errno::ENOENT raise "Configuration file not found: #{CONFIG_PATH}" rescue Psych::SyntaxError => e raise "YAML syntax error occurred while parsing #{CONFIG_PATH}: #{e.}" end |