Class: Vizcore::ProjectManifest

Inherits:
Object
  • Object
show all
Defined in:
lib/vizcore/project_manifest.rb

Overview

Reads a project-level manifest such as vizcore.yml.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ProjectManifest

Returns a new instance of ProjectManifest.

Parameters:

  • path (String, Pathname)


18
19
20
21
22
23
24
25
26
# File 'lib/vizcore/project_manifest.rb', line 18

def initialize(path)
  @path = Pathname.new(path).expand_path
  raise ArgumentError, "Project manifest not found: #{@path}" unless @path.file?

  @root = @path.dirname
  @data = normalize_hash(YAML.safe_load_file(@path, aliases: false) || {})
rescue Psych::Exception => e
  raise ArgumentError, "Invalid project manifest #{@path}: #{e.message}"
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



15
16
17
# File 'lib/vizcore/project_manifest.rb', line 15

def path
  @path
end

#rootObject (readonly)

Returns the value of attribute root.



15
16
17
# File 'lib/vizcore/project_manifest.rb', line 15

def root
  @root
end

Class Method Details

.load(path) ⇒ Vizcore::ProjectManifest

Parameters:

  • path (String, Pathname)

Returns:



11
12
13
# File 'lib/vizcore/project_manifest.rb', line 11

def self.load(path)
  new(path)
end

Instance Method Details

#config_defaults(profile: nil) ⇒ Hash

Returns config defaults accepted by Vizcore::Config.

Returns:

  • (Hash)

    config defaults accepted by Vizcore::Config



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vizcore/project_manifest.rb', line 29

def config_defaults(profile: nil)
  data = data_for(profile)
  {
    scene_file: expand_path(value_at(data, "scene") || value_at(data, "scene_file")),
    audio_source: value_at(data, "audio_source") || value_at(data, "audio", "source"),
    audio_file: expand_path(value_at(data, "audio_file") || value_at(data, "audio", "file")),
    audio_device: value_at(data, "audio_device") || value_at(data, "audio", "device"),
    feature_file: expand_path(value_at(data, "feature_file") || value_at(data, "features")),
    control_preset: expand_path(value_at(data, "control_preset") || value_at(data, "controlPreset")),
    osc_port: value_at(data, "osc_port") || value_at(data, "sync", "osc_port") || value_at(data, "sync", "osc", "port"),
    plugin_assets: plugin_assets(profile: profile)
  }.compact
end

#plugin_assets(profile: nil) ⇒ Array<Pathname>

Returns frontend plugin assets served and loaded by RackApp.

Returns:

  • (Array<Pathname>)

    frontend plugin assets served and loaded by RackApp



49
50
51
52
53
# File 'lib/vizcore/project_manifest.rb', line 49

def plugin_assets(profile: nil)
  entries = plugin_entries(profile: profile)
  assets = base_values("plugin_assets", "frontend_plugins") + profile_values(profile, "plugin_assets", "frontend_plugins")
  (entries.filter_map { |entry| plugin_asset_path(entry) } + assets.filter_map { |entry| expand_path(entry) }).uniq
end

#plugins(profile: nil) ⇒ Array<String>

Returns require paths loaded before scene evaluation.

Returns:

  • (Array<String>)

    require paths loaded before scene evaluation



44
45
46
# File 'lib/vizcore/project_manifest.rb', line 44

def plugins(profile: nil)
  plugin_entries(profile: profile).filter_map { |entry| plugin_require_path(entry) }.uniq
end

#profile_namesArray<String>

Returns configured profile names.

Returns:

  • (Array<String>)

    configured profile names



56
57
58
# File 'lib/vizcore/project_manifest.rb', line 56

def profile_names
  Hash(@data["profiles"] || {}).keys
end