Module: Jax::Generators::Plugin
- Included in:
- PluginGenerator, PluginManager
- Defined in:
- lib/jax/generators/plugin/all.rb,
lib/jax/generators/plugin/plugin_manager.rb,
lib/jax/generators/plugin/plugin_generator.rb
Defined Under Namespace
Classes: Credentials, PluginGenerator, PluginManager, ResponseError
Instance Method Summary
collapse
Instance Method Details
#each_plugin(name = nil, &block) ⇒ Object
80
81
82
|
# File 'lib/jax/generators/plugin/all.rb', line 80
def each_plugin(name = nil, &block)
matching_plugins(name).each &block
end
|
100
101
102
103
104
105
106
|
# File 'lib/jax/generators/plugin/all.rb', line 100
def (response)
begin
hash = Hash.from_xml(response)
rescue
raise ResponseError.new("Fatal: response couldn't be parsed. (Maybe it wasn't valid XML?)")
end
end
|
#find_plugin_list(hash_containing_plugin_list) ⇒ Object
65
66
67
68
69
|
# File 'lib/jax/generators/plugin/all.rb', line 65
def find_plugin_list(hash_containing_plugin_list)
hash_containing_plugin_list['jax_plugins'] ||
hash_containing_plugin_list['nil_classes'] ||
raise(ResponseError.new("Fatal: couldn't find plugin list."))
end
|
#get_remote_plugins_matching(name = nil) ⇒ Object
71
72
73
74
75
76
77
78
|
# File 'lib/jax/generators/plugin/all.rb', line 71
def get_remote_plugins_matching(name = nil)
plugins = rest_resource("plugins")
if name
plugins['search'][name].get
else
plugins.get
end
end
|
#installed_plugin_manifests(filter_name = nil) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/jax/generators/plugin/all.rb', line 48
def installed_plugin_manifests(filter_name = nil)
{ 'jax_plugins' => search(installed_plugins, filter_name).collect do |name, path|
load_or_infer_manifest(name, path)
end
}
end
|
#installed_plugins ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/jax/generators/plugin/all.rb', line 30
def installed_plugins
plugins = []
Dir.glob(Jax.root.join("vendor/plugins/*").to_s).each do |path|
if File.directory? path
plugins.push [File.basename(path), Pathname.new(path)]
end
end
plugins.sort { |a, b| a[0] <=> b[0] }
end
|
#load_or_infer_manifest(name, plugin_dir) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/jax/generators/plugin/all.rb', line 40
def load_or_infer_manifest(name, plugin_dir)
if File.file?(manifest_path = File.join(plugin_dir, "manifest.yml"))
YAML::load(File.read(manifest_path)) || { 'name' => name, 'description' => '(Description unavailable)' }
else
{ 'name' => name, 'description' => '(Manifest file not found!)' }
end
end
|
#matching_plugins(name = nil) ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'lib/jax/generators/plugin/all.rb', line 55
def matching_plugins(name = nil)
if options[:local]
hash = installed_plugin_manifests(name)
else
hash = get_remote_plugins_matching name
end
find_plugin_list(hash)
end
|
#plugin_version(details) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/jax/generators/plugin/all.rb', line 84
def plugin_version(details)
if options['version']
for release in details['releases']
if release['version'] && release['version'] == options['version']
return options['version']
end
end
raise "Release information for version #{options['version']} not found for plugin '#{details['name']}'!"
else
if release = details['releases'].last and release['version']
return release['version']
end
raise "Release information not found for plugin '#{details['name']}'!"
end
end
|
#rest_resource(name, accept = :xml) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/jax/generators/plugin/all.rb', line 10
def rest_resource(name, accept = :xml)
url = Jax.plugin_repository_url
url.concat "/" unless url =~ /\/$/
url.concat name
RestClient::Resource.new(url, :accept => accept)
end
|
#search(plugin_list, query) ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/jax/generators/plugin/all.rb', line 21
def search(plugin_list, query)
plugin_list.select { |plugin, path_to_plugin|
!query || plugin =~ search_query_rx(query)
}.inject({}) do |hash, (plugin, path_to_plugin)|
hash[plugin] = path_to_plugin
hash
end
end
|
#search_query_rx(query) ⇒ Object
17
18
19
|
# File 'lib/jax/generators/plugin/all.rb', line 17
def search_query_rx(query)
/^#{Regexp::escape query}/i
end
|