Class: PhraseAppUpdater::YMLConfigLoader
- Inherits:
-
Object
- Object
- PhraseAppUpdater::YMLConfigLoader
- Defined in:
- lib/phraseapp_updater/yml_config_loader.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#file_format ⇒ Object
readonly
Returns the value of attribute file_format.
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
Instance Method Summary collapse
-
#initialize(file_path) ⇒ YMLConfigLoader
constructor
A new instance of YMLConfigLoader.
Constructor Details
#initialize(file_path) ⇒ YMLConfigLoader
Returns a new instance of YMLConfigLoader.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/phraseapp_updater/yml_config_loader.rb', line 6 def initialize(file_path) unless File.readable?(file_path) raise RuntimeError.new("Can't read config file at #{file_path}") end parsed_yaml = YAML.load(File.read(file_path)) unless parsed_yaml raise RuntimeError.new("Couldn't parse file contents: #{File.read(file_path)}") end config = parsed_yaml.fetch("phraseapp") @api_key = config.fetch("access_token") @project_id = config.fetch("project_id") push_file_format = config.fetch("push").fetch("sources").first.fetch("params").fetch("file_format") pull_file_format = config.fetch("pull").fetch("targets").first.fetch("params").fetch("file_format") unless push_file_format == pull_file_format raise ArgumentError.new("Push and pull must be the same format") end @file_format = convert(push_file_format) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
5 6 7 |
# File 'lib/phraseapp_updater/yml_config_loader.rb', line 5 def api_key @api_key end |
#file_format ⇒ Object (readonly)
Returns the value of attribute file_format.
5 6 7 |
# File 'lib/phraseapp_updater/yml_config_loader.rb', line 5 def file_format @file_format end |
#project_id ⇒ Object (readonly)
Returns the value of attribute project_id.
5 6 7 |
# File 'lib/phraseapp_updater/yml_config_loader.rb', line 5 def project_id @project_id end |