Class: Travis::Yaml::Nodes::FixedValue

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

Direct Known Subclasses

CompilerEntry, Language, OSEntry

Instance Attribute Summary

Attributes inherited from Scalar

#value

Attributes inherited from Node

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Scalar

#!@, #==, cast, #cast, cast?, #cast?, default_type, #default_type, #each_scalar, #empty?, has_default?, #inspect, #prepare, #visit_child, #visit_scalar, #visit_sequence, #with_value, #with_value!

Methods inherited from Node

#decrypt, #decrypted?, #deep_verify, #dup, #encrypt, #encrypted?, #error, #errors, #errors?, has_default?, #initialize, #method_missing, #nested_warning, #nested_warnings, #prepare, #respond_to_missing?, #serialize, #to_json, #to_legacy_ruby, #to_ruby, #to_s, #to_yaml, #verify, #verify_language, #visit_child, #visit_mapping, #visit_pair, #visit_scalar, #visit_sequence, #visit_unexpected, #warngings?, #warning, #warnings, #with_value

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

Class Method Details

.[](*values) ⇒ Object



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

def self.[](*values)
  Class.new(self) { value(*values) }
end

.aliasesObject



25
26
27
# File 'lib/travis/yaml/nodes/fixed_value.rb', line 25

def self.aliases
  @aliases ||= superclass.respond_to?(:aliases) ? superclass.aliases.dup : {}
end

.default(value = nil) ⇒ Object



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

def self.default(value = nil)
  value &&= value.to_s
  super(value)
end

.ignore_caseObject



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

def self.ignore_case
  @ignore_case = true
end

.ignore_case?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/travis/yaml/nodes/fixed_value.rb', line 13

def self.ignore_case?
  @ignore_case ||= false
end

.map_value(value) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/travis/yaml/nodes/fixed_value.rb', line 29

def self.map_value(value)
  value = value.to_s
  if ignore_case?
    all_values = valid_values + aliases.keys
    value      = all_values.detect { |supported| supported.downcase == value.downcase }
  end
  value &&= aliases.fetch(value, value)
  value if valid_values.include? value
end

.valid_valuesObject



21
22
23
# File 'lib/travis/yaml/nodes/fixed_value.rb', line 21

def self.valid_values
  @valid_values ||= superclass.respond_to?(:valid_values) ? superclass.valid_values.dup : []
end

.value(*list) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/travis/yaml/nodes/fixed_value.rb', line 39

def self.value(*list)
  list.each do |value|
    if value.respond_to? :each_pair
      value.each_pair { |aka, proper| aliases[aka.to_s] = proper.to_s }
    else
      valid_values << value.to_s
    end
  end
end

Instance Method Details

#value=(value) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/travis/yaml/nodes/fixed_value.rb', line 49

def value=(value)
  if mapped = self.class.map_value(value)
    super(mapped)
  elsif self.value
    warning "illegal value %p, defaulting to %p", value, self.value
  elsif value
    error "illegal value %p", value
  end
end