[logaling-commit] logaling/logaling-command [master] Add handling remove personal project(glossary)

Back to archive index

SUZUKI Miho null+****@clear*****
Thu Sep 27 12:06:23 JST 2012


SUZUKI Miho	2012-09-27 12:06:23 +0900 (Thu, 27 Sep 2012)

  New Revision: 610dbc2876db4798279e1653e9cca12795ead8d0
  https://github.com/logaling/logaling-command/commit/610dbc2876db4798279e1653e9cca12795ead8d0

  Merged 43c76e3: Merge pull request #83 from logaling/add-handling-remove-personal-glossary

  Log:
    Add handling remove personal project(glossary)

  Modified files:
    lib/logaling/project.rb
    lib/logaling/repository.rb
    spec/logaling/repository_spec.rb

  Modified: lib/logaling/project.rb (+16 -6)
===================================================================
--- lib/logaling/project.rb    2012-09-21 12:22:18 +0900 (cfe8290)
+++ lib/logaling/project.rb    2012-09-27 12:06:23 +0900 (dc181f5)
@@ -106,12 +106,22 @@ module Logaling
   end
 
   class PersonalProject < Project
-    def self.create(root_path, glossary_name, source_language, target_language, repository=nil)
-      project_name = [glossary_name, source_language, target_language, 'yml'].join('.')
-      project_path = File.join(root_path, project_name)
-      project = PersonalProject.new(project_path, repository)
-      project.initialize_glossary(source_language, target_language)
-      project
+    class << self
+      def create(root_path, glossary_name, source_language, target_language, repository=nil)
+        project_name = [glossary_name, source_language, target_language, 'yml'].join('.')
+        project_path = File.join(root_path, project_name)
+        project = PersonalProject.new(project_path, repository)
+        project.initialize_glossary(source_language, target_language)
+        project
+      end
+
+      def remove(root_path, glossary_name, source_language, target_language, repository=nil)
+        project_name = [glossary_name, source_language, target_language, 'yml'].join('.')
+        project_path = File.join(root_path, project_name)
+        project = PersonalProject.new(project_path, repository)
+        FileUtils.rm_rf(project_path, :secure => true)
+        project
+      end
     end
 
     def name

  Modified: lib/logaling/repository.rb (+11 -0)
===================================================================
--- lib/logaling/repository.rb    2012-09-21 12:22:18 +0900 (51a0184)
+++ lib/logaling/repository.rb    2012-09-27 12:06:23 +0900 (d39b8e9)
@@ -51,6 +51,17 @@ module Logaling
       PersonalProject.create(personal_glossary_root_path, project_name, source_language, target_language, self)
     end
 
+    def remove_personal_project(project_name, source_language, target_language)
+      unless glossary_exists?(project_name, source_language, target_language)
+        raise Logaling::GlossaryNotFound, "The glossary '#{project_name}' not found."
+      end
+      PersonalProject.remove(personal_glossary_root_path, project_name, source_language, target_language, self)
+    rescue Logaling::GlossaryNotFound => e
+      raise e
+    rescue
+      raise Logaling::CommandFailed, "Failed remove the glossary #{project_name}."
+    end
+
     def import(glossary_source)
       FileUtils.mkdir_p(cache_path)
       Dir.chdir(cache_path) do

  Modified: spec/logaling/repository_spec.rb (+30 -0)
===================================================================
--- spec/logaling/repository_spec.rb    2012-09-21 12:22:18 +0900 (5bfddc7)
+++ spec/logaling/repository_spec.rb    2012-09-27 12:06:23 +0900 (5bdf15b)
@@ -169,6 +169,36 @@ module Logaling
       end
     end
 
+    describe "#remove_personal_project" do
+      let(:rm_glossary_name) { "rm_personal_project" }
+      let(:rm_source_language) { "en" }
+      let(:rm_target_language) { "ja" }
+      before do
+        FileUtils.rm_rf(File.join(logaling_home, 'personal'), :secure => true)
+        repository.create_personal_project(rm_glossary_name, rm_source_language, rm_target_language)
+      end
+
+      context "when target personal project exists" do
+        before do
+          repository.remove_personal_project(rm_glossary_name, rm_source_language, rm_target_language)
+          @projects = repository.projects
+        end
+
+        it "should remove personal project" do
+          @projects.size.should == 1
+        end
+      end
+
+      context "when target personal project not exist" do
+        it "should raise Logaling::GlossaryNotFound" do
+          @name = rm_glossary_name + "foo"
+          lambda{
+            repository.remove_personal_project(@name, rm_source_language, rm_target_language)
+          }.should raise_error(Logaling::GlossaryNotFound)
+        end
+      end
+    end
+
     after do
       FileUtils.rm_rf(File.join(logaling_home, 'projects', 'spec'), :secure => true)
     end
-------------- next part --------------
An HTML attachment was scrubbed...
Download 



More information about the logaling-commit mailing list
Back to archive index