Class: Ree::PackageSchemaBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ree/core/package_schema_builder.rb

Constant Summary collapse

Schema =
Ree::PackageSchema

Instance Method Summary collapse

Instance Method Details

#call(package) ⇒ Hash

Parameters:

Returns:

  • (Hash)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ree/core/package_schema_builder.rb', line 11

def call(package)
  Ree.logger.debug("generating package schema for '#{package.name}' package")

  if !package.loaded?
    raise Ree::Error.new("package schema should be loaded", :invalid_schema)
  end

  data = {
    Schema::SCHEMA_TYPE => Schema::PACKAGE,
    Schema::SCHEMA_VERSION => Schema::SCHEMA_VERSION_NUMBER,
    Schema::NAME => package.name,
    Schema::ENTRY_PATH => package.entry_rpath,
    Schema::TAGS => package.tags,
    Schema::DEPENDS_ON => package.deps.sort_by(&:name).map { |dep|
      {
        Schema::DependsOn::NAME => dep.name,
      }
    },
    Schema::ENV_VARS => package.env_vars.sort_by(&:name).map { |var|
      {
        Schema::EnvVars::NAME => var.name,
        Schema::EnvVars::DOC => var.doc,
      }
    },
    Schema::OBJECTS => package.objects.select { !_1.rpath.nil? }.sort_by(&:name).map { |object|
      {
        Schema::Objects::NAME => object.name,
        Schema::Objects::SCHEMA => object.schema_rpath,
        Schema::Objects::TAGS => object.tags
      }
    }
  }

  data
end