Class: Pod::YAMLHelper
- Inherits:
-
Object
- Object
- Pod::YAMLHelper
- Defined in:
- lib/cocoapods-core/yaml_helper.rb
Overview
This class misses important features necessary for a correct YAML serialization and thus it is safe to use only for the Lockfile. The missing features include:
-
Strings are never quoted even when ambiguous.
Converts objects to their YAML representation.
This class was created for the need having control on how the YAML is representation is generated. In details it provides:
-
sorting for hashes in ruby 1.8.x
-
ability to hint the sorting of the keys of a dictionary when converting it. In this case the keys are also separated by an additional new line feed for readability.
Class Method Summary collapse
-
.convert(value) ⇒ String
Returns the YAML representation of the given object.
- .convert_hash(value, hash_keys_hint, line_separator = "\n") ⇒ Object
-
.load_file(file_path) ⇒ Hash, Array
Loads a YAML file and leans on the #load_string imp to do error detection.
-
.load_string(yaml_string, file_path = nil) ⇒ Hash, Array
Loads a YAML string and provide more informative error messages in special cases like merge conflict.
Class Method Details
.convert(value) ⇒ String
Returns the YAML representation of the given object. If the given object is a Hash, it accepts an optional hint for sorting the keys.
31 32 33 34 |
# File 'lib/cocoapods-core/yaml_helper.rb', line 31 def convert(value) result = process_according_to_class(value) result << "\n" end |
.convert_hash(value, hash_keys_hint, line_separator = "\n") ⇒ Object
36 37 38 39 |
# File 'lib/cocoapods-core/yaml_helper.rb', line 36 def convert_hash(value, hash_keys_hint, line_separator = "\n") result = process_hash(value, hash_keys_hint, line_separator) result << "\n" end |
.load_file(file_path) ⇒ Hash, Array
Loads a YAML file and leans on the #load_string imp to do error detection
70 71 72 |
# File 'lib/cocoapods-core/yaml_helper.rb', line 70 def load_file(file_path) load_string(File.read(file_path), file_path) end |
.load_string(yaml_string, file_path = nil) ⇒ Hash, Array
Loads a YAML string and provide more informative error messages in special cases like merge conflict.
52 53 54 55 56 57 58 59 60 |
# File 'lib/cocoapods-core/yaml_helper.rb', line 52 def load_string(yaml_string, file_path = nil) YAML.load(yaml_string) rescue if yaml_has_merge_error?(yaml_string) raise Informative, yaml_merge_conflict_msg(yaml_string, file_path) else raise Informative, yaml_parsing_error_msg(yaml_string, file_path) end end |