Module: Katachi::Shapes

Defined in:
lib/katachi/shapes.rb

Overview

A container for all the shapes

Class Method Summary collapse

Class Method Details

.[](maybe_shape) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/katachi/shapes.rb', line 15

def self.[](maybe_shape)
  # :$undefined is a special case because it's a valid key but not a shape
  # This is because it's used to represent a value that is not present in a hash
  # Afaik it's the only shape that has to look at the parent of the value being compared
  # instead of the value itself.
  return maybe_shape if maybe_shape == :$undefined || !valid_key?(maybe_shape)

  @shapes[maybe_shape] || raise(ArgumentError, "Unknown shape: #{maybe_shape}")
end

.add(key, shape) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/katachi/shapes.rb', line 9

def self.add(key, shape)
  raise ArgumentError, "Invalid shape key: #{key}" unless valid_key?(key)

  @shapes[key] = shape
end

.all ⇒ Object



7
# File 'lib/katachi/shapes.rb', line 7

def self.all = @shapes

.valid_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


6
# File 'lib/katachi/shapes.rb', line 6

def self.valid_key?(key) = key.is_a?(Symbol) && key.to_s.start_with?("$")