kono_utils 0.15.11 → 0.15.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa908781b92ab7ffee58cb7579da7184ab3caaa0
4
- data.tar.gz: 5120270fa884ca616c8ed1ffbe70b9a2c3d3eba5
3
+ metadata.gz: 2c989fde2a18bae206a3db073e72f5ea78dbe450
4
+ data.tar.gz: 7f4793f9dc78c6b880a7216d55d1e0a32487a5d0
5
5
  SHA512:
6
- metadata.gz: 09c427f717885461540faa0a76b20c24a457181dc0ded4348edcd7b67905c4e7fc3a4b6e53e5c0032af3e87ca7179e048e560efd421eb7f2a26805a1ea4d5368
7
- data.tar.gz: 14fcbd7a7ad985015439ac111047c03fd771cc79096c6098c953cd80e5f227c7d3de74c653eb8b4a014fcd761394cd1ea2618d321695ef854bce5c99fb6590e6
6
+ metadata.gz: 2e0a5c77c35aac14545ac1044236512100504b1b8b3c89149fedd256c226cea27032796b701e6b6cdff6cad12577fc665aa51ef7b4c4ccb9051fe481b81a629b
7
+ data.tar.gz: 9e305100f12371c412dce8b6153308a6f58606d122efdd75b7b1f0a9c284af91b87be8d7422c1b478e9e25b1411e71102f98ed73c95f74f5bcd5b0595c030e6f
@@ -31,7 +31,7 @@ module KonoUtils
31
31
 
32
32
  respond_to do |format|
33
33
  format.html # index.html.erb
34
- format.xml { render :xml => @objects }
34
+ format.xml {render :xml => @objects}
35
35
  unless respond_to_call.nil?
36
36
  respond_to_call.call(format)
37
37
  end
@@ -44,11 +44,11 @@ module KonoUtils
44
44
  @object = base_class.new
45
45
  authorize @object
46
46
  @object = yield(@object) if block_given?
47
- logger.debug { "Nuovo oggetto #{@object.inspect}" }
47
+ logger.debug {"Nuovo oggetto #{@object.inspect}"}
48
48
 
49
49
  respond_to do |format|
50
50
  format.html
51
- format.xml { render :xml => @object }
51
+ format.xml {render :xml => @object}
52
52
  end
53
53
  end
54
54
 
@@ -63,11 +63,9 @@ module KonoUtils
63
63
  @object = yield(@object) if block_given?
64
64
  respond_to do |format|
65
65
  if @object.update_attributes(clean_params)
66
- format.html { redirect_to edit_custom_polymorphic_path(@object), :notice => success_update_message(@object) }
67
- format.xml { head :ok }
66
+ _successful_update(format)
68
67
  else
69
- format.html { render :action => :edit }
70
- format.xml { render :xml => @object.errors, :status => :unprocessable_entity }
68
+ _failed_update(format)
71
69
  end
72
70
  end
73
71
  end
@@ -78,15 +76,13 @@ module KonoUtils
78
76
  @object = base_class.new(clean_params)
79
77
  authorize @object
80
78
  @object = yield(@object) if block_given?
81
- logger.debug { "Nuovo oggetto #{@object.inspect}" }
79
+ logger.debug {"Nuovo oggetto #{@object.inspect}"}
82
80
 
83
81
  respond_to do |format|
84
82
  if @object.save
85
- format.html { redirect_to edit_custom_polymorphic_path(@object), :notice => success_create_message(@object) }
86
- format.xml { render :xml => @object, :status => :created, :location => @object }
83
+ _successful_create(format)
87
84
  else
88
- format.html { render :action => :new }
89
- format.xml { render :xml => @object.errors, :status => :unprocessable_entity }
85
+ _failed_create(format)
90
86
  end
91
87
  end
92
88
  end
@@ -99,13 +95,9 @@ module KonoUtils
99
95
 
100
96
  respond_to do |format|
101
97
  if @object.destroy
102
- format.html { redirect_to index_custom_polymorphic_path(base_class),
103
- :notice => success_destroy_message(@object) }
104
- format.xml { head :ok }
98
+ _successful_destroy(format)
105
99
  else
106
- format.html { redirect_to index_custom_polymorphic_path(base_class),
107
- :flash => {:error => @object.errors.full_messages.join(',')} }
108
- format.xml { head :ko }
100
+ _failed_destroy(format)
109
101
  end
110
102
  end
111
103
  end
@@ -126,14 +118,14 @@ module KonoUtils
126
118
  def load_object
127
119
  @object = base_class.find(params[:id])
128
120
  authorize @object
129
- logger.debug { "Oggetto #{@object.inspect}" }
121
+ logger.debug {"Oggetto #{@object.inspect}"}
130
122
 
131
123
  end
132
124
 
133
125
  def base_class
134
126
  controller = controller_name
135
127
  modello = controller.singularize.camelize.safe_constantize
136
- logger.debug { "Editazione del controller:#{controller} per modello: #{modello.to_s}" }
128
+ logger.debug {"Editazione del controller:#{controller} per modello: #{modello.to_s}"}
137
129
 
138
130
  raise "Non riesco a restituire la classe base per il controller #{controller}" if modello.nil?
139
131
 
@@ -150,15 +142,15 @@ module KonoUtils
150
142
  def clean_params
151
143
  permitted = policy(base_class.new).permitted_attributes
152
144
  dati = params.required(base_class.name.underscore.gsub('/', '_').to_sym).permit(permitted)
153
- ::Rails.logger.info { "Permitted Attributes: #{permitted.inspect}" }
154
- ::Rails.logger.info { "Parametri puliti: #{dati.inspect}" }
145
+ ::Rails.logger.info {"Permitted Attributes: #{permitted.inspect}"}
146
+ ::Rails.logger.info {"Parametri puliti: #{dati.inspect}"}
155
147
  dati
156
148
  end
157
149
 
158
150
  def check_errors
159
151
  unless @object.valid?
160
- logger.debug { "Invalid Obj:" }
161
- logger.debug { @object.errors.inspect }
152
+ logger.debug {"Invalid Obj:"}
153
+ logger.debug {@object.errors.inspect}
162
154
  end
163
155
  end
164
156
 
@@ -183,7 +175,37 @@ module KonoUtils
183
175
  polymorphic_path(*rec)
184
176
  end
185
177
 
178
+ def _failed_destroy(format)
179
+ format.html {redirect_to index_custom_polymorphic_path(base_class),
180
+ :flash => {:error => @object.errors.full_messages.join(',')}}
181
+ format.xml {head :ko}
182
+ end
183
+
184
+ def _successful_destroy(format)
185
+ format.html {redirect_to index_custom_polymorphic_path(base_class),
186
+ :notice => success_destroy_message(@object)}
187
+ format.xml {head :ok}
188
+ end
189
+
190
+ def _failed_create(format)
191
+ format.html {render :action => :new}
192
+ format.xml {render :xml => @object.errors, :status => :unprocessable_entity}
193
+ end
186
194
 
195
+ def _successful_create(format)
196
+ format.html {redirect_to edit_custom_polymorphic_path(@object), :notice => success_create_message(@object)}
197
+ format.xml {render :xml => @object, :status => :created, :location => @object}
198
+ end
199
+
200
+ def _failed_update(format)
201
+ format.html {render :action => :edit}
202
+ format.xml {render :xml => @object.errors, :status => :unprocessable_entity}
203
+ end
204
+
205
+ def _successful_update(format)
206
+ format.html {redirect_to edit_custom_polymorphic_path(@object), :notice => success_update_message(@object)}
207
+ format.xml {head :ok}
208
+ end
187
209
  end
188
210
 
189
211
  # module ClassMethods
@@ -3,11 +3,8 @@ module KonoUtils
3
3
  # Classe che si occupa di decodificare una qualsiasi stringa in formato utf8,
4
4
  # cercando di trovare l'encoding iniziale a tentativi.
5
5
  class Encoder
6
-
7
-
8
6
  attr_accessor :string
9
7
 
10
-
11
8
  ##
12
9
  # * *Attributes* :
13
10
  # - string -> Stringa da elaborare
@@ -15,41 +12,36 @@ module KonoUtils
15
12
  self.string = string
16
13
  end
17
14
 
18
-
19
15
  ##
20
16
  # Funcione di rimozione del carattere BOM http://en.wikipedia.org/wiki/Byte_order_mark
21
17
  # e encoding normale
22
18
  def remove_bom
23
- string_encoder.gsub("\xEF\xBB\xBF".force_encoding("UTF-8"), '')
19
+ string_encoder.gsub("\xEF\xBB\xBF".force_encoding('UTF-8'), '')
24
20
  end
25
21
 
26
22
  ##
27
23
  # Funzione di encoding semplice
28
24
  def string_encoder
29
- return self.string if self.string.valid_encoding?
30
- str = self.string
25
+ return string if string.valid_encoding?
26
+ str = string
31
27
  Encoding.list.each do |e|
32
28
  begin
33
29
  str.force_encoding(e.name)
34
- tmp_string = str.encode("UTF-8")
30
+ tmp_string = str.encode('UTF-8')
35
31
  return tmp_string if tmp_string.valid_encoding?
36
32
  rescue
37
- logger.debug { "Rescue -> #{e.name}" }
33
+ Rails.logger.debug { "Rescue -> #{e.name}" } if defined?(::Rails)
38
34
  end
39
35
  end
40
36
 
41
37
  impossible_encoding
42
38
 
43
- self.string
39
+ string
44
40
  end
45
41
 
46
42
  ##
47
43
  # Metodo placeholder, volendo si può estendere la funzione e sovrascrivere questa funzione
48
44
  # per essere notificati in caso di mancata decodifica
49
- def impossible_encoding
50
-
51
- end
52
-
53
-
45
+ def impossible_encoding; end
54
46
  end
55
- end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module KonoUtils
2
- VERSION = '0.15.11'
2
+ VERSION = '0.15.12'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kono_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.11
4
+ version: 0.15.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-13 00:00:00.000000000 Z
11
+ date: 2018-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -375,7 +375,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
375
375
  version: '0'
376
376
  requirements: []
377
377
  rubyforge_project:
378
- rubygems_version: 2.4.8
378
+ rubygems_version: 2.6.14
379
379
  signing_key:
380
380
  specification_version: 4
381
381
  summary: Kono Utilities