[logaling-commit] logaling/logaling-server [enable-creating-user-glossary] Remove unneccesary code

Zurück zum Archiv-Index

SHIMADA Koji null+****@clear*****
Fri Sep 21 10:38:49 JST 2012


SHIMADA Koji	2012-09-21 10:38:49 +0900 (Fri, 21 Sep 2012)

  New Revision: 4b1e01964099b8715b05341c5a7fbcb400101e4a
  https://github.com/logaling/logaling-server/commit/4b1e01964099b8715b05341c5a7fbcb400101e4a

  Log:
    Remove unneccesary code
    
    checking bilingual_pair_exists move into glossary api
    (https://github.com/logaling/logaling-command/commit/192b23640c9f219a4bda161d40ef1e6f9ac25e76)
    so remove them.
    
    and clarify the exception.

  Modified files:
    app/controllers/terms_controller.rb
    app/models/user_glossary.rb

  Modified: app/controllers/terms_controller.rb (+7 -7)
===================================================================
--- app/controllers/terms_controller.rb    2012-09-21 09:31:15 +0900 (d8b0f89)
+++ app/controllers/terms_controller.rb    2012-09-21 10:38:49 +0900 (e897408)
@@ -11,8 +11,7 @@ class TermsController < ApplicationController
     @user_glossary.add!(@term)
 
     redirect_to user_glossary_path(current_user, @user_glossary), notice: 'Term was successfully added.'
-  rescue => e
-    @term.errors.add(:source_term, e) if****@term*****?
+  rescue ArgumentError, Logaling::GlossaryNotFound
     render action: "new"
   end
 
@@ -21,20 +20,21 @@ class TermsController < ApplicationController
   end
 
   def update
-    @term = Term.find(params[:id])
+    @term = Term.load(params[:id], @user_glossary)
     new_term = Term.new(params[:term])
     @user_glossary.update(@term, new_term)
+
     redirect_to user_glossary_path(current_user, @user_glossary), notice: 'Term was successfully updated.'
-  rescue => e
-    @term.errors.add(:target_term, e) if****@term*****?
+  rescue ArgumentError, Logaling::GlossaryNotFound
     render action: "edit"
   end
 
   def destroy
-    @term = Term.find(params[:id])
+    @term = Term.load(params[:id], @user_glossary)
     @user_glossary.delete(@term)
+
     redirect_to user_glossary_path(current_user, @user_glossary), notice: 'Term was successfully destroyed.'
-  rescue => e
+  rescue ArgumentError, Logaling::GlossaryNotFound
     redirect_to user_glossary_path(current_user, @user_glossary), notice: e.to_s
   end
 

  Modified: app/models/user_glossary.rb (+16 -15)
===================================================================
--- app/models/user_glossary.rb    2012-09-21 09:31:15 +0900 (4f11532)
+++ app/models/user_glossary.rb    2012-09-21 10:38:49 +0900 (846b6eb)
@@ -14,45 +14,46 @@ class UserGlossary < ActiveRecord::Base
   end
 
   def add!(term)
-    raise Logaling::TermError unless term.valid?
+    raise ArgumentError unless term.valid?
 
     glossary = find_glossary
     raise Logaling::GlossaryNotFound unless glossary
 
-    if glossary.bilingual_pair_exists?(term.source_term, term.target_term)
-      raise Logaling::TermError, "term '#{term.source_term}: #{term.target_term}' already exists in '#{name}'"
-    end
-
     glossary.add(term.source_term, term.target_term, term.note)
     LogalingServer.repository.index
+
+  rescue Logaling::TermError
+    term.errors.add(:source_term, "term '#{term.source_term}: #{term.target_term}' already exists in '#{name}'")
+    raise ArgumentError
   end
 
   def update(term, new_term)
-    raise Logaling::TermError unless new_term.valid?
+    return if term == new_term
+    raise ArgumentError unless new_term.valid?
 
     glossary = find_glossary
     raise Logaling::GlossaryNotFound unless glossary
 
-    if glossary.bilingual_pair_exists?(term.source_term, new_term.target_term, new_term.note)
-      raise Logaling::TermError, "term '#{term.source_term}: #{new_term.target_term}' already exists in '#{name}'"
-    end
-
     glossary.update(term.source_term, term.target_term, new_term.target_term, new_term.note)
     LogalingServer.repository.index
+
+  rescue Logaling::TermError
+    term.errors.add(:target_term, "term '#{term.source_term}: #{new_term.target_term}' already exists in '#{name}'")
+    raise ArgumentError
   end
 
   def delete(term)
-    raise Logaling::TermError unless term.valid?
+    raise ArgumentError unless term.valid?
 
     glossary = find_glossary
     raise Logaling::GlossaryNotFound unless glossary
 
-    unless glossary.bilingual_pair_exists?(term.source_term, term.target_term)
-      raise Logaling::TermError, "term '#{term.source_term}: #{term.target_term}' doesn't exist in '#{name}'"
-    end
-
     glossary.delete(term.source_term, term.target_term)
     LogalingServer.repository.index
+
+  rescue Logaling::TermError
+    term.errors.add(:target_term, "term '#{term.source_term}: #{term.target_term}' doesn't exists in '#{name}'")
+    raise ArgumentError
   end
 
   def find_bilingual_pair(soruce_term, target_term)
-------------- next part --------------
An HTML attachment was scrubbed...
Download 



More information about the logaling-commit mailing list
Zurück zum Archiv-Index