rescue-dog 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea1931c553f09ed1cf0e12f65479dbbc0a949d76
4
- data.tar.gz: 49b18603085618a2120933598e512d0e9a3c1491
3
+ metadata.gz: 04a759ce546669df119ad51af2b97b93a417db88
4
+ data.tar.gz: 6ec7e0fef288002684edc508f39baadf6fd1ba39
5
5
  SHA512:
6
- metadata.gz: 27f9b874868af6234c7a1ca9cdb4d7e0b7d597e100303991b554e2ece7d20c0441db504593c2f2b647fea7414caab95d64d22349d9a9c41d577f27798a553a6f
7
- data.tar.gz: 788415d867e62f4083d66675aba84476ae5458c3da8024851c3b991b0b9215d56edb66a1e14e89b493f173f52697d26a00342b7d85fc7d5d1f3321a32407feff
6
+ metadata.gz: 3c506070a73c70ef41bfb5049e0f217b16b2c424a37c268e9656d3b730196a9db5b42e1bf92f92cb99702695350e92b5007148de909769fa0aedfe2f5d8b2334
7
+ data.tar.gz: 618a85f1e3f2b7f1f4f1df03e776c54072746bea2e80a00b83485e52da43253e1b658aa641b32bdcf0023ec3a5fc3062df940e6533a7385c7a4fa66d834e5b6d
@@ -45,26 +45,21 @@ module Rescue
45
45
  Parameter.define(self)
46
46
  Action.define(self, clazz, var_sym, params_sym)
47
47
 
48
- [:new].each do |type|
48
+ [:new, :edit, :show, :create, :update, :delete].each do |type|
49
49
  args = options.delete(type) || (actions.delete(type) ? {} : nil)
50
- define_action_method(type, :new_call, args) if args
51
- end
52
-
53
- [:show, :edit].each do |type|
54
- args = options.delete(type) || (actions.delete(type) ? {} : nil)
55
- define_action_method(type, :find_call, args) if args
56
- end
57
-
58
- [:create, :update, :delete].each do |type|
59
- args = options.delete(type) || (actions.delete(type) ? {} : nil)
60
- if args
61
- args[:flash] ||= true
62
- define_action_method(type, :"#{type}_call", args) if args
63
- end
50
+ define_action_method(type, args) if args
64
51
  end
65
52
  end
66
53
 
67
- def define_action_method name, call_method, options = {}
54
+ def define_action_method name, options = {}
55
+ raise RuntimeError "`name` is already defined." if method_defined?(name)
56
+ options[:type] ||= name
57
+ options[:flash] ||= [:create, :update, :delete].include?(options[:type])
58
+ call_method = case options[:type]
59
+ when :show, :edit ; :find_call
60
+ else ; :"#{options[:type]}_call"
61
+ end
62
+ rescue_given = options[:rescue]||options[:error]||options[:flash]
68
63
  success_message = options[:success]
69
64
  error_message = options[:error]
70
65
  if options[:flash]
@@ -72,14 +67,21 @@ module Rescue
72
67
  error_message ||= Flash.message(self, name, :error)
73
68
  end
74
69
 
75
- define_method name do
76
- begin
70
+ if rescue_given
71
+ define_method name do
72
+ begin
73
+ send(call_method)
74
+ flash[:success] = success_message unless success_message.blank?
75
+ instance_exec(&options[:render]) if options[:render]
76
+ rescue
77
+ flash.now[:error] = error_message unless error_message.blank?
78
+ instance_exec(&options[:rescue]) if options[:rescue]
79
+ end
80
+ end
81
+ else
82
+ define_method name do
77
83
  send(call_method)
78
- flash[:success] = success_message unless success_message.blank?
79
84
  instance_exec(&options[:render]) if options[:render]
80
- rescue
81
- flash.now[:error] = error_message unless error_message.blank?
82
- instance_exec(&options[:rescue]) if options[:rescue]
83
85
  end
84
86
  end
85
87
  end
@@ -8,7 +8,7 @@ module Rescue
8
8
  instance_variable_set(var_sym, clazz.new)
9
9
  end
10
10
  object.send(:define_method, :find_call) do
11
- id = find_params[Rescue.config.primary_key]
11
+ id = find_params[Rescue.config.primary_key]
12
12
  instance_variable_set(var_sym, clazz.find(id))
13
13
  end
14
14
  object.send(:define_method, :create_call) do
@@ -1,3 +1,3 @@
1
1
  module Rescue
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rescue-dog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yulii
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-08 00:00:00.000000000 Z
11
+ date: 2013-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails