Class: KDoc::YamlDoc
Overview
YamlDoc is a DSL for modeling YAML data objects
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Attributes inherited from Container
Attributes included from BlockProcessor
#action_block, #block, #block_state, #children, #depend_on_tags, #dependents, #init_block
Attributes included from Datum
Attributes included from Taggable
Instance Method Summary collapse
-
#initialize(key = nil, **opts, &block) ⇒ YamlDoc
constructor
Create YAML document.
-
#load(load_action: :once, data_action: :replace) ⇒ Object
Load data from file.
- #loaded? ⇒ Boolean
Methods inherited from Container
Methods included from BlockProcessor
#action, #actioned?, #add_child, #block_execute, #children_evaluated?, #debug_block_processor, #depend_on, #dependencies_met?, #evaluated?, #execute_block, #fire_action, #fire_children, #fire_eval, #fire_init, #import, #import_data, #init, #initialize_block_processor, #initialized?, #new?, #resolve_dependency
Methods included from Datum
#clear_data, #initialize_data, #set_data
Methods included from Guarded
#clear_errors, #error_hash, #error_messages, #errors, #guard, #log_any_messages, #valid?, #warn
Methods included from Taggable
#initialize_tag, #key, #namespace, #project, #tag, #type
Constructor Details
#initialize(key = nil, **opts, &block) ⇒ YamlDoc
Create YAML document
15 16 17 18 19 20 21 |
# File 'lib/k_doc/yaml_doc.rb', line 15 def initialize(key = nil, **opts, &block) super(**{ key: key }.merge(opts)) initialize_file @block = block if block_given? end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
8 9 10 |
# File 'lib/k_doc/yaml_doc.rb', line 8 def file @file end |
Instance Method Details
#load(load_action: :once, data_action: :replace) ⇒ Object
Load data from file
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/k_doc/yaml_doc.rb', line 31 def load(load_action: :once, data_action: :replace) return if load_action == :once && loaded? content = File.read(file) hash = YAML.safe_load(content) set_data(hash, data_action: data_action) @loaded = true end |
#loaded? ⇒ Boolean
44 45 46 |
# File 'lib/k_doc/yaml_doc.rb', line 44 def loaded? @loaded end |