Class: CleoDesignTokens::Bucket

Inherits:
Object
  • Object
show all
Defined in:
lib/cleo_design_tokens/bucket.rb

Overview

Wraps one frozen lookup with a single-argument fetch. Exposed so tests can build one over a fixture lookup, exactly like the module's own colors.primitives below.

Instance Method Summary collapse

Constructor Details

#initialize(lookup) ⇒ Bucket

Returns a new instance of Bucket.



8
9
10
# File 'lib/cleo_design_tokens/bucket.rb', line 8

def initialize(lookup)
  @lookup = lookup
end

Instance Method Details

#fetch(key) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
20
# File 'lib/cleo_design_tokens/bucket.rb', line 12

def fetch(key)
  value = @lookup.fetch(key) { raise UnknownTokenError, "unknown design token: #{key.inspect}" }
  # `Hash#fetch` only guards a missing *key* — a key present with a nil
  # value (malformed data: a primitive leaf with no `$value`) would
  # otherwise return nil instead of raising.
  raise UnknownTokenError, "design token #{key.inspect} has no value" if value.nil?

  value
end