Module: Nugrant::Helper::Bag
- Defined in:
- lib/nugrant/helper/bag.rb
Class Method Summary collapse
- .parse_data(filepath, filetype, options = {}) ⇒ Object
- .parse_json(data_string) ⇒ Object
- .parse_yml(data_string) ⇒ Object
- .read(filepath, filetype, options = {}) ⇒ Object
Class Method Details
.parse_data(filepath, filetype, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/nugrant/helper/bag.rb', line 15 def self.parse_data(filepath, filetype, = {}) return if not File.exists?(filepath) File.open(filepath, "rb") do |file| parsing_method = "parse_#{filetype}" return send(parsing_method, file.read) end rescue => error if [:error_handler] # TODO: Implements error handler logic [:error_handler].handle("Could not parse the user #{filetype} parameters file '#{filepath}': #{error}") end end |
.parse_json(data_string) ⇒ Object
29 30 31 |
# File 'lib/nugrant/helper/bag.rb', line 29 def self.parse_json(data_string) MultiJson.load(data_string) end |
.parse_yml(data_string) ⇒ Object
33 34 35 36 37 |
# File 'lib/nugrant/helper/bag.rb', line 33 def self.parse_yml(data_string) YAML::ENGINE.yamler = 'syck' if defined?(YAML::ENGINE) YAML.load(data_string) end |