Class: Bade::Precompiled
- Inherits:
-
Object
- Object
- Bade::Precompiled
- Defined in:
- lib/bade/precompiled.rb
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(code, source_file_path = nil) ⇒ Precompiled
constructor
A new instance of Precompiled.
- #write_yaml_to_file(file) ⇒ Object
Constructor Details
#initialize(code, source_file_path = nil) ⇒ Precompiled
Returns a new instance of Precompiled.
40 41 42 43 |
# File 'lib/bade/precompiled.rb', line 40 def initialize(code, source_file_path = nil) @code_string = code @source_file_path = source_file_path end |
Instance Attribute Details
#code_string ⇒ String
10 11 12 |
# File 'lib/bade/precompiled.rb', line 10 def code_string @code_string end |
#source_file_path ⇒ String
14 15 16 |
# File 'lib/bade/precompiled.rb', line 14 def source_file_path @source_file_path end |
Class Method Details
.from_yaml_file(file) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bade/precompiled.rb', line 22 def self.from_yaml_file(file) file = if file.is_a?(String) File.new(file, 'r') else file end hash = YAML.load(file) 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 |
Instance Method Details
#write_yaml_to_file(file) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bade/precompiled.rb', line 47 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 |