Class: AppLocale::Config
- Inherits:
-
Object
- Object
- AppLocale::Config
- Defined in:
- lib/applocale/config.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#configuration_data ⇒ Object
Returns the value of attribute configuration_data.
-
#host ⇒ Object
Returns the value of attribute host.
-
#locale_directory ⇒ Object
Returns the value of attribute locale_directory.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config_file) ⇒ Config
constructor
A new instance of Config.
- #parse_config_file! ⇒ Object
- #validate_config_file! ⇒ Object
Constructor Details
#initialize(config_file) ⇒ Config
Returns a new instance of Config.
12 13 14 15 16 17 18 19 |
# File 'lib/applocale/config.rb', line 12 def initialize(config_file) @config_file = config_file parse_config_file! @api_key = env_or_config_value("api_key") @project_id = env_or_config_value("project_id") @host = env_or_config_value("host") @locale_directory = env_or_config_value("locale_directory", default: "config/locales") end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/applocale/config.rb', line 6 def api_key @api_key end |
#config_file ⇒ Object
Returns the value of attribute config_file.
6 7 8 |
# File 'lib/applocale/config.rb', line 6 def config_file @config_file end |
#configuration_data ⇒ Object
Returns the value of attribute configuration_data.
6 7 8 |
# File 'lib/applocale/config.rb', line 6 def configuration_data @configuration_data end |
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/applocale/config.rb', line 6 def host @host end |
#locale_directory ⇒ Object
Returns the value of attribute locale_directory.
6 7 8 |
# File 'lib/applocale/config.rb', line 6 def locale_directory @locale_directory end |
#project_id ⇒ Object
Returns the value of attribute project_id.
6 7 8 |
# File 'lib/applocale/config.rb', line 6 def project_id @project_id end |
Class Method Details
.load(config_file) ⇒ Object
8 9 10 |
# File 'lib/applocale/config.rb', line 8 def self.load(config_file) new(config_file) end |
Instance Method Details
#parse_config_file! ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/applocale/config.rb', line 21 def parse_config_file! validate_config_file! file_content = File.read(config_file_path) parsed_config_file = ERB.new(file_content).result @configuration_data = YAML.safe_load(parsed_config_file).dig("applocale") || {} end |
#validate_config_file! ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/applocale/config.rb', line 29 def validate_config_file! unless File.exist?(config_file_path) puts "[AppLocale] Error: #{config_file_path} does not exist." exit 1 end unless File.readable?(config_file_path) puts "[AppLocale] Error: #{config_file_path} is not readable by AppLocale." exit 1 end end |