Class: Travis::Yaml::Nodes::Sequence

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

Instance Attribute Summary collapse

Attributes inherited from Node

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#decrypt, #decrypted?, #dup, #encrypt, #encrypted?, #error, #errors, #errors?, has_default?, #initialize, #method_missing, #nested_warning, #respond_to_missing?, #serialize, #to_json, #to_legacy_ruby, #to_ruby, #to_yaml, #verify_language, #visit_pair, #visit_unexpected, #warngings?, #warning, #warnings

Constructor Details

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

Dynamic Method Handling

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

Instance Attribute Details

#childrenObject (readonly) Also known as: __getobj__

Returns the value of attribute children.



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

def children
  @children
end

Class Method Details

.[](node_type) ⇒ Object



7
8
9
10
# File 'lib/travis/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/travis/yaml/nodes/sequence.rb', line 12

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

Instance Method Details

#==(other) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/travis/yaml/nodes/sequence.rb', line 45

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



104
105
106
107
108
# File 'lib/travis/yaml/nodes/sequence.rb', line 104

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

#add_value!(value) ⇒ Object



110
111
112
# File 'lib/travis/yaml/nodes/sequence.rb', line 110

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

#deep_verifyObject



83
84
85
86
# File 'lib/travis/yaml/nodes/sequence.rb', line 83

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

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



88
89
90
91
# File 'lib/travis/yaml/nodes/sequence.rb', line 88

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)


54
55
56
# File 'lib/travis/yaml/nodes/sequence.rb', line 54

def empty?
  @children.empty?
end

#identifierObject



66
67
68
# File 'lib/travis/yaml/nodes/sequence.rb', line 66

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

#inspectObject



58
59
60
# File 'lib/travis/yaml/nodes/sequence.rb', line 58

def inspect
  identifier.inspect
end

#nested_warnings(*prefix) ⇒ Object



39
40
41
42
43
# File 'lib/travis/yaml/nodes/sequence.rb', line 39

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

#prepareObject



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

def prepare
  @children = []
end

#to_sObject



62
63
64
# File 'lib/travis/yaml/nodes/sequence.rb', line 62

def to_s
  identifier.to_s
end

#verifyObject



70
71
72
73
# File 'lib/travis/yaml/nodes/sequence.rb', line 70

def verify
  verify_children
  super
end

#verify_childrenObject



75
76
77
78
79
80
81
# File 'lib/travis/yaml/nodes/sequence.rb', line 75

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

#visit_child(visitor, value) ⇒ Object



33
34
35
36
37
# File 'lib/travis/yaml/nodes/sequence.rb', line 33

def visit_child(visitor, value)
  child = self.class.type.new(self)
  visitor.accept(child, value)
  @children << child
end

#visit_mapping(visitor, value) ⇒ Object



29
30
31
# File 'lib/travis/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/travis/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/travis/yaml/nodes/sequence.rb', line 21

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

#with_value(value) ⇒ Object



93
94
95
96
97
98
# File 'lib/travis/yaml/nodes/sequence.rb', line 93

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



100
101
102
# File 'lib/travis/yaml/nodes/sequence.rb', line 100

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