respond_with_service 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/respond_with_service/version.rb +1 -1
- data/lib/respond_with_service.rb +38 -25
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 615c8cf97c2d913c74d400f0db7fc7b2a820c614
|
4
|
+
data.tar.gz: 87fb94a1c510b5f0a01f5b7d7418d4ff342542a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d5952470e6984148cffe18da6005d796bf6987369b040ab5f1abace542264cb2f3bf0232d4341318518de4340a72dc3de408ede3434a06609324099c4d57145
|
7
|
+
data.tar.gz: be692bdf2ecfb35382f9521bf764968c33c7531518be70b1b375fe74c427b829decd9ad603858bde4bd9f250546ea7dcc8b30cb129c50160297edc9dd39c3e33
|
data/lib/respond_with_service.rb
CHANGED
@@ -13,43 +13,56 @@ module AccountModuleService
|
|
13
13
|
module InstanceMethods
|
14
14
|
private
|
15
15
|
|
16
|
-
def redirect_to_after_call
|
17
|
-
if
|
16
|
+
def redirect_to_after_call
|
17
|
+
if @service_instance.call
|
18
18
|
flash[:notice] = 'Successfully update'
|
19
|
-
|
20
|
-
redirect_to [fail_path, :admin, model_instance]
|
19
|
+
redirect_to [:admin, @model_instance.class.to_s.underscore.pluralize]
|
21
20
|
else
|
22
21
|
# TODO notice errors ap create_account_service.errors
|
23
|
-
|
22
|
+
flash[:error] = 'something went wrong'
|
23
|
+
if @fail_path == :new
|
24
|
+
redirect_to [@fail_path, :admin, @model_instance.class.to_s.underscore]
|
25
|
+
else
|
26
|
+
redirect_to [@fail_path, :admin, @model_instance]
|
27
|
+
end
|
24
28
|
end
|
25
29
|
end
|
30
|
+
|
31
|
+
def find_model_instance class_name
|
32
|
+
# TODO model can be conf
|
33
|
+
model = Object.const_get class_name
|
34
|
+
case params[:action].to_sym
|
35
|
+
when :create
|
36
|
+
@model_instance = model.new
|
37
|
+
@fail_path = :new
|
38
|
+
when :update
|
39
|
+
@model_instance = model.find params[:id]
|
40
|
+
@fail_path = :edit
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def find_service_instance
|
45
|
+
service = Object.const_get(@model_instance.class.to_s)
|
46
|
+
.const_get "#{params[:action].capitalize}#{@model_instance.class}Service"
|
47
|
+
@service_instance = service.new params, @model_instance
|
48
|
+
end
|
26
49
|
end
|
27
50
|
|
28
51
|
module ClassMethods
|
29
52
|
def respond_with_service class_name, conf
|
30
53
|
conf[:actions].each do |action|
|
31
|
-
|
32
|
-
model = Object.const_get class_name
|
33
|
-
#service = Object.const_get "#{class_name}Service"
|
34
|
-
define_method action do
|
35
|
-
case action
|
36
|
-
when :create
|
37
|
-
model_instance = model.new
|
38
|
-
fail_path = :new
|
39
|
-
service = Object.const_get(class_name)
|
40
|
-
.const_get "Create#{class_name}Service"
|
41
|
-
when :update
|
42
|
-
model_instance = model.find params[:id]
|
43
|
-
fail_path = :edit
|
44
|
-
service = Object.const_get(class_name)
|
45
|
-
.const_get "Update#{class_name}Service"
|
46
|
-
end
|
47
|
-
service_instance = service.new params, model_instance
|
48
|
-
redirect_to_after_call service_instance,
|
49
|
-
model_instance, fail_path
|
50
|
-
end
|
54
|
+
self.create_action action, class_name
|
51
55
|
end
|
52
56
|
end
|
57
|
+
|
58
|
+
def create_action action, class_name
|
59
|
+
define_method action do
|
60
|
+
find_model_instance class_name
|
61
|
+
find_service_instance
|
62
|
+
redirect_to_after_call
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
53
66
|
end
|
54
67
|
end
|
55
68
|
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: respond_with_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre-Alexandre Piarulli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|