Class: PDK::Config::JSON
Instance Attribute Summary
Attributes inherited from Namespace
Instance Method Summary collapse
-
#parse_file(filename) ⇒ Object
Parses a JSON document.
-
#serialize_data(data) ⇒ Object
Serializes object data into a JSON string.
Methods inherited from Namespace
#[], #[]=, #child_namespace?, #fetch, #include_in_parent?, #initialize, #mount, #namespace, #read_only!, #resolve, #setting, #to_h
Constructor Details
This class inherits a constructor from PDK::Config::Namespace
Instance Method Details
#parse_file(filename) ⇒ Object
Parses a JSON document.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pdk/config/json.rb', line 9 def parse_file(filename) raise unless block_given? data = load_data(filename) return if data.nil? || data.empty? require 'json' data = ::JSON.parse(data) return if data.nil? || data.empty? data.each { |k, v| yield k, PDK::Config::Setting.new(k, self, v) } rescue ::JSON::ParserError => e raise PDK::Config::LoadError, e. end |
#serialize_data(data) ⇒ Object
Serializes object data into a JSON string.
28 29 30 31 32 |
# File 'lib/pdk/config/json.rb', line 28 def serialize_data(data) require 'json' ::JSON.pretty_generate(data) end |