active_scaffold_vho 3.2.4 → 3.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NWQ4NTMwYWQ0MzYzNjZhMmVlNjA5MzAxYmE3MWI3YmFkNDg4NzFhYQ==
4
+ ZDc3NWI5YWQ0NmNlZTY0YzNiZjBhZmMxZGRlYzdjYjI3OWY2NTYyNw==
5
5
  data.tar.gz: !binary |-
6
- NDQyNTA0MWQyZjQ4NWIwNWUzYzk0MDFlNjM3NTgxOTUyNGFiNzg3NA==
6
+ MmYzMzdhMzJmMmNiNTk0NGY4MTAyNzcwZGE2Nzg3YjBhMzhjZDM2Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDNkNzIwOTVkNTQzYWZmZGEzNmZkYjRlYjEzY2FlYmU4OGUyODhmYjI1MWM5
10
- ZjlhZWEzMmE3ZjVlNDUwMWZhYTliNzFiM2I4YzZlZTEzYTM2N2FhMjk1ZjVl
11
- YjE0M2U0MjJlOGEyZWFhNjIxM2IxNDk2NjY0ZTA5YWUyYThlODU=
9
+ Y2EyYTljMzA2YmE1OWFlMmExNGZjMDZlNThhYzQzM2I5MDBmN2Q0ZTkwNWJj
10
+ MDFlZjhhYWQyN2VkMjdiNWM5NjhiNzlkOTE2ZjI2ZDI2YjBiOGU5NGRlNmE1
11
+ ZTFmY2Y1M2RiNDAyZjA2OWQ2ZWE4NmQ0OThiOTZjZTY5N2E3M2I=
12
12
  data.tar.gz: !binary |-
13
- ZWJkNjM2MDYwMTM5ZTUzZDQ5MzBlZDU3Zjk4Nzg1OGVkYmJmNjE2YTZlOTNk
14
- NmYxNjVhYWVjY2ZjYjcwMTlmMWUyNjdkNjhlZTYxNTRkMWU3YmZmYjUzOTlm
15
- ZTM4MzY4Zjk2MGMxMTQ2YzJlMmNkZjBlODc2MmI5YTk1NDFmZTE=
13
+ ZDg0ZTNkMzhlYzdlY2U0NTYwMGQ2NjhlY2NiY2Q2MGE4MTI0YzI5YTU3OWJh
14
+ NjFmMWQ2ZjMzNTJlZmY2ZWVhNDkyZjNkZjY1ZThmYjU4YTBiMmU1NmNmMmQz
15
+ MWYzNmViYjc5YTJkNDlmZGI0M2QzYmVhZmM1ZWY5OTRmOTdlNGQ=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_scaffold_vho (3.2.3)
4
+ active_scaffold_vho (3.2.4)
5
5
  kaminari
6
6
  rails (>= 3.1.0)
7
7
 
@@ -88,7 +88,19 @@ module ActiveScaffold::Actions
88
88
 
89
89
  # API response object that will be converted to XML/YAML/JSON using to_xxx
90
90
  def response_object
91
- @response_object = successful? ? (@record || @records) : @record.errors
91
+ @response_object = if successful?
92
+ (@record || @records)
93
+ else
94
+ unless flash[:error].nil?
95
+ @record.errors.add(:base, flash[:error])
96
+ flash.discard(:error)
97
+ end
98
+ {:errors => @record.errors}
99
+ end
100
+ end
101
+
102
+ def error_object_attributes
103
+ [:errors]
92
104
  end
93
105
 
94
106
  # Success is the existence of certain variables and the absence of errors (when applicable).
@@ -153,6 +165,10 @@ module ActiveScaffold::Actions
153
165
  model.respond_to?(:build) ? model.build(build_options || {}) : model.new
154
166
  end
155
167
 
168
+ def virtual_columns(columns)
169
+ columns.reject {|col| active_scaffold_config.model.columns_hash[col] || active_scaffold_config.model.reflect_on_association(col)}
170
+ end
171
+
156
172
  private
157
173
  def respond_to_action(action)
158
174
  respond_to do |type|
@@ -67,15 +67,18 @@ module ActiveScaffold::Actions
67
67
  end
68
68
 
69
69
  def create_respond_to_xml
70
- render :xml => response_object.to_xml(:only => create_columns_names), :content_type => Mime::XML, :status => response_status, :location => response_location
70
+ column_names = successful? ? create_columns_names : error_object_attributes
71
+ render :xml => response_object.to_xml(:only => column_names, :methods => virtual_columns(column_names)), :content_type => Mime::XML, :status => response_status, :location => response_location
71
72
  end
72
73
 
73
74
  def create_respond_to_json
74
- render :text => response_object.to_json(:only => create_columns_names), :content_type => Mime::JSON, :status => response_status, :location => response_location
75
+ column_names = successful? ? create_columns_names : error_object_attributes
76
+ render :text => response_object.to_json(:only => column_names, :methods => virtual_columns(column_names)), :content_type => Mime::JSON, :status => response_status, :location => response_location
75
77
  end
76
78
 
77
79
  def create_respond_to_yaml
78
- render :text => Hash.from_xml(response_object.to_xml(:only => create_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status, :location => response_location
80
+ column_names = successful? ? create_columns_names : error_object_attributes
81
+ render :text => Hash.from_xml(response_object.to_xml(:only => column_names, :methods => virtual_columns(column_names))).to_yaml, :content_type => Mime::YAML, :status => response_status, :location => response_location
79
82
  end
80
83
 
81
84
  # A simple method to find and prepare an example new record for the form
@@ -31,15 +31,18 @@ module ActiveScaffold::Actions
31
31
  end
32
32
 
33
33
  def destroy_respond_to_xml
34
- render :xml => successful? ? "" : response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status
34
+ column_names = successful? ? [active_scaffold_config.model.primary_key] : error_object_attributes
35
+ render :xml => successful? ? "" : response_object.to_xml(:only => column_names), :content_type => Mime::XML, :status => response_status
35
36
  end
36
37
 
37
38
  def destroy_respond_to_json
38
- render :text => successful? ? "" : response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status
39
+ column_names = successful? ? [active_scaffold_config.model.primary_key] : error_object_attributes
40
+ render :text => successful? ? "" : response_object.to_json(:only => column_names), :content_type => Mime::JSON, :status => response_status
39
41
  end
40
42
 
41
43
  def destroy_respond_to_yaml
42
- render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status
44
+ column_names = successful? ? [active_scaffold_config.model.primary_key] : error_object_attributes
45
+ render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => column_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
43
46
  end
44
47
 
45
48
  def destroy_find_record
@@ -40,13 +40,16 @@ module ActiveScaffold::Actions
40
40
  end
41
41
  end
42
42
  def list_respond_to_xml
43
- render :xml => response_object.to_xml(:only => list_columns_names), :content_type => Mime::XML, :status => response_status
43
+ column_names = successful? ? list_columns_names : error_object_attributes
44
+ render :xml => response_object.to_xml(:only => column_names, :methods => virtual_columns(column_names)), :content_type => Mime::XML, :status => response_status
44
45
  end
45
46
  def list_respond_to_json
46
- render :text => response_object.to_json(:only => list_columns_names), :content_type => Mime::JSON, :status => response_status
47
+ column_names = successful? ? list_columns_names : error_object_attributes
48
+ render :text => response_object.to_json(:only => column_names, :methods => virtual_columns(column_names)), :content_type => Mime::JSON, :status => response_status
47
49
  end
48
50
  def list_respond_to_yaml
49
- render :text => Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
51
+ column_names = successful? ? list_columns_names : error_object_attributes
52
+ render :text => Hash.from_xml(response_object.to_xml(:only => column_names, :methods => virtual_columns(column_names))).to_yaml, :content_type => Mime::YAML, :status => response_status
50
53
  end
51
54
 
52
55
  def row_respond_to_html
@@ -115,16 +118,25 @@ module ActiveScaffold::Actions
115
118
  @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0
116
119
  respond_to_action(:action_confirmation)
117
120
  else
118
- if params[:id] && params[:id] && params[:id].to_i > 0
119
- @record = find_if_allowed(params[:id], (request.post? || request.put?) ? :update : :delete)
120
- unless @record.nil?
121
- yield @record
121
+ begin
122
+ if params[:id] && params[:id] && params[:id].to_i > 0
123
+ @record = find_if_allowed(params[:id], (request.post? || request.put?) ? :update : :delete)
124
+ unless @record.nil?
125
+ yield @record
126
+ else
127
+ self.successful = false
128
+ flash[:error] = as_(:no_authorization_for_action, :action => action_name)
129
+ end
122
130
  else
123
- self.successful = false
124
- flash[:error] = as_(:no_authorization_for_action, :action => action_name)
131
+ yield
125
132
  end
126
- else
127
- yield
133
+ rescue ActiveRecord::RecordInvalid
134
+ rescue ActiveRecord::StaleObjectError
135
+ @record.errors.add(:base, as_(:version_inconsistency)) unless @record.nil?
136
+ self.successful=false
137
+ rescue ActiveRecord::RecordNotSaved
138
+ @record.errors.add(:base, as_(:record_not_saved)) if !@record.nil? && @record.errors.empty?
139
+ self.successful = false
128
140
  end
129
141
  respond_to_action(render_action)
130
142
  end
@@ -146,15 +158,18 @@ module ActiveScaffold::Actions
146
158
  end
147
159
 
148
160
  def action_update_respond_to_xml
149
- render :xml => successful? ? "" : response_object.to_xml(:only => list_columns_names), :content_type => Mime::XML, :status => response_status
161
+ column_names = successful? ? list_columns_names : error_object_attributes
162
+ render :xml => response_object.to_xml(:only => column_names, :methods => virtual_columns(column_names)), :content_type => Mime::XML, :status => response_status
150
163
  end
151
164
 
152
165
  def action_update_respond_to_json
153
- render :text => successful? ? "" : response_object.to_json(:only => list_columns_names), :content_type => Mime::JSON, :status => response_status
166
+ column_names = successful? ? list_columns_names : error_object_attributes
167
+ render :text => response_object.to_json(:only => column_names, :methods => virtual_columns(column_names)), :content_type => Mime::JSON, :status => response_status
154
168
  end
155
169
 
156
170
  def action_update_respond_to_yaml
157
- render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
171
+ column_names = successful? ? list_columns_names : error_object_attributes
172
+ render :text => Hash.from_xml(response_object.to_xml(:only => column_names, :methods => virtual_columns(column_names))).to_yaml, :content_type => Mime::YAML, :status => response_status
158
173
  end
159
174
 
160
175
  def save_current_page_num
@@ -21,15 +21,18 @@ module ActiveScaffold::Actions
21
21
  protected
22
22
 
23
23
  def show_respond_to_json
24
- render :text => response_object.to_json(:only => show_columns_names), :content_type => Mime::JSON, :status => response_status
24
+ column_names = successful? ? show_columns_names : error_object_attributes
25
+ render :text => response_object.to_json(:only => show_columns_names, :methods => virtual_columns(column_names)), :content_type => Mime::JSON, :status => response_status
25
26
  end
26
27
 
27
28
  def show_respond_to_yaml
28
- render :text => Hash.from_xml(response_object.to_xml(:only => show_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
29
+ column_names = successful? ? show_columns_names : error_object_attributes
30
+ render :text => Hash.from_xml(response_object.to_xml(:only => show_columns_names, :methods => virtual_columns(column_names))).to_yaml, :content_type => Mime::YAML, :status => response_status
29
31
  end
30
32
 
31
33
  def show_respond_to_xml
32
- render :xml => response_object.to_xml(:only => show_columns_names), :content_type => Mime::XML, :status => response_status
34
+ column_names = successful? ? show_columns_names : error_object_attributes
35
+ render :xml => response_object.to_xml(:only => show_columns_names, :methods => virtual_columns(column_names)), :content_type => Mime::XML, :status => response_status
33
36
  end
34
37
 
35
38
  def show_respond_to_js
@@ -55,13 +55,16 @@ module ActiveScaffold::Actions
55
55
  render :action => 'on_update'
56
56
  end
57
57
  def update_respond_to_xml
58
- render :xml => response_object.to_xml(:only => update_columns_names), :content_type => Mime::XML, :status => response_status
58
+ column_names = successful? ? update_columns_names : error_object_attributes
59
+ render :xml => response_object.to_xml(:only => column_names, :methods => virtual_columns(column_names)), :content_type => Mime::XML, :status => response_status
59
60
  end
60
61
  def update_respond_to_json
61
- render :text => response_object.to_json(:only => update_columns_names), :content_type => Mime::JSON, :status => response_status
62
+ column_names = successful? ? update_columns_names : error_object_attributes
63
+ render :text => response_object.to_json(:only => column_names, :methods => virtual_columns(column_names)), :content_type => Mime::JSON, :status => response_status
62
64
  end
63
65
  def update_respond_to_yaml
64
- render :text => Hash.from_xml(response_object.to_xml(:only => update_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
66
+ column_names = successful? ? update_columns_names : error_object_attributes
67
+ render :text => Hash.from_xml(response_object.to_xml(:only => column_names, :methods => virtual_columns(column_names))).to_yaml, :content_type => Mime::YAML, :status => response_status
65
68
  end
66
69
  # A simple method to find and prepare a record for editing
67
70
  # May be overridden to customize the record (set default values, etc.)
@@ -2,7 +2,7 @@ module ActiveScaffold
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 2
5
- PATCH = 4
5
+ PATCH = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold_vho
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.4
4
+ version: 3.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Many, see README
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-17 00:00:00.000000000 Z
11
+ date: 2014-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda