class Bade::Precompiled
Attributes
code_string[RW]
@return [String]
source_file_path[RW]
@return [String]
Public Class Methods
from_yaml_file(file)
click to toggle source
@param [String, File] file file instance or path to file
# File lib/bade/precompiled.rb, line 21 def self.from_yaml_file(file) file = if file.is_a?(String) File.new(file, 'r') else file end hash = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.0') YAML.safe_load(file, filename: file.path, permitted_classes: [Symbol]) else YAML.safe_load(file, [Symbol]) end raise LoadError, 'YAML file is not in valid format' unless hash.is_a?(Hash) file_path = hash[:source_file_path] content = hash[:code_string] new(content, file_path) end
new(code, source_file_path = nil)
click to toggle source
@param [String] code
# File lib/bade/precompiled.rb, line 43 def initialize(code, source_file_path = nil) @code_string = code @source_file_path = source_file_path end
Public Instance Methods
write_yaml_to_file(file)
click to toggle source
@param [String, File] file file instance or path to file
# File lib/bade/precompiled.rb, line 50 def write_yaml_to_file(file) file = if file.is_a?(String) File.new(file, 'w') else file end content = { source_file_path: source_file_path, code_string: code_string, }.to_yaml file.write(content) file.flush end