Class: MediaTypes::Scheme::Links

Inherits:
Object
  • Object
show all
Defined in:
lib/media_types/scheme/links.rb

Instance Method Summary collapse

Constructor Details

#initializeLinks

Returns a new instance of Links.



9
10
11
# File 'lib/media_types/scheme/links.rb', line 9

def initialize
  self.links = Rules.new(allow_empty: false, expected_type: ::Hash)
end

Instance Method Details

#inspectObject



30
31
32
# File 'lib/media_types/scheme/links.rb', line 30

def inspect
  "[Scheme::Links #{links.keys}]"
end


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/media_types/scheme/links.rb', line 13

def link(key, allow_nil: false, optional: false, &block)
  links.add(
    key,
    Scheme.new do
      attribute :href, String, allow_nil: allow_nil
      instance_exec(&block) if block_given?
    end,
    optional: optional
  )

  self
end

#run_fixture_validations(expect_symbol_keys, backtrace = []) ⇒ Object

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/media_types/scheme/links.rb', line 34

def run_fixture_validations(expect_symbol_keys, backtrace = [])
  fixture_errors = @links.flat_map {|key, rule|
    if rule.is_a?(Scheme)
      begin
        rule.run_fixture_validations(expect_symbol_keys, backtrace.dup.append(key))
        nil
      rescue AssertionError => e
        e.fixture_errors
      end
    end
  }.compact

  raise AssertionError.new(fixture_errors) unless fixture_errors.empty?
end

#validate!(output, options, **_opts) ⇒ Object



26
27
28
# File 'lib/media_types/scheme/links.rb', line 26

def validate!(output, options, **_opts)
  RulesExhaustedGuard.call(output, options, rules: links)
end