Class: FindSubscriptions::SchemaRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/find_subscriptions/schema_registry.rb

Overview

Registry of CSV schemas; supports registration, lookup by name, and auto-detection from headers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchemaRegistry

Returns a new instance of SchemaRegistry.



12
13
14
# File 'lib/find_subscriptions/schema_registry.rb', line 12

def initialize
  @schemas = {}
end

Instance Attribute Details

#schemasObject (readonly)

Returns the value of attribute schemas.



10
11
12
# File 'lib/find_subscriptions/schema_registry.rb', line 10

def schemas
  @schemas
end

Instance Method Details

#detect_for(csv_headers) ⇒ Object

Tries each schema until one matches the CSV headers.



25
26
27
28
29
30
# File 'lib/find_subscriptions/schema_registry.rb', line 25

def detect_for(csv_headers)
  @schemas.each_value do |schema|
    return schema if schema.matches_headers?(csv_headers)
  end
  nil
end

#fetch(name) ⇒ Object



20
21
22
# File 'lib/find_subscriptions/schema_registry.rb', line 20

def fetch(name)
  @schemas.fetch(name) { raise ArgumentError, "Unknown schema: #{name}" }
end

#register(name, schema) ⇒ Object



16
17
18
# File 'lib/find_subscriptions/schema_registry.rb', line 16

def register(name, schema)
  @schemas[name] = schema
end