Refactoring

This commit is contained in:
uu59 2014-06-19 16:56:12 +09:00
parent c101f15b6b
commit 81acdd9067
12 changed files with 17 additions and 30 deletions

4
.gitignore vendored
View File

@ -26,5 +26,5 @@
/Gemfile.plugins
/db/user.txt
/db/fluentd.json
/db/*-user.txt
/db/*-fluentd.json

View File

@ -46,7 +46,7 @@ class ApplicationController < ActionController::Base
private
def find_fluentd
@fluentd = Fluentd.find(params[:fluentd_id])
@fluentd = Fluentd.factory
end
def set_locale

View File

@ -1,13 +1,8 @@
class FluentdController < ApplicationController
before_action :find_fluentd, only: [:edit, :update, :destroy]
def index
@fluentds = Fluentd.all
end
def show
@fluentds = Fluentd.all
render "index"
@fluentds = [Fluentd.factory].compact
end
def new
@ -44,7 +39,7 @@ class FluentdController < ApplicationController
private
def find_fluentd
@fluentd = Fluentd.find(params[:id])
@fluentd = Fluentd.factory
end
def fluentd_params

View File

@ -27,8 +27,7 @@ class TutorialsController < ApplicationController
end
def find_fluentd
# NOTE: use first fluentd for tutorial
@fluentd = Fluentd.first
@fluentd = Fluentd.factory
end
def check_ready

View File

@ -116,17 +116,7 @@ class Fluentd
end
def self.exists?
File.exists?(JSON_PATH)
end
def self.all
[factory].compact
end
def self.find(id)
factory
end
# ActiveRecord mimic
def self.factory
return unless exists?
@ -134,6 +124,10 @@ class Fluentd
Fluentd.new(attr)
end
def self.exists?
File.exists?(JSON_PATH)
end
def update_attributes(params)
params.each_pair do |k, v|
send("#{k}=", v)
@ -142,7 +136,6 @@ class Fluentd
def save
return false unless valid?
self.id = 1
json = COLUMNS.inject({}) do |result, col|
result[col] = send(col)
result

View File

@ -10,7 +10,7 @@ class User
has_secure_password
ENCRYPTED_PASSWORD_FILE = Rails.env.test? ? "tmp/test.txt" : Rails.root + "db/user.txt"
ENCRYPTED_PASSWORD_FILE = Rails.root + "db/#{Rails.env}-user.txt"
attr_accessor :name, :password, :password_confirmation, :current_password

View File

@ -1,3 +1,3 @@
- page_title t('.page_title')
= render partial: "form", locals: { btn: t(".create"), url: fluentd_index_path, method: :post }
= render partial: "form", locals: { btn: t(".create"), url: fluentd_path, method: :post }

View File

@ -10,7 +10,7 @@
= t('.step1')
- else
= icon('fa-warning text text-danger')
= link_to t('.step1'), fluentd_index_path
= link_to t('.step1'), fluentd_path
%li
- if @fluentd && @fluentd.agent.running?
= icon('fa-check text text-success')

View File

@ -89,7 +89,7 @@ en:
finish: Update config
form:
<<: *fluentd_common
index:
show:
<<: *fluentd_common
page_title: fluentd
new:

View File

@ -89,7 +89,7 @@ ja:
finish: 設定する
form:
<<: *fluentd_common
index:
show:
<<: *fluentd_common
page_title: fluentd
new:

View File

@ -1,5 +1,5 @@
Rails.application.routes.draw do
root "fluentd#index" # TODO: change to dashboard
root "fluentd#show" # TODO: change to dashboard
resource :fluentd, controller: :fluentd do
resource :agent, only: [:show], module: :fluentd do