Class: Suma::SchemaCollection
- Inherits:
-
Object
- Object
- Suma::SchemaCollection
- Defined in:
- lib/suma/schema_collection.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#docs ⇒ Object
Returns the value of attribute docs.
-
#manifest ⇒ Object
Returns the value of attribute manifest.
-
#output_path_docs ⇒ Object
Returns the value of attribute output_path_docs.
-
#output_path_schemas ⇒ Object
Returns the value of attribute output_path_schemas.
-
#schemas ⇒ Object
Returns the value of attribute schemas.
Instance Method Summary collapse
- #compile ⇒ Object
- #doc_from_schema_name(schema_name) ⇒ Object
- #finalize ⇒ Object
-
#initialize(config: nil, config_yaml: nil, output_path_docs: nil, output_path_schemas: nil, manifest: nil) ⇒ SchemaCollection
constructor
A new instance of SchemaCollection.
- #process_schemas(schemas, klass) ⇒ Object
Constructor Details
#initialize(config: nil, config_yaml: nil, output_path_docs: nil, output_path_schemas: nil, manifest: nil) ⇒ SchemaCollection
Returns a new instance of SchemaCollection.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/suma/schema_collection.rb', line 14 def initialize(config: nil, config_yaml: nil, output_path_docs: nil, output_path_schemas: nil, manifest: nil) @schemas = {} @docs = {} @schema_name_to_docs = {} @output_path_docs = if output_path_docs Pathname.new(output_path_docs). else Pathname.new(Dir.pwd) end @output_path_schemas = if output_path_schemas Pathname.new(output_path_schemas). else Pathname.new(Dir.pwd) end @config = if config config elsif config_yaml SchemaConfig::Config.from_file(config_yaml) end @manifest = manifest end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
11 12 13 |
# File 'lib/suma/schema_collection.rb', line 11 def config @config end |
#docs ⇒ Object
Returns the value of attribute docs.
11 12 13 |
# File 'lib/suma/schema_collection.rb', line 11 def docs @docs end |
#manifest ⇒ Object
Returns the value of attribute manifest.
11 12 13 |
# File 'lib/suma/schema_collection.rb', line 11 def manifest @manifest end |
#output_path_docs ⇒ Object
Returns the value of attribute output_path_docs.
11 12 13 |
# File 'lib/suma/schema_collection.rb', line 11 def output_path_docs @output_path_docs end |
#output_path_schemas ⇒ Object
Returns the value of attribute output_path_schemas.
11 12 13 |
# File 'lib/suma/schema_collection.rb', line 11 def output_path_schemas @output_path_schemas end |
#schemas ⇒ Object
Returns the value of attribute schemas.
11 12 13 |
# File 'lib/suma/schema_collection.rb', line 11 def schemas @schemas end |
Instance Method Details
#compile ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/suma/schema_collection.rb', line 76 def compile finalize schemas.each_pair do |_schema_id, entry| entry.save_exp end docs.each_pair do |_schema_id, entry| entry.compile end # TODO: make this parallel # Utils.log"Starting Ractor processing" # pool = Ractor.new do # loop do # Ractor.yield(Ractor.receive) # end # end # workers = (1..4).map do |i| # Ractor.new(pool, name: "r#{i}") do |p| # loop do # input = p.take # Utils.log"compiling in ractor for #{input.filename_adoc}" # output_value = input.compile # Ractor.yield(output_value) # end # end # end # docs.each do |doc| # pool.send(doc) # end # results = [] # docs.size.times do # results << Ractor.select(*workers) # end # pp results end |
#doc_from_schema_name(schema_name) ⇒ Object
39 40 41 |
# File 'lib/suma/schema_collection.rb', line 39 def doc_from_schema_name(schema_name) @schema_name_to_docs[schema_name] end |
#finalize ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/suma/schema_collection.rb', line 62 def finalize # Process each schema in @config.schemas process_schemas(@config.schemas, SchemaAttachment) manifest_entry = @manifest.lookup(:schemas_only, true) manifest_entry.each do |entry| next unless entry.schema_config # Process each schema in entry.schema_config.schemas process_schemas(entry.schema_config.schemas, SchemaDocument) end end |
#process_schemas(schemas, klass) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/suma/schema_collection.rb', line 43 def process_schemas(schemas, klass) schemas.each do |config_schema| s = ExpressSchema.new( id: config_schema.id, path: config_schema.path.to_s, output_path: @output_path_schemas.to_s, ) doc = klass.new( schema: s, output_path: @output_path_docs.join(s.id), ) @docs[s.id] = doc @schemas[s.id] = s @schema_name_to_docs[s.id] = doc end end |