OSDN Git Service

Move all Context classes into Services
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Thu, 16 Jan 2014 17:03:42 +0000 (19:03 +0200)
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Thu, 16 Jan 2014 17:03:42 +0000 (19:03 +0200)
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
22 files changed:
app/controllers/admin/projects_controller.rb
app/controllers/projects/blob_controller.rb
app/controllers/projects/edit_tree_controller.rb
app/controllers/projects/issues_controller.rb
app/controllers/projects/new_tree_controller.rb
app/controllers/projects/notes_controller.rb
app/controllers/projects_controller.rb
app/controllers/search_controller.rb
app/services/base_service.rb [moved from app/contexts/base_context.rb with 96% similarity]
app/services/files/base_service.rb [moved from app/contexts/files/base_context.rb with 92% similarity]
app/services/files/create_service.rb [moved from app/contexts/files/create_context.rb with 97% similarity]
app/services/files/delete_service.rb [moved from app/contexts/files/delete_context.rb with 96% similarity]
app/services/files/update_service.rb [moved from app/contexts/files/update_context.rb with 96% similarity]
app/services/issues/bulk_update_service.rb [moved from app/contexts/issues/bulk_update_context.rb with 95% similarity]
app/services/notes/create_service.rb [moved from app/contexts/notes/create_context.rb with 80% similarity]
app/services/notes/load_service.rb [moved from app/contexts/notes/load_context.rb with 94% similarity]
app/services/projects/create_service.rb [moved from app/contexts/projects/create_context.rb with 98% similarity]
app/services/projects/fork_service.rb [moved from app/contexts/projects/fork_context.rb with 97% similarity]
app/services/projects/transfer_service.rb [moved from app/contexts/projects/transfer_context.rb with 94% similarity]
app/services/projects/update_service.rb [moved from app/contexts/projects/update_context.rb with 94% similarity]
app/services/search/global_service.rb [moved from app/contexts/search/global_context.rb with 98% similarity]
app/services/search/project_service.rb [moved from app/contexts/search/project_context.rb with 98% similarity]

index 7e3e29f..ea20595 100644 (file)
@@ -19,7 +19,7 @@ class Admin::ProjectsController < Admin::ApplicationController
   end
 
   def transfer
-    result = ::Projects::TransferContext.new(@project, current_user, project: params).execute(:admin)
+    result = ::Projects::TransferService.new(@project, current_user, project: params).execute(:admin)
 
     if result
       redirect_to [:admin, @project]
index fc9807e..2aa7347 100644 (file)
@@ -13,7 +13,7 @@ class Projects::BlobController < Projects::ApplicationController
   end
 
   def destroy
-    result = Files::DeleteContext.new(@project, current_user, params, @ref, @path).execute
+    result = Files::DeleteService.new(@project, current_user, params, @ref, @path).execute
 
     if result[:status] == :success
       flash[:notice] = "Your changes have been successfully committed"
index 3921273..aa46313 100644 (file)
@@ -7,7 +7,7 @@ class Projects::EditTreeController < Projects::BaseTreeController
   end
 
   def update
-    result = Files::UpdateContext.new(@project, current_user, params, @ref, @path).execute
+    result = Files::UpdateService.new(@project, current_user, params, @ref, @path).execute
 
     if result[:status] == :success
       flash[:notice] = "Your changes have been successfully committed"
index 83ff968..770fcca 100644 (file)
@@ -89,7 +89,7 @@ class Projects::IssuesController < Projects::ApplicationController
   end
 
   def bulk_update
-    result = Issues::BulkUpdateContext.new(project, current_user, params).execute
+    result = Issues::BulkUpdateService.new(project, current_user, params).execute
     redirect_to :back, notice: "#{result[:count]} issues updated"
   end
 
index 933a0cb..2f3647a 100644 (file)
@@ -6,7 +6,7 @@ class Projects::NewTreeController < Projects::BaseTreeController
 
   def update
     file_path = File.join(@path, File.basename(params[:file_name]))
-    result = Files::CreateContext.new(@project, current_user, params, @ref, file_path).execute
+    result = Files::CreateService.new(@project, current_user, params, @ref, file_path).execute
 
     if result[:status] == :success
       flash[:notice] = "Your changes have been successfully committed"
index 261841f..9c9c2de 100644 (file)
@@ -5,7 +5,7 @@ class Projects::NotesController < Projects::ApplicationController
   before_filter :authorize_admin_note!, only: [:update, :destroy]
 
   def index
-    @notes = Notes::LoadContext.new(project, current_user, params).execute
+    @notes = Notes::LoadService.new(project, current_user, params).execute
 
     notes_json = { notes: [] }
 
@@ -20,7 +20,7 @@ class Projects::NotesController < Projects::ApplicationController
   end
 
   def create
-    @note = Notes::CreateContext.new(project, current_user, params).execute
+    @note = Notes::CreateService.new(project, current_user, params).execute
 
     respond_to do |format|
       format.json { render_note_json(@note) }
index e1c55e7..6ec109b 100644 (file)
@@ -20,7 +20,7 @@ class ProjectsController < ApplicationController
   end
 
   def create
-    @project = ::Projects::CreateContext.new(current_user, params[:project]).execute
+    @project = ::Projects::CreateService.new(current_user, params[:project]).execute
 
     respond_to do |format|
       flash[:notice] = 'Project was successfully created.' if @project.saved?
@@ -36,7 +36,7 @@ class ProjectsController < ApplicationController
   end
 
   def update
-    status = ::Projects::UpdateContext.new(@project, current_user, params).execute
+    status = ::Projects::UpdateService.new(@project, current_user, params).execute
 
     respond_to do |format|
       if status
@@ -51,7 +51,7 @@ class ProjectsController < ApplicationController
   end
 
   def transfer
-    ::Projects::TransferContext.new(project, current_user, params).execute
+    ::Projects::TransferService.new(project, current_user, params).execute
   end
 
   def show
@@ -89,7 +89,7 @@ class ProjectsController < ApplicationController
   end
 
   def fork
-    @forked_project = ::Projects::ForkContext.new(project, current_user).execute
+    @forked_project = ::Projects::ForkService.new(project, current_user).execute
 
     respond_to do |format|
       format.html do
index ba8f08c..e853c22 100644 (file)
@@ -5,9 +5,9 @@ class SearchController < ApplicationController
 
     if @project
       return access_denied! unless can?(current_user, :download_code, @project)
-      @search_results = Search::ProjectContext.new(@project, current_user, params).execute
+      @search_results = Search::ProjectService.new(@project, current_user, params).execute
     else
-      @search_results = Search::GlobalContext.new(current_user, params).execute
+      @search_results = Search::GlobalService.new(current_user, params).execute
     end
   end
 end
similarity index 96%
rename from app/contexts/base_context.rb
rename to app/services/base_service.rb
index 6accd9b..610f047 100644 (file)
@@ -1,4 +1,4 @@
-class BaseContext
+class BaseService
   attr_accessor :project, :current_user, :params
 
   def initialize(project, user, params)
similarity index 92%
rename from app/contexts/files/base_context.rb
rename to app/services/files/base_service.rb
index 44f9826..f1765d3 100644 (file)
@@ -1,5 +1,5 @@
 module Files
-  class BaseContext < ::BaseContext
+  class BaseService < ::BaseService
     attr_reader :ref, :path
 
     def initialize(project, user, params, ref, path = nil)
similarity index 97%
rename from app/contexts/files/create_context.rb
rename to app/services/files/create_service.rb
index b3d62a0..361bb45 100644 (file)
@@ -1,7 +1,7 @@
 require_relative "base_context"
 
 module Files
-  class CreateContext < BaseContext
+  class CreateService < BaseService
     def execute
       allowed = if project.protected_branch?(ref)
                   can?(current_user, :push_code_to_protected_branches, project)
similarity index 96%
rename from app/contexts/files/delete_context.rb
rename to app/services/files/delete_service.rb
index 39ff7c2..30f1f25 100644 (file)
@@ -1,7 +1,7 @@
 require_relative "base_context"
 
 module Files
-  class DeleteContext < BaseContext
+  class DeleteService < BaseService
     def execute
       allowed = if project.protected_branch?(ref)
                   can?(current_user, :push_code_to_protected_branches, project)
similarity index 96%
rename from app/contexts/files/update_context.rb
rename to app/services/files/update_service.rb
index 556027a..20ca1ff 100644 (file)
@@ -1,7 +1,7 @@
 require_relative "base_context"
 
 module Files
-  class UpdateContext < BaseContext
+  class UpdateService < BaseService
     def execute
       allowed = if project.protected_branch?(ref)
                   can?(current_user, :push_code_to_protected_branches, project)
similarity index 95%
rename from app/contexts/issues/bulk_update_context.rb
rename to app/services/issues/bulk_update_service.rb
index ab38a4f..f72a346 100644 (file)
@@ -1,5 +1,5 @@
 module Issues
-  class BulkUpdateContext < BaseContext
+  class BulkUpdateService < BaseService
     def execute
       update_data = params[:update]
 
similarity index 80%
rename from app/contexts/notes/create_context.rb
rename to app/services/notes/create_service.rb
index 36ea76f..fb87e17 100644 (file)
@@ -1,5 +1,5 @@
 module Notes
-  class CreateContext < BaseContext
+  class CreateService < BaseService
     def execute
       note = project.notes.new(params[:note])
       note.author = current_user
similarity index 94%
rename from app/contexts/notes/load_context.rb
rename to app/services/notes/load_service.rb
index 234e9ac..f7ad7d6 100644 (file)
@@ -1,5 +1,5 @@
 module Notes
-  class LoadContext < BaseContext
+  class LoadService < BaseService
     def execute
       target_type = params[:target_type]
       target_id   = params[:target_id]
similarity index 98%
rename from app/contexts/projects/create_context.rb
rename to app/services/projects/create_service.rb
index 2acb9fb..033be8f 100644 (file)
@@ -1,5 +1,5 @@
 module Projects
-  class CreateContext < BaseContext
+  class CreateService < BaseService
     def initialize(user, params)
       @current_user, @params = user, params.dup
     end
similarity index 97%
rename from app/contexts/projects/fork_context.rb
rename to app/services/projects/fork_service.rb
index fbc6722..2f1c7b1 100644 (file)
@@ -1,5 +1,5 @@
 module Projects
-  class ForkContext < BaseContext
+  class ForkService < BaseService
     include Gitlab::ShellAdapter
 
     def initialize(project, user)
similarity index 94%
rename from app/contexts/projects/transfer_context.rb
rename to app/services/projects/transfer_service.rb
index 3011984..f8e27f6 100644 (file)
@@ -1,5 +1,5 @@
 module Projects
-  class TransferContext < BaseContext
+  class TransferService < BaseService
     def execute(role = :default)
       namespace_id = params[:project].delete(:namespace_id)
       allowed_transfer = can?(current_user, :change_namespace, project) || role == :admin
similarity index 94%
rename from app/contexts/projects/update_context.rb
rename to app/services/projects/update_service.rb
index 94de10d..d9d371d 100644 (file)
@@ -1,5 +1,5 @@
 module Projects
-  class UpdateContext < BaseContext
+  class UpdateService < BaseService
     def execute(role = :default)
       params[:project].delete(:namespace_id)
       # check that user is allowed to set specified visibility_level
similarity index 98%
rename from app/contexts/search/global_context.rb
rename to app/services/search/global_service.rb
index 74e7460..c5ca332 100644 (file)
@@ -1,5 +1,5 @@
 module Search
-  class GlobalContext
+  class GlobalService
     attr_accessor :current_user, :params
 
     def initialize(user, params)
similarity index 98%
rename from app/contexts/search/project_context.rb
rename to app/services/search/project_service.rb
index 690652b..3ebaafc 100644 (file)
@@ -1,5 +1,5 @@
 module Search
-  class ProjectContext
+  class ProjectService
     attr_accessor :project, :current_user, :params
 
     def initialize(project, user, params)