Class: Aspera::Schema::Registry
- Inherits:
-
Object
- Object
- Aspera::Schema::Registry
- Includes:
- Singleton
- Defined in:
- lib/aspera/schema/registry.rb
Constant Summary collapse
- LOCATIONS =
{ spec: 'aspera/transfer/spec.schema.yaml', args: 'aspera/sync/args.schema.yaml', conf: 'aspera/sync/conf.schema.yaml', opts: 'aspera/cli/options.schema.yaml', aoc: 'aspera/schema/IBM Aspera on Cloud API-0.2.6-enhanced.yaml', faspex: 'aspera/schema/IBM Aspera Faspex API-5.0-enhanced.yaml' }
- OPTIONS =
'opts'- TRANSFER_SPEC =
'spec'- SYNC_CONF =
'conf'- SYNC_ARGS =
'args'- AOC =
'aoc'- FASPEX =
'faspex'- TRANSFER_INFO =
"#{OPTIONS}:components.schemas.TransferInfo"- REQ_BODY =
'.requestBody.content.application/json.schema'
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#reader(name_path) ⇒ Reader
Read schema from file or from cache.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
42 43 44 45 |
# File 'lib/aspera/schema/registry.rb', line 42 def initialize @cache = {} @main_folder = File.('../..', __dir__) end |
Class Method Details
.known?(sym) ⇒ Boolean
14 15 16 |
# File 'lib/aspera/schema/registry.rb', line 14 def known?(sym) LOCATIONS.key?(sym) end |
.req_body(component, endpoint) ⇒ Object
18 19 20 |
# File 'lib/aspera/schema/registry.rb', line 18 def req_body(component, endpoint) "#{component}:paths./#{endpoint}.requestBody.content.application/json.schema" end |
Instance Method Details
#reader(name_path) ⇒ Reader
Read schema from file or from cache
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/aspera/schema/registry.rb', line 50 def reader(name_path) name, path = name_path.split(':', 2) sym = name.to_sym Aspera.assert(Registry.known?(sym)){"schema: #{sym}"} spec_file = File.join(@main_folder, LOCATIONS[sym]) @cache[sym] = Yaml.safe_load(File.read(spec_file)) if spec_file.end_with?('.yaml') && !@cache.key?(sym) @cache[sym] = JSON.parse(File.read(spec_file)) if spec_file.end_with?('.json') && !@cache.key?(sym) reader = Reader.new(@cache[sym]) return reader unless path reader.dig(*path.split('.')) end |