Class: PluginPackParser

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/plugin/plugin_pack.rb

Class Method Summary collapse

Class Method Details

.parse_pack_meta(pack_spec) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/commands/plugin/plugin_pack.rb', line 51

def self.parse_pack_meta(pack_spec)
  pack_meta = {}
  return pack_meta if pack_spec['about'].nil?
  pack_spec['about'].children_with_index.each do |meta|
    key = meta[1].value
    value = pack_spec['about'][key].value
    pack_meta[key] = value
  end
  pack_meta
end

.parse_pack_plugins(pack_spec) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/commands/plugin/plugin_pack.rb', line 62

def self.parse_pack_plugins(pack_spec)
  plugins = {}
  return plugins if pack_spec['plugins'].nil? or pack_spec['plugins'].children.nil?
  pack_spec['plugins'].children_with_index.each do |p|
    name = p[1].value
    next if pack_spec['plugins'][name].nil?
    source = pack_spec['plugins'][name].value
    plugins[name] = source
  end
  plugins
end

.parse_spec(spec) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/commands/plugin/plugin_pack.rb', line 35

def self.parse_spec(spec)
  pack_spec = YAML.parse(spec)
  pack_meta = self.parse_pack_meta(pack_spec)
  pack_plugins = self.parse_pack_plugins(pack_spec)
  return nil if pack_plugins.empty?
  pack_name = pack_meta.delete('name') || 'Untitled Pack'
  pack = PluginPack.new(pack_name)
  pack_meta.each_pair { |key, value| pack.send("#{key}=", value) if pack.respond_to?(key) }
  pack_plugins.each_pair { |name, source| pack.add_plugin(name, source) }
  pack
end

.parse_spec_file(spec_file_or_url) ⇒ Object



47
48
49
# File 'lib/commands/plugin/plugin_pack.rb', line 47

def self.parse_spec_file(spec_file_or_url)
  self.parse_spec(open(spec_file_or_url))
end