Class: FakeValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/media_types/serialization/fake_validator.rb

Overview

Validator that accepts all input

Constant Summary collapse

UNSET =
Object.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix, view = nil, version = nil, suffixes = {}) ⇒ FakeValidator

Returns a new instance of FakeValidator.



4
5
6
7
8
9
# File 'lib/media_types/serialization/fake_validator.rb', line 4

def initialize(prefix, view = nil, version = nil, suffixes = {})
  self.prefix = prefix
  self.suffixes = suffixes
  self.internal_view = view
  self.internal_version = version
end

Instance Attribute Details

#prefixObject

Returns the value of attribute prefix.



46
47
48
# File 'lib/media_types/serialization/fake_validator.rb', line 46

def prefix
  @prefix
end

#suffixesObject

Returns the value of attribute suffixes.



47
48
49
# File 'lib/media_types/serialization/fake_validator.rb', line 47

def suffixes
  @suffixes
end

Instance Method Details

#identifierObject



28
29
30
31
32
33
34
35
36
# File 'lib/media_types/serialization/fake_validator.rb', line 28

def identifier
  suffix = suffixes[[internal_view, internal_version]] || ''
  result = prefix
  result += '.v' + internal_version.to_s unless internal_version.nil?
  result += '.' + internal_view.to_s unless internal_view.nil?
  result += '+' + suffix.to_s unless suffix.empty?

  result
end

#override_suffix(suffix) ⇒ Object



23
24
25
26
# File 'lib/media_types/serialization/fake_validator.rb', line 23

def override_suffix(suffix)
  suffixes[[internal_view, internal_version]] = suffix
  FakeValidator.new(prefix, internal_view, version, suffixes)
end

#validatable?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/media_types/serialization/fake_validator.rb', line 38

def validatable?
  true
end

#validate!(_) ⇒ Object



42
43
44
# File 'lib/media_types/serialization/fake_validator.rb', line 42

def validate!(_)
  true
end

#version(version = UNSET) ⇒ Object



18
19
20
21
# File 'lib/media_types/serialization/fake_validator.rb', line 18

def version(version = UNSET)
  return self.internal_version if version == UNSET
  FakeValidator.new(prefix, internal_view, version, suffixes)
end

#view(view = UNSET) ⇒ Object



13
14
15
16
# File 'lib/media_types/serialization/fake_validator.rb', line 13

def view(view = UNSET)
  return self.internal_view if view == UNSET
  FakeValidator.new(prefix, view, internal_version, suffixes)
end