Class: Textus::Schemas
- Inherits:
-
Object
- Object
- Textus::Schemas
- Defined in:
- lib/textus/schemas.rb
Overview
Eager-loading schema cache. Loads every *.yaml under dir at construction. A missing directory is treated as “no schemas” (does not raise) to mirror the lazy behavior previously embedded in Store#schema_for.
Instance Method Summary collapse
- #all ⇒ Object
- #fetch(name) ⇒ Object
-
#fetch_or_nil(name) ⇒ Object
Only nil short-circuits.
-
#initialize(dir) ⇒ Schemas
constructor
A new instance of Schemas.
Constructor Details
#initialize(dir) ⇒ Schemas
Returns a new instance of Schemas.
6 7 8 9 10 |
# File 'lib/textus/schemas.rb', line 6 def initialize(dir) @dir = dir @schemas = {} load_all end |
Instance Method Details
#all ⇒ Object
23 24 25 |
# File 'lib/textus/schemas.rb', line 23 def all @schemas.values end |
#fetch(name) ⇒ Object
12 13 14 |
# File 'lib/textus/schemas.rb', line 12 def fetch(name) @schemas[name] || raise(IoError.new("schema not found: #{File.join(@dir, "#{name}.yaml")}")) end |
#fetch_or_nil(name) ⇒ Object
Only nil short-circuits. A missing-but-named schema still raises IoError.
17 18 19 20 21 |
# File 'lib/textus/schemas.rb', line 17 def fetch_or_nil(name) return nil if name.nil? fetch(name) end |