Class: Textus::Schema::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/schema/registry.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Registry

Returns a new instance of Registry.



4
5
6
7
8
# File 'lib/textus/schema/registry.rb', line 4

def initialize(dir)
  @dir = dir
  @schemas = {}
  load_all
end

Instance Method Details

#allObject



20
21
22
# File 'lib/textus/schema/registry.rb', line 20

def all
  @schemas.values
end

#by_nameObject



24
25
26
# File 'lib/textus/schema/registry.rb', line 24

def by_name
  @schemas.dup
end

#fetch(name) ⇒ Object



10
11
12
# File 'lib/textus/schema/registry.rb', line 10

def fetch(name)
  @schemas[name] || raise(IoError.new("schema not found: #{File.join(@dir, "#{name}.yaml")}"))
end

#fetch_or_nil(name) ⇒ Object



14
15
16
17
18
# File 'lib/textus/schema/registry.rb', line 14

def fetch_or_nil(name)
  return nil if name.nil?

  fetch(name)
end