Refactor logic in view using decorator.

This commit is contained in:
hassaku 2014-09-30 22:07:52 +09:00
parent 3ae454566c
commit 4e959c1fd2
4 changed files with 16 additions and 7 deletions

View File

@ -8,7 +8,7 @@ class PluginsController < ApplicationController
end
def recommended
@plugins = Plugin.recommended
@plugins = PluginDecorator.decorate_collection(Plugin.recommended)
end
def updated

View File

@ -0,0 +1,13 @@
class PluginDecorator < Draper::Decorator
delegate_all
def status
if installed?
I18n.t("terms.installed")
elsif processing?
I18n.t("terms.processing")
else
I18n.t("terms.not_installed")
end
end
end

View File

@ -8,6 +8,7 @@ class Plugin
WORKING = []
include ActiveModel::Model
include Draper::Decoratable
attr_accessor :gem_name, :version, :category
validates :gem_name, presence: true

View File

@ -20,12 +20,7 @@
%td
= plugin.category
%td
- if plugin.installed?
= t("terms.installed")
- elsif plugin.processing?
= t("terms.processing")
- else
= t("terms.not_installed")
= plugin.status
%td
= link_to t('plugins.view_on_rubygems_org'), plugin.rubygems_org_page, target: "_blank"