Skip to content

Commit

Permalink
Added class to store the selected files in a yaml file located in the…
Browse files Browse the repository at this point in the history
… tmp directory.

Removed the AR session configuration and removed the database migration for it.
  • Loading branch information
Matthew Savage authored and Matthew Savage committed Aug 15, 2009
1 parent 8de3a7c commit 83c948d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 47 deletions.
26 changes: 21 additions & 5 deletions app/controllers/editor_controller.rb
@@ -1,6 +1,8 @@
require 'ftools'

class EditorController < ApplicationController
before_filter :get_files, :except => [:choose_directory, :select_files, :set_files]

def choose_directory
end

Expand All @@ -20,7 +22,7 @@ def set_files
redirect_to "/editor/choose_directory" and return
end

session[:files] = params[:selected_files]
FileListStore.store_files params[:selected_files]
# Backup files!
params[:selected_files].each do |file|
File.copy(file, "#{file}.backup")
Expand All @@ -32,11 +34,17 @@ def set_files
redirect_to "/editor/show_translations"
end

def clear_selected_files
FileListStore.clear_files
flash[:notice] = "The selected file list has been cleared."
redirect_to "/editor/choose_directory"
end

def show_translations
@translations = {}

files = session[:files]
files.each do |file|

@files.each do |file|
yaml = YAML.load_file(file)
@translations.merge!(yaml)
end
Expand Down Expand Up @@ -101,8 +109,7 @@ def index

private
def manipulate_files
files = session[:files]
files.each do |file|
@files.each do |file|
yaml = YAML.load_file file
yaml.each_pair do |lang, translations|
yield lang, translations
Expand All @@ -113,4 +120,13 @@ def manipulate_files
end
end
end

def get_files
begin
@files = FileListStore.get_files
rescue
flash[:notice] = "Couldn't find the list of files selected - please start again."
redirect_to "/editor/choose_directory" and return
end
end
end
3 changes: 1 addition & 2 deletions config/initializers/session_store.rb
Expand Up @@ -11,5 +11,4 @@

# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rake db:sessions:create")
ActionController::Base.session_store = :active_record_store
# (create the session table with "rake db:sessions:create")
16 changes: 0 additions & 16 deletions db/migrate/20090815164634_create_sessions.rb

This file was deleted.

24 changes: 0 additions & 24 deletions db/schema.rb
@@ -1,24 +0,0 @@
# This file is auto-generated from the current state of the database. Instead of editing this file,
# please use the migrations feature of Active Record to incrementally modify your database, and
# then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
# to create the application database on another system, you should be using db:schema:load, not running
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20090815164634) do

create_table "sessions", :force => true do |t|
t.string "session_id", :null => false
t.text "data"
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"

end
15 changes: 15 additions & 0 deletions lib/file_list_store.rb
@@ -0,0 +1,15 @@
class FileListStore
def self.get_files
f = YAML.load_file("#{RAILS_ROOT}/tmp/selected_files.yml")
end

def self.store_files(files)
File.open("#{RAILS_ROOT}/tmp/selected_files.yml", "w") do |out|
YAML.dump(files, out)
end
end

def self.clear_files
File.delete "#{RAILS_ROOT}/tmp/selected_files.yml"
end
end

0 comments on commit 83c948d

Please sign in to comment.