Class: Travis::Yaml::Nodes::Node

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

Direct Known Subclasses

Mapping, Scalar, Sequence

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) {|_self| ... } ⇒ Node

Returns a new instance of Node.

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
13
14
# File 'lib/travis/yaml/nodes/node.rb', line 9

def initialize(parent)
  @nested_warnings = []
  @parent          = parent
  prepare
  yield self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



92
93
94
95
# File 'lib/travis/yaml/nodes/node.rb', line 92

def method_missing(method, *args, &block)
  return super unless __getobj__.respond_to?(method)
  __getobj__.public_send(method, *args, &block)
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



8
9
10
# File 'lib/travis/yaml/nodes/node.rb', line 8

def parent
  @parent
end

Class Method Details

.has_default?Boolean

Returns:

  • (Boolean)


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

def self.has_default?
  false
end

Instance Method Details

#decrypt(&block) ⇒ Object



101
102
103
# File 'lib/travis/yaml/nodes/node.rb', line 101

def decrypt(&block)
  each_scalar(SecureString) { |v| v.decrypt(&block) }
end

#decrypted?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/travis/yaml/nodes/node.rb', line 109

def decrypted?
  each_scalar(SecureString).all? { |v| v.decrypted? }
end

#deep_verifyObject



60
61
62
# File 'lib/travis/yaml/nodes/node.rb', line 60

def deep_verify
  verify
end

#dupObject



143
144
145
# File 'lib/travis/yaml/nodes/node.rb', line 143

def dup
  super.dup_values
end

#encrypt(&block) ⇒ Object



105
106
107
# File 'lib/travis/yaml/nodes/node.rb', line 105

def encrypt(&block)
  each_scalar(SecureString) { |v| v.encrypt(&block) }
end

#encrypted?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/travis/yaml/nodes/node.rb', line 113

def encrypted?
  each_scalar(SecureString).all? { |v| v.encrypted? }
end

#error(message, *params) ⇒ Object



47
48
49
# File 'lib/travis/yaml/nodes/node.rb', line 47

def error(message, *params)
  errors << message % params
end

#errorsObject



39
40
41
# File 'lib/travis/yaml/nodes/node.rb', line 39

def errors
  @errors ||= []
end

#errors?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/travis/yaml/nodes/node.rb', line 20

def errors?
  errors.any?
end

#nested_warning(message, *prefix) ⇒ Object



28
29
30
# File 'lib/travis/yaml/nodes/node.rb', line 28

def nested_warning(message, *prefix)
  @nested_warnings << [prefix, message]
end

#nested_warnings(*prefix) ⇒ Object



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

def nested_warnings(*prefix)
  messages  = errors + warnings
  prefixed  = messages.map { |warning| [prefix, warning] }
  prefixed += @nested_warnings.map { |p, w| [prefix + p, w] }
  prefixed
end

#prepareObject



51
52
# File 'lib/travis/yaml/nodes/node.rb', line 51

def prepare
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to_missing?(method, include_private = false)
  __getobj__.respond_to?(method, false)
end

#serialize(serializer, options = nil) ⇒ Object



117
118
119
# File 'lib/travis/yaml/nodes/node.rb', line 117

def serialize(serializer, options = nil)
  Serializer[serializer].serialize(self, options)
end

#to_json(options = nil) ⇒ Object



125
126
127
# File 'lib/travis/yaml/nodes/node.rb', line 125

def to_json(options = nil)
  serialize(:json, options)
end

#to_legacy_ruby(options = nil) ⇒ Object



133
134
135
# File 'lib/travis/yaml/nodes/node.rb', line 133

def to_legacy_ruby(options = nil)
  serialize(:legacy, options)
end

#to_ruby(options = nil) ⇒ Object



129
130
131
# File 'lib/travis/yaml/nodes/node.rb', line 129

def to_ruby(options = nil)
  serialize(:ruby, options)
end

#to_sObject



97
98
99
# File 'lib/travis/yaml/nodes/node.rb', line 97

def to_s
  __getobj__.to_s
end

#to_yaml(options = nil) ⇒ Object



121
122
123
# File 'lib/travis/yaml/nodes/node.rb', line 121

def to_yaml(options = nil)
  serialize(:yaml, options)
end

#verifyObject



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

def verify
end

#verify_language(language) ⇒ Object



57
58
# File 'lib/travis/yaml/nodes/node.rb', line 57

def verify_language(language)
end

#visit_child(visitor, value) ⇒ Object



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

def visit_child(visitor, value)
  error("unexpected child")
end

#visit_mapping(visitor, value) ⇒ Object



68
69
70
# File 'lib/travis/yaml/nodes/node.rb', line 68

def visit_mapping(visitor, value)
  error("unexpected mapping")
end

#visit_pair(visitor, key, value) ⇒ Object



72
73
74
# File 'lib/travis/yaml/nodes/node.rb', line 72

def visit_pair(visitor, key, value)
  error("unexpected pair")
end

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



76
77
78
# File 'lib/travis/yaml/nodes/node.rb', line 76

def visit_scalar(visitor, type, value, implicit = true)
  error("unexpected scalar") unless type == :null
end

#visit_sequence(visitor, value) ⇒ Object



80
81
82
# File 'lib/travis/yaml/nodes/node.rb', line 80

def visit_sequence(visitor, value)
  error("unexpected sequence")
end

#visit_unexpected(visitor, value, message = nil) ⇒ Object



64
65
66
# File 'lib/travis/yaml/nodes/node.rb', line 64

def visit_unexpected(visitor, value, message = nil)
  error(message || "unexpected %p", value)
end

#warngings?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/travis/yaml/nodes/node.rb', line 16

def warngings?
  warnings.any?
end

#warning(message, *params) ⇒ Object



43
44
45
# File 'lib/travis/yaml/nodes/node.rb', line 43

def warning(message, *params)
  warnings << message % params
end

#warningsObject



24
25
26
# File 'lib/travis/yaml/nodes/node.rb', line 24

def warnings
  @warnings ||= []
end

#with_value(value) ⇒ Object



137
138
139
140
141
# File 'lib/travis/yaml/nodes/node.rb', line 137

def with_value(value)
  node = dup
  node.with_value!(value)
  node
end