Class: Leftovers::ConfigLoader::Node
- Inherits:
-
Object
- Object
- Leftovers::ConfigLoader::Node
- Defined in:
- lib/leftovers/config_loader/node.rb
Constant Summary collapse
- TO_RUBY_INSTANCE =
::Psych::Visitors::ToRuby.new( ::Psych::ScalarScanner.new(class_loader), class_loader )
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #all_errors ⇒ Object
- #array? ⇒ Boolean
- #children ⇒ Object
- #each_key(&block) ⇒ Object
- #error_message ⇒ Object
- #hash? ⇒ Boolean
-
#initialize(node, file, name = nil) ⇒ Node
constructor
A new instance of Node.
- #integer? ⇒ Boolean
- #keys ⇒ Object
- #location ⇒ Object
- #name_ ⇒ Object
- #pairs ⇒ Object
- #scalar? ⇒ Boolean
- #string? ⇒ Boolean
- #to_ruby ⇒ Object
- #to_s ⇒ Object
- #to_sym ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(node, file, name = nil) ⇒ Node
Returns a new instance of Node.
15 16 17 18 19 |
# File 'lib/leftovers/config_loader/node.rb', line 15 def initialize(node, file, name = nil) @node = node @file = file @name = name end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
13 14 15 |
# File 'lib/leftovers/config_loader/node.rb', line 13 def error @error end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
12 13 14 |
# File 'lib/leftovers/config_loader/node.rb', line 12 def file @file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/leftovers/config_loader/node.rb', line 12 def name @name end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
12 13 14 |
# File 'lib/leftovers/config_loader/node.rb', line 12 def node @node end |
Instance Method Details
#all_errors ⇒ Object
33 34 35 |
# File 'lib/leftovers/config_loader/node.rb', line 33 def all_errors Array() + children.flat_map(&:all_errors) end |
#array? ⇒ Boolean
87 88 89 |
# File 'lib/leftovers/config_loader/node.rb', line 87 def array? node.is_a?(::Psych::Nodes::Sequence) end |
#children ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/leftovers/config_loader/node.rb', line 49 def children @children ||= if hash? prepare_hash_children elsif array? node.children.map { |value| self.class.new(value, file, "#{name} value") } else [] end end |
#each_key(&block) ⇒ Object
67 68 69 |
# File 'lib/leftovers/config_loader/node.rb', line 67 def each_key(&block) keys.each(&block) end |
#error_message ⇒ Object
29 30 31 |
# File 'lib/leftovers/config_loader/node.rb', line 29 def "Config SchemaError: #{location} #{@error}" if @error end |
#hash? ⇒ Boolean
41 42 43 |
# File 'lib/leftovers/config_loader/node.rb', line 41 def hash? node.is_a?(::Psych::Nodes::Mapping) end |
#integer? ⇒ Boolean
91 92 93 |
# File 'lib/leftovers/config_loader/node.rb', line 91 def integer? to_ruby.is_a?(::Integer) end |
#keys ⇒ Object
59 60 61 |
# File 'lib/leftovers/config_loader/node.rb', line 59 def keys @keys ||= pairs.map(&:first) end |
#location ⇒ Object
45 46 47 |
# File 'lib/leftovers/config_loader/node.rb', line 45 def location "#{file.relative_path}:#{node.start_line + 1}:#{node.start_column}" end |
#name_ ⇒ Object
21 22 23 |
# File 'lib/leftovers/config_loader/node.rb', line 21 def name_ "#{name} " if name end |
#pairs ⇒ Object
63 64 65 |
# File 'lib/leftovers/config_loader/node.rb', line 63 def pairs @pairs ||= children.each_slice(2).to_a end |
#scalar? ⇒ Boolean
83 84 85 |
# File 'lib/leftovers/config_loader/node.rb', line 83 def scalar? !array? and !hash? end |
#string? ⇒ Boolean
79 80 81 |
# File 'lib/leftovers/config_loader/node.rb', line 79 def string? to_ruby.is_a?(::String) end |
#to_ruby ⇒ Object
71 72 73 |
# File 'lib/leftovers/config_loader/node.rb', line 71 def to_ruby @to_ruby ||= TO_RUBY_INSTANCE.accept(node) end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/leftovers/config_loader/node.rb', line 37 def to_s to_ruby.to_s end |
#to_sym ⇒ Object
75 76 77 |
# File 'lib/leftovers/config_loader/node.rb', line 75 def to_sym to_ruby.to_sym if string? end |
#valid? ⇒ Boolean
25 26 27 |
# File 'lib/leftovers/config_loader/node.rb', line 25 def valid? !error end |