Class: POEditor::PullCommand
- Inherits:
-
Object
- Object
- POEditor::PullCommand
- Defined in:
- lib/poeditor/commands/pull_command.rb
Instance Method Summary collapse
-
#get_configuration(argv) ⇒ POEditor::Configuration
Returns Configuration from the given system arguments.
-
#get_configuration_file_path(argv) ⇒ String
Detects and returns the location of ‘poeditor.yml` file from the given system arguments.
-
#get_or_raise(yaml, key) ⇒ Object
Returns the value of specified key from the given yaml instance.
- #run(argv) ⇒ Object
Instance Method Details
#get_configuration(argv) ⇒ POEditor::Configuration
Returns Configuration from the given system arguments.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/poeditor/commands/pull_command.rb', line 31 def get_configuration(argv) config_path = get_configuration_file_path(argv) unless File.exist?(config_path) raise POEditor::Exception.new %{\ Configuration file doesn't exist: #{config_path}. Try creating `poeditor.yml` or specifying the path using '--config'.\ } end yaml = YAML.load(File.read(config_path)) Configuration.new( api_key: get_or_raise(yaml, "api_key"), project_id: get_or_raise(yaml, "project_id"), type: get_or_raise(yaml, "type"), tags: yaml["tags"], filters: yaml["filters"], languages: get_or_raise(yaml, "languages"), language_alias: yaml["language_alias"], path: get_or_raise(yaml, "path"), path_replace: yaml["path_replace"], ) end |
#get_configuration_file_path(argv) ⇒ String
Detects and returns the location of ‘poeditor.yml` file from the given system arguments.
17 18 19 20 21 22 23 24 |
# File 'lib/poeditor/commands/pull_command.rb', line 17 def get_configuration_file_path(argv) config_index = argv.index("-c") || argv.index("--config") if config_index config_path = argv[config_index + 1] else config_path = "poeditor.yml" end end |
#get_or_raise(yaml, key) ⇒ Object
Returns the value of specified key from the given yaml instance. Raise exception when there’s no key in the yaml.
61 62 63 64 |
# File 'lib/poeditor/commands/pull_command.rb', line 61 def get_or_raise(yaml, key) yaml[key] or raise POEditor::Exception.new \ "Missing configuration key: '#{key}'" end |