multi-updator 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ .rvmrc
@@ -1 +1 @@
1
- require 'multi-updator/routes'
1
+ require 'multi-updator/routes.rb'
@@ -0,0 +1,45 @@
1
+ class ApplicationController
2
+ def multi_update
3
+
4
+ delete_list, update_list, create_list = [], [], [];
5
+
6
+ params[:multiple_data].each do |index, single_data|
7
+ destroy_flag = single_data.delete(:_destroy)
8
+
9
+ if(destroy_flag == "1")
10
+ delete_list << single_data[:id]
11
+ else
12
+ if(single_data[:id])
13
+ update_list << single_data
14
+ else
15
+ create_list << single_data
16
+ end
17
+ end
18
+ end
19
+
20
+ # 1. delete
21
+ resource_class.destroy(delete_list) unless delete_list.empty?
22
+
23
+ # 2. update
24
+ update_list.each do |single_data|
25
+ # TODO resource_class.find 로 찾을 수 없는 경우 - entry_service 같은 경우에 대한 대응이 필요하다.
26
+ # ...
27
+ data = resource_class.find(single_data.delete(:id))
28
+ update_resource(data, single_data)
29
+ end
30
+
31
+ # 3. create
32
+ create_list.each do |single_data|
33
+ #data = build_resource(single_data)
34
+ #data.save
35
+ single_data[:domain_id] = @domain.id
36
+ resource_class.create!(single_data)
37
+ end
38
+
39
+ respond_to do |format|
40
+ format.html { redirect_to(collection_url) }
41
+ format.xml { head :ok }
42
+ format.json { render :json => {"Multi-Update" => "OK"} }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,40 @@
1
+ ActionDispatch::Routing::Mapper::Resources::Resource.class_eval do
2
+ self::NEW_DEFAULT_ACTIONS = (self::DEFAULT_ACTIONS << [:select, :multi_update]).flatten!
3
+
4
+ def default_actions
5
+ self.class::NEW_DEFAULT_ACTIONS
6
+ end
7
+ end
8
+
9
+ ActionDispatch::Routing::Mapper::Resources.class_eval do
10
+ def resources(*resources, &block)
11
+ options = resources.extract_options!
12
+
13
+ if apply_common_behavior_for(:resources, resources, options, &block)
14
+ return self
15
+ end
16
+
17
+ resource_scope(Resource.new(resources.pop, options)) do
18
+ yield if block_given?
19
+
20
+ collection do
21
+ get :index if parent_resource.actions.include?(:index)
22
+ post :create if parent_resource.actions.include?(:create)
23
+ put :multi_update if parent_resource.actions.include?(:multi_update)
24
+ end
25
+
26
+ new do
27
+ get :new
28
+ end if parent_resource.actions.include?(:new)
29
+
30
+ member do
31
+ get :edit if parent_resource.actions.include?(:edit)
32
+ get :show if parent_resource.actions.include?(:show)
33
+ put :update if parent_resource.actions.include?(:update)
34
+ delete :destroy if parent_resource.actions.include?(:destroy)
35
+ end
36
+ end
37
+
38
+ self
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  module Rotorua
2
2
  module MultiUpdator
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - shnam
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-12 00:00:00 +09:00
17
+ date: 2011-01-13 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -32,6 +32,8 @@ files:
32
32
  - Gemfile
33
33
  - Rakefile
34
34
  - lib/multi-updator.rb
35
+ - lib/multi-updator/application_controller.rb
36
+ - lib/multi-updator/routes.rb
35
37
  - lib/multi-updator/version.rb
36
38
  - multi-updator.gemspec
37
39
  has_rdoc: true