Class: CC::Yaml::Nodes::Sequence

Inherits:
Node
  • Object
show all
Defined in:
lib/cc/yaml/nodes/sequence.rb

Direct Known Subclasses

FetchList, GlobList

Instance Attribute Summary collapse

Attributes inherited from Node

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#as_json, #dup, #error, #errors, #errors?, has_default?, #initialize, #method_missing, #nested_warning, #respond_to_missing?, #visit_pair, #visit_unexpected, #warning, #warnings, #warnings?

Constructor Details

This class inherits a constructor from CC::Yaml::Nodes::Node

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CC::Yaml::Nodes::Node

Instance Attribute Details

#childrenObject (readonly) Also known as: __getobj__

Returns the value of attribute children.



4
5
6
# File 'lib/cc/yaml/nodes/sequence.rb', line 4

def children
  @children
end

Class Method Details

.[](node_type) ⇒ Object



7
8
9
10
# File 'lib/cc/yaml/nodes/sequence.rb', line 7

def self.[](node_type)
  node_type = Scalar[node_type] unless node_type.is_a? Node
  Class.new(self) { type(node_type) }
end

.type(identifier = nil) ⇒ Object



12
13
14
15
# File 'lib/cc/yaml/nodes/sequence.rb', line 12

def self.type(identifier = nil)
  @type = Nodes[identifier] if identifier
  @type ||= superclass.respond_to?(:type) ? superclass.type : nil
end

Instance Method Details

#==(other) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/cc/yaml/nodes/sequence.rb', line 59

def ==(other)
  other = other.children if other.is_a? Sequence
  if other.respond_to? :to_a and other.to_a.size == children.size
    children.zip(other.to_a).all? { |a, b| a == b }
  else
    identifier == other
  end
end

#add_value(value) ⇒ Object



118
119
120
121
122
# File 'lib/cc/yaml/nodes/sequence.rb', line 118

def add_value(value)
  added = with_value(self)
  added.add_value!(value)
  added
end

#add_value!(value) ⇒ Object



124
125
126
# File 'lib/cc/yaml/nodes/sequence.rb', line 124

def add_value!(value)
  children.concat(with_value(value).children)
end

#allow_child?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/cc/yaml/nodes/sequence.rb', line 49

def allow_child?(*)
  true
end

#deep_verifyObject



97
98
99
100
# File 'lib/cc/yaml/nodes/sequence.rb', line 97

def deep_verify
  @children.each(&:deep_verify)
  super
end

#each_scalar(type = nil, &block) ⇒ Object



102
103
104
105
# File 'lib/cc/yaml/nodes/sequence.rb', line 102

def each_scalar(type = nil, &block)
  return enum_for(:each_scalar, type) unless block
  @children.each { |c| c.each_scalar(type, &block) }
end

#empty?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/cc/yaml/nodes/sequence.rb', line 68

def empty?
  @children.empty?
end

#identifierObject



80
81
82
# File 'lib/cc/yaml/nodes/sequence.rb', line 80

def identifier
  @children.size == 1 ? @children.first : @children
end

#inspectObject



72
73
74
# File 'lib/cc/yaml/nodes/sequence.rb', line 72

def inspect
  identifier.inspect
end

#nested_warnings(*prefix) ⇒ Object



53
54
55
56
57
# File 'lib/cc/yaml/nodes/sequence.rb', line 53

def nested_warnings(*prefix)
  @children.inject(super) do |list, value|
    list = value.nested_warnings(*prefix) + list
  end
end

#prepareObject



17
18
19
# File 'lib/cc/yaml/nodes/sequence.rb', line 17

def prepare
  @children = []
end

#to_sObject



76
77
78
# File 'lib/cc/yaml/nodes/sequence.rb', line 76

def to_s
  identifier.to_s
end

#verifyObject



84
85
86
87
# File 'lib/cc/yaml/nodes/sequence.rb', line 84

def verify
  verify_children
  super
end

#verify_childrenObject



89
90
91
92
93
94
95
# File 'lib/cc/yaml/nodes/sequence.rb', line 89

def verify_children
  @children.delete_if do |child|
    next unless child.errors?
    child.errors.each { |message| error(message) }
    true
  end
end

#visit_child(visitor, value) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cc/yaml/nodes/sequence.rb', line 33

def visit_child(visitor, value)
  child =
    if self.class.type
      self.class.type.new(self)
    else
      visitor.node_wrapper_class(value).new(self)
    end
  visitor.accept(child, value)

  if allow_child?(child)
    @children << child
  else
    warning("Discarding invalid value for %s: %s", self.class, child.value.inspect)
  end
end

#visit_mapping(visitor, value) ⇒ Object



29
30
31
# File 'lib/cc/yaml/nodes/sequence.rb', line 29

def visit_mapping(visitor, value)
  visit_child(visitor, value)
end

#visit_scalar(visitor, type, value, implicit = true) ⇒ Object



25
26
27
# File 'lib/cc/yaml/nodes/sequence.rb', line 25

def visit_scalar(visitor, type, value, implicit = true)
  visit_child(visitor, value) if type != :null
end

#visit_sequence(visitor, value) ⇒ Object



21
22
23
# File 'lib/cc/yaml/nodes/sequence.rb', line 21

def visit_sequence(visitor, value)
  visitor.apply_sequence(self, value)
end

#with_value(value) ⇒ Object



107
108
109
110
111
112
# File 'lib/cc/yaml/nodes/sequence.rb', line 107

def with_value(value)
  return value.dup if value.is_a? self.class
  value = value.children if value.is_a? Sequence
  value = value.value while value.is_a? Scalar
  Parser::Ruby.new(Array(value)).parse self.class.new(parent)
end

#with_value!(value) ⇒ Object



114
115
116
# File 'lib/cc/yaml/nodes/sequence.rb', line 114

def with_value!(value)
  children.replace with_value(value).children
end