Class: Gienah::Manifest
- Inherits:
-
Object
- Object
- Gienah::Manifest
- Defined in:
- lib/gienah/manifest.rb,
sig/gienah.rbs
Constant Summary collapse
- REQUIRED =
%w[id name version api_version entry].freeze
- EXACT_CAPABILITIES =
%w[ buffer.read buffer.edit workspace.read ui.panel ui.command ui.statusbar ui.decoration completion.provide language.define process.exec exec ].freeze
- LIMITS =
%w[memory_mb request_timeout_ms max_message_bytes max_concurrent_requests startup_timeout_ms].freeze
Instance Attribute Summary collapse
-
#activation ⇒ Array[String]
readonly
Returns the value of attribute activation.
-
#api_version ⇒ Integer
readonly
Returns the value of attribute api_version.
-
#capabilities ⇒ Array[String]
readonly
Returns the value of attribute capabilities.
-
#contributes ⇒ Hash[String, json]
readonly
Returns the value of attribute contributes.
-
#entry ⇒ String
readonly
Returns the value of attribute entry.
-
#id ⇒ String
readonly
Returns the value of attribute id.
-
#limits ⇒ Hash[String, Numeric]
readonly
Returns the value of attribute limits.
-
#name ⇒ String
readonly
Returns the value of attribute name.
-
#root ⇒ String
readonly
Returns the value of attribute root.
-
#version ⇒ String
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Attribute Details
#activation ⇒ Array[String] (readonly)
Returns the value of attribute activation.
27 28 29 |
# File 'sig/gienah.rbs', line 27 def activation @activation end |
#api_version ⇒ Integer (readonly)
Returns the value of attribute api_version.
25 26 27 |
# File 'sig/gienah.rbs', line 25 def api_version @api_version end |
#capabilities ⇒ Array[String] (readonly)
Returns the value of attribute capabilities.
28 29 30 |
# File 'sig/gienah.rbs', line 28 def capabilities @capabilities end |
#contributes ⇒ Hash[String, json] (readonly)
Returns the value of attribute contributes.
29 30 31 |
# File 'sig/gienah.rbs', line 29 def contributes @contributes end |
#entry ⇒ String (readonly)
Returns the value of attribute entry.
26 27 28 |
# File 'sig/gienah.rbs', line 26 def entry @entry end |
#id ⇒ String (readonly)
Returns the value of attribute id.
22 23 24 |
# File 'sig/gienah.rbs', line 22 def id @id end |
#limits ⇒ Hash[String, Numeric] (readonly)
Returns the value of attribute limits.
30 31 32 |
# File 'sig/gienah.rbs', line 30 def limits @limits end |
#name ⇒ String (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'sig/gienah.rbs', line 23 def name @name end |
#root ⇒ String (readonly)
Returns the value of attribute root.
31 32 33 |
# File 'sig/gienah.rbs', line 31 def root @root end |
#version ⇒ String (readonly)
Returns the value of attribute version.
24 25 26 |
# File 'sig/gienah.rbs', line 24 def version @version end |
Class Method Details
.from_hash(value, root: Dir.pwd) ⇒ Manifest
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gienah/manifest.rb', line 25 def from_hash(value, root: Dir.pwd) raise ProtocolError, "manifest must be an object" unless value.is_a?(Hash) value = value.transform_keys(&:to_s) REQUIRED.each { |key| raise ProtocolError, "manifest missing #{key}" unless value.key?(key) } id = text(value["id"], "id") name = text(value["name"], "name") version = text(value["version"], "version") api_version = positive_integer(value["api_version"], "api_version") entry = text(value["entry"], "entry") raise ProtocolError, "entry must be relative" if Pathname.new(entry).absolute? || entry.split(File::SEPARATOR).include?("..") activation = array(value.fetch("activation", []), "activation").map { |item| text(item, "activation") } capabilities = array(value.fetch("capabilities", []), "capabilities").map do |item| capability = text(item, "capability") validate_capability(capability) capability end.uniq.freeze contributes = value.fetch("contributes", {}) raise ProtocolError, "contributes must be an object" unless contributes.is_a?(Hash) limits = validate_limits(value.fetch("limits", {})) new(id, name, version, api_version, entry, activation.freeze, capabilities, deep_freeze(contributes), limits, File.(root.to_s)).freeze end |
.load(path) ⇒ Manifest
16 17 18 19 20 21 22 23 |
# File 'lib/gienah/manifest.rb', line 16 def load(path) path = File.(path.to_s) raise ArgumentError, "manifest does not exist" unless File.file?(path) from_hash(JSON.parse(strip_jsonc(File.binread(path))), root: File.dirname(path)) rescue JSON::ParserError => error raise ProtocolError, "invalid manifest JSON: #{error.}" end |