transponder 0.9.3 → 0.9.4

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: 0fec12d7a52b2396ec3e8111eebdb23179dfe192
4
- data.tar.gz: e0b9e960e3c27dc644a9a0fd4ad542a746bc5c61
3
+ metadata.gz: ae5313ea40c13eddf346a725c50263a3e021f940
4
+ data.tar.gz: 867c027783309a27f902b128e41eb3485f69742f
5
5
  SHA512:
6
- metadata.gz: ba45cf22e5142201a664890c1ef153f8a5eaeac53bcdd2488de158745428369ad6986eb30c7d7bc5ab9890f8afa08b7d709c11b1eb0ddde136453df3fd12c1d9
7
- data.tar.gz: d567cae128e3a632ff20a5f1d5e654b97060bcba54071bd5c3c09f052ebbd3d33937d2525b2ea65cdaf0be7e7f4fe7bfc6d08ae0335690468c5a594a2d3ab84a
6
+ metadata.gz: fc31fd7c4e0c31d34903aafcbaa1ab99ae3f831377036c0f3ad14e770f2a2b4856894976792353c741c33cfec897b5a97fc5bf3d7e84fc2b591823725f1dfd94
7
+ data.tar.gz: 6222353d06d23fbb60cb798221be528da21891d95f139031cc30d7f9dcec7f5355ba2c8674b1793557989e68d22742acdc9bd373b590be1c7f2a6273e9cf2b89
@@ -22,7 +22,7 @@ class Transponder.Presenter
22
22
 
23
23
  elify: (event, response) ->
24
24
  if @response.errors
25
- if @response.id then "##{@modelName}_#{@response.id}" else "#new_#{@modelName}"
25
+ if @response.id then "##{@response.model_name}_#{@response.id}" else "#new_#{@response.model_name}"
26
26
  else
27
27
  "#{event.target.localName}##{event.target.id}"
28
28
 
@@ -34,7 +34,7 @@ class Transponder.Presenter
34
34
  runAction: (event, response) =>
35
35
  @beforeFilter(event, response)
36
36
  if @response.errors
37
- @errorOut()
37
+ @errorOut(@response.action)
38
38
  else
39
39
  @[event.type.split(':').pop()]()
40
40
  @afterFilter(event, response)
@@ -45,12 +45,10 @@ class Transponder.Presenter
45
45
  triggerEmpty: (eventName) ->
46
46
  console.log "#{eventName} triggered! Override this action in your own presenter"
47
47
 
48
- triggerEmptyError: (eventName) ->
49
- console.log "Error #{eventName} triggered! Override this action in your own presenter"
50
48
 
51
- errorOut: ->
52
- for key, value of @response.errors
53
- @error[key](value)
49
+
50
+ errorOut: (action) ->
51
+ @error[action](@response.errors, @element)
54
52
 
55
53
  index: ->
56
54
  @triggerEmpty('Index')
@@ -68,17 +66,20 @@ class Transponder.Presenter
68
66
  @triggerEmpty('Destroy')
69
67
 
70
68
  error:
71
- index: ->
69
+ triggerEmptyError: (eventName) ->
70
+ console.log "Error #{eventName} triggered! Override this action in your own presenter"
71
+
72
+ index: (errors, element) ->
72
73
  @triggerEmptyError('Index')
73
- show: ->
74
+ show: (errors, element) ->
74
75
  @triggerEmptyError('Show')
75
- new: ->
76
+ new: (errors, element) ->
76
77
  @triggerEmptyError('New')
77
- edit: ->
78
+ edit: (errors, element) ->
78
79
  @triggerEmptyError('Edit')
79
- update: ->
80
+ update: (errors, element) ->
80
81
  @triggerEmptyError('Update')
81
- create: ->
82
+ create: (errors, element) ->
82
83
  @triggerEmptyError('Create')
83
- destroy: ->
84
+ destroy: (errors, element) ->
84
85
  @triggerEmptyError('Destroy')
@@ -4,18 +4,32 @@ module Transponder
4
4
 
5
5
  included do
6
6
  after_filter :intercept_js
7
+ helper_method :xms_module_name
8
+ end
7
9
 
8
- def xms_errors object, message: nil
9
- render json: { errors: (message || object.errors),
10
- controller: controller_name,
11
- action: action_name,
12
- namespace: params[:controller].split('/')[0] }, status: :unprocessable_entity
13
- end
10
+ def xms_module_name
11
+ params[:controller].include?('/') ? params[:controller].split('/')[0] : 'application'
12
+ end
13
+
14
+ def xms_error_hash(object, message, action, module_name)
15
+ {
16
+ errors: (message || object.errors ),
17
+ controller: controller_name,
18
+ action: (action || action_name),
19
+ model_name: object.class.name.downcase,
20
+ id: object.id,
21
+ module: (module_name || xms_module_name)
22
+ }
23
+ end
24
+
25
+ def xms_error object, message: nil, action: nil, module_name: nil
26
+ render json: xms_error_hash(object, message, action, module_name),
27
+ status: :unprocessable_entity
28
+ end
14
29
 
15
- def intercept_js
16
- if request.format == :js
17
- response.header['Content-Type'] = "application/transmission"
18
- end
30
+ def intercept_js
31
+ if request.format == :js
32
+ response.header['Content-Type'] = "application/transmission"
19
33
  end
20
34
  end
21
35
  end
@@ -1,3 +1,3 @@
1
1
  module Transponder
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
data/lib/transponder.rb CHANGED
@@ -16,10 +16,6 @@ require 'transponder/transmission'
16
16
 
17
17
  module Transponder
18
18
  module ViewHelpers
19
- def xms_module_name
20
- params[:controller].include?('/') ? params[:controller].split('/')[0] : nil
21
- end
22
-
23
19
  def xms_event(module_name: nil, action: nil)
24
20
  _module = module_name || xms_module_name || 'application'
25
21
  _action = action || action_name
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transponder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zack Siri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-03 00:00:00.000000000 Z
11
+ date: 2013-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coffee-rails