Class: Polyn::Cli::SchemaLoader

Inherits:
Object
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/polyn/cli/schema_loader.rb

Overview

Loads the JSON schema into the schema registry.

Constant Summary collapse

STORE_NAME =
"POLYN_SCHEMAS"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thor, **opts) ⇒ SchemaLoader

Returns a new instance of SchemaLoader.



19
20
21
22
23
24
25
26
27
28
# File 'lib/polyn/cli/schema_loader.rb', line 19

def initialize(thor, **opts)
  @thor               = thor
  @client             = connect
  @store_name         = opts.fetch(:store_name, STORE_NAME)
  @bucket             = client.key_value(@store_name)
  @cloud_event_schema = Polyn::Cli::CloudEvent.to_h.freeze
  @schemas_dir        = opts.fetch(:schemas_dir, File.join(Dir.pwd, "schemas"))
  @schemas            = {}
  @existing_schemas   = {}
end

Class Method Details

.load(cli) ⇒ Bool

Loads the schemas from the schema repository into the Polyn schema registry.

Returns:

  • (Bool)


15
16
17
# File 'lib/polyn/cli/schema_loader.rb', line 15

def self.load(cli)
  new(cli).load_schemas
end

Instance Method Details

#load_schemasObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/polyn/cli/schema_loader.rb', line 30

def load_schemas
  thor.say "Loading schemas into the Polyn schema registry from '#{schemas_dir}'"
  read_schemas
  load_existing_schemas

  schemas.each do |name, schema|
    bucket.put(name, JSON.generate(schema))
  end

  delete_missing_schemas

  true
end