Sha256: 8228476fcf0e07bcd89736b58e2411f239fad57668b002ca3aee07fd3c466a30
Contents?: true
Size: 1.81 KB
Versions: 8
Compression:
Stored size: 1.81 KB
Contents
require_relative "script_config" module Extension module Models module SpecificationHandlers module BeaconExtensionUtils class ScriptConfigRepository include SmartProperties property! :ctx, accepts: ShopifyCLI::Context def active? ctx.file_exist?(filename) end def get! raise RuntimeError.new("NoScriptConfigFile"), filename unless active? content = ctx.read(filename) hash = file_content_to_hash(content) from_h(hash) end def filename raise NotImplementedError end private def from_h(hash) Extension::Models::SpecificationHandlers::BeaconExtensionUtils::ScriptConfig.new(content: hash, filename: filename) end def file_content_to_hash(file_content) raise NotImplementedError end def hash_to_file_content(hash) raise NotImplementedError end end class ScriptConfigYmlRepository < ScriptConfigRepository def self.filename "extension.config.yml" end def filename ScriptConfigYmlRepository.filename end private def file_content_to_hash(file_content) begin hash = YAML.load(file_content) rescue Psych::SyntaxError raise parse_error end raise parse_error unless hash.is_a?(Hash) hash end def hash_to_file_content(hash) YAML.dump(hash) end def parse_error RuntimeError.new("ScriptConfigParseError #{filename}, serialization_format: \"YAML\" ") end end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems