Fix plugins handling

This commit is contained in:
uu59 2014-07-28 15:28:59 +09:00
parent f69652cfd6
commit a9ab6c1270
4 changed files with 17 additions and 7 deletions

View File

@ -30,9 +30,15 @@ class PluginsController < ApplicationController
end
def upgrade
pl = Plugin.new(gem_name: params[:plugins][:name])
pl.uninstall! if pl.installed?
GemInstaller.new.async.perform(params[:plugins][:name], params[:plugins][:version])
redirect_to plugins_path
end
def bulk_upgrade
params[:plugins].each do |gem_name|
pl = Plugin.new(gem_name: gem_name)
GemInstaller.new.async.perform(gem_name, pl.latest_version)
end
redirect_to plugins_path
end
end

View File

@ -78,7 +78,7 @@ class Plugin
def inspect
self.version ||= latest_version
%Q|<"#{gem_name}", "#{version}">|
%Q|<#{gem_name}, "#{version}">|
end
def rubygems_org_page
@ -88,9 +88,12 @@ class Plugin
def self.installed
Rails.cache.fetch("installed_gems", expires_in: 3.seconds) do
Bundler.with_clean_env do
`#{fluent_gem_path} list`.lines.grep(/fluent-plugin/).map do |gem|
name, version = gem.strip.split(" (")
new(gem_name: name, version: version.gsub(/\)$/, ""))
gems = `#{fluent_gem_path} list`.try(:lines)
return [] unless gems
gems.grep(/fluent-plugin/).map do |gem|
name, versions_str = gem.strip.split(" ")
version = versions_str[/[^(), ]+/]
new(gem_name: name, version: version)
end
end
end

View File

@ -3,7 +3,7 @@
- unless @plugins.present?
= t('.no_updates')
- else
= form_tag(install_plugins_path, method: :patch) do
= form_tag(bulk_upgrade_plugins_path, method: :patch) do
%table{class: "table table-striped table-hover"}
%tr
%th.col-lg-2= t('.name')

View File

@ -55,6 +55,7 @@ Rails.application.routes.draw do
patch :install
patch :uninstall
patch :upgrade
patch :bulk_upgrade
end
end