cowtech-rails 2.7.1.0 → 2.8.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,7 +48,7 @@ module Cowtech
48
48
  end
49
49
 
50
50
  def get_param(key, default = nil)
51
- if params[key].blank? then default else params[key] end
51
+ params[key].blank? ? default : params[key]
52
52
  end
53
53
 
54
54
  def _normalize_type(format = nil)
@@ -83,7 +83,7 @@ module Cowtech
83
83
  self.crud_query_initialize(data) if !data[:query_initialized]
84
84
  query = data[:query_expr] if !query
85
85
 
86
- query.count.times do |i| query[i] = "(#{query[i]})" end
86
+ query.count.times { |i| query[i] = "(#{query[i]})" }
87
87
  query.join(" AND ")
88
88
  end
89
89
 
@@ -98,7 +98,7 @@ module Cowtech
98
98
  self.crud_query_initialize(data) if !data[:query_initialized]
99
99
 
100
100
  expr = [expr] if !expr.respond_to?(:each)
101
- expr.each do |e| data[:query_expr] << e end
101
+ expr.each { |e| data[:query_expr] << e }
102
102
 
103
103
  data[:query_params].merge!(params)
104
104
  end
@@ -155,7 +155,7 @@ module Cowtech
155
155
  # BUILD QUERY
156
156
  data[:query_params].merge!(parameters)
157
157
  search_query = []
158
- fields.each do |field| search_query << "(#{search.gsub("@FIELD@", "#{self.crud_get_class(data).table_name}.#{field.to_s}")})" end
158
+ fields.each { |field| search_query << "(#{search.gsub("@FIELD@", "#{self.crud_get_class(data).table_name}.#{field.to_s}")})" }
159
159
 
160
160
  # ADD OPTIONAL DATA
161
161
  if externals then
@@ -164,7 +164,7 @@ module Cowtech
164
164
 
165
165
  if !external[:manual] then
166
166
  external_conds = []
167
- external.fetch(:fields, []).each do |external_field| external_conds << "(#{search.gsub("@FIELD@", "#{external[:table]}.#{external_field.to_s}")})" end
167
+ external.fetch(:fields, []).each { |external_field| external_conds << "(#{search.gsub("@FIELD@", "#{external[:table]}.#{external_field.to_s}")})" }
168
168
  external_field = external.fetch(:external_field, "id")
169
169
  external_query = "(#{external.fetch(:field, "id")} IN (SELECT #{external.fetch(:external_field, "id")} FROM #{external[:table]} WHERE #{external_conds.join(" OR ")}))"
170
170
  else
@@ -211,12 +211,12 @@ module Cowtech
211
211
  end
212
212
 
213
213
  def crud_form_submit_label
214
- if self.crud_get_form_data.new_record? then "Create" else "Edit" end
214
+ self.crud_get_form_data.new_record? ? "Create" : "Edit"
215
215
  end
216
216
 
217
217
  def crud_get_page_param(key = :page, upperbound = -1)
218
218
  page = params[key]
219
- page = if params[key].is_valid_integer? then params[key].to_integer else 1 end
219
+ page = params[key].is_valid_integer? ? params[key].to_integer : 1
220
220
  page = 1 if page < 1
221
221
  page = upperbound if (upperbound > 0 && page > upperbound)
222
222
  page
@@ -242,7 +242,7 @@ module Cowtech
242
242
  bounds = OpenStruct.new({:total => 0, :first => 0, :last => 0, :pages => 0, :page => 1, :per_page => 1})
243
243
 
244
244
  if records != nil && records.count > 0 then
245
- per_page = (if per_page.is_valid_integer? then per_page else records[0].class.per_page end).to_integer
245
+ per_page = (per_page.is_valid_integer? ? per_page : records[0].class.per_page).to_integer
246
246
  per_page = records.count if per_page < 1
247
247
  bounds.total = records.count
248
248
  bounds.per_page = per_page
@@ -260,7 +260,7 @@ module Cowtech
260
260
 
261
261
  def crud_update_params
262
262
  blacklist = ["controller", "action", "id"]
263
- session["params-#{self.location_name}"] = (params.delete_if {|k,v| blacklist.include?(k) || params[k].is_a?(Tempfile)})
263
+ session["params-#{self.location_name}"] = (params.delete_if { |k,v| blacklist.include?(k) || params[k].is_a?(Tempfile)})
264
264
  end
265
265
 
266
266
  def crud_end_write_action(additional = nil, absolute = false)
@@ -276,7 +276,7 @@ module Cowtech
276
276
  end
277
277
 
278
278
  if additional != nil then
279
- additional.each do |k, v| rp[k] = v end
279
+ additional.each { |k, v| rp[k] = v }
280
280
  end
281
281
 
282
282
  url_for(rp)
@@ -31,7 +31,7 @@ module Cowtech
31
31
 
32
32
  final_msg = []
33
33
  final_msg << self.debug_timestamp if !no_timestamp
34
- tags.collect {|tag| "[" + tag + "]" }.each { |tag| final_msg << tag } if tags.present?
34
+ tags.collect { |tag| "[" + tag + "]" }.each { |tag| final_msg << tag } if tags.present?
35
35
  final_msg << msg
36
36
  final_msg = final_msg.join(" ")
37
37
 
@@ -14,7 +14,7 @@ module Cowtech
14
14
  elsif field.is_a?(Float) then
15
15
  field.format_number
16
16
  elsif field.blank? || field.strip.blank? then
17
- (if default then default else "Not set" end)
17
+ (default ? default : "Not set")
18
18
  else
19
19
  field
20
20
  end
@@ -35,7 +35,7 @@ module Cowtech
35
35
  end
36
36
 
37
37
  def text_class(val, additional = nil)
38
- "class=\"text #{if additional.blank? then nil else additional end} #{if val.blank? then "unset" else nil end}\""
38
+ "class=\"text #{additional.blank? ? nil : additional} #{val.blank? ? "unset" : nil}\""
39
39
  end
40
40
  end
41
41
  end
@@ -69,7 +69,7 @@ module Cowtech
69
69
  if condition.is_a?(Hash) then
70
70
  condition.each_pair do |key, val|
71
71
  if key == "$or" then
72
- @mongo_query = @mongo_query.any_of(val)
72
+ @mongo_query = @mongo_query.any_of(val) # TODO: This don't work as expected. See: https://github.com/mongoid/mongoid/issues/569
73
73
  else
74
74
  @mongo_query = @mongo_query.where({key => val})
75
75
  end
@@ -86,7 +86,7 @@ module Cowtech
86
86
  # Operate on parenthesis. If unbalanced, no substitution is done
87
87
  if search.gsub(/[^(]/mi, "").strip.length == search.gsub(/[^)]/mi, "").strip.length then
88
88
  # Split token
89
- search = search.split(/(\s(AND|OR)\s)|([\(\)])/).select{|t| !t.empty? && t !~ /^(AND|OR)$/}
89
+ search = search.split(/(\s(AND|OR)\s)|([\(\)])/).select{ |t| !t.empty? && t !~ /^(AND|OR)$/}
90
90
 
91
91
  # Replace tokens
92
92
  search = search.collect { |token|
@@ -128,7 +128,6 @@ module Cowtech
128
128
  end
129
129
 
130
130
  # Now add external fields
131
- # TODO: Can we enhance this?
132
131
  (args[:external] || []).each do |external|
133
132
  external_query = external[:class].not_deleted
134
133
  eor_query = []
@@ -136,7 +135,7 @@ module Cowtech
136
135
  eor_query << {field.to_sym => Regexp.new(expr, Regexp::EXTENDED | Regexp::MULTILINE | Regexp::IGNORECASE)}
137
136
  end
138
137
 
139
- ids = external_query.any_of(eor_query).only(:id).all.collect {|r| r.id }
138
+ ids = external_query.any_of(eor_query).only(:id).all.collect { |r| r.id }
140
139
  or_query << {external[:foreign_key].in => ids} if ids.count > 0
141
140
  end
142
141
 
@@ -207,7 +206,7 @@ module Cowtech
207
206
 
208
207
  def mongo_update_params(args = {})
209
208
  blacklist = self.mongo_update_params_black_list(args)
210
- session["params-#{self.location_name}"] = (params.delete_if {|k,v| blacklist.include?(k) || params[k].is_a?(Tempfile) || params[k].blank?})
209
+ session["params-#{self.location_name}"] = (params.delete_if { |k,v| blacklist.include?(k) || params[k].is_a?(Tempfile) || params[k].blank?})
211
210
  end
212
211
 
213
212
  def mongo_end_write_action(args = {})
@@ -27,7 +27,7 @@ module Cowtech
27
27
  end
28
28
 
29
29
  def safe_id
30
- if self.id then self.id else 0 end
30
+ self.id || 0
31
31
  end
32
32
 
33
33
  def editable?(user = nil)
@@ -41,7 +41,7 @@ module Cowtech
41
41
  end
42
42
 
43
43
  # OTTENIAMO GLI ARGOMENTI
44
- args = (if args.is_a?(Hash) then args else args[0] end).delete_if { |k,v| v.blank? }
44
+ args = (args.is_a?(Hash) ? args : args[0]).delete_if { |k,v| v.blank? }
45
45
 
46
46
  # AGGIUSTIAMO REPLY TO
47
47
  args[:reply_to] = args[:from] if !args[:reply_to]
@@ -52,10 +52,10 @@ module Cowtech
52
52
 
53
53
  mail(args) do |format|
54
54
  if plain_body then # SE C'E' PLAIN BODY
55
- format.text do render :text => plain_body end
55
+ format.text { render :text => plain_body }
56
56
  end
57
57
  if html_body then # SE C'E' HTML
58
- format.html do render :text => html_body end
58
+ format.html { render :text => html_body }
59
59
  end
60
60
  end
61
61
  end
@@ -36,7 +36,7 @@ module Cowtech
36
36
  rv = ""
37
37
 
38
38
  rv += "[#{Time.now.strftime("%Y-%m-%d %T")}] " if !options[:no_time]
39
- rv += options[:prefix].ensure_array.collect {|p| "[" + p.center(6, " ") + "]" }.join(" ") + " " if options[:prefix].present?
39
+ rv += options[:prefix].ensure_array.collect { |p| "[" + p.center(6, " ") + "]" }.join(" ") + " " if options[:prefix].present?
40
40
  rv += message
41
41
 
42
42
  rv
@@ -54,7 +54,7 @@ module Cowtech
54
54
  args_string = args.present? ? " with arguments #{args.to_json}" : ""
55
55
 
56
56
  task = Rake::Task[name]
57
- values = task.arg_names.collect {|a| args[a.to_sym] }
57
+ values = task.arg_names.collect { |a| args[a.to_sym] }
58
58
 
59
59
  self.log(label + args_string + " ...", {:prefix => ["RAKE", "START", name]})
60
60
  task.reenable
@@ -87,14 +87,14 @@ module Cowtech
87
87
  PhusionPassenger.on_event(:starting_worker_process) do |forked|
88
88
  if forked && !FileTest.exists?(@pid) then
89
89
  self.log("Starting process with PID #{$$}", {:prefix => ["WORKER", "START"]})
90
- File.open(@pid, "w") {|f| f.write($$) }
90
+ File.open(@pid, "w") { |f| f.write($$) }
91
91
  self.handle_plain
92
92
  end
93
93
  end
94
94
 
95
95
  PhusionPassenger.on_event(:stopping_worker_process) do
96
96
  if FileTest.exists?(@pid) then
97
- if File.open(@pid, "r") {|f| pid = f.read.to_i} == $$ then
97
+ if File.open(@pid, "r") { |f| pid = f.read.to_i} == $$ then
98
98
  self.log("Stopped process with PID #{$$}", {:prefix => ["WORKER", "STOP"]})
99
99
  File.delete(@pid)
100
100
  end
@@ -8,18 +8,18 @@ module Cowtech
8
8
  module RubyOnRails
9
9
  class AppUtils
10
10
  def self.run_command(cmd)
11
- IO.popen(cmd, "r") do |f| puts f.gets end
11
+ IO.popen(cmd, "r") { |f| puts f.gets }
12
12
  end
13
13
 
14
14
  def self.get_version(as_string = true)
15
15
  info = YAML.load_file(Rails.root + "config/application_info.yml")
16
- (if as_string then "Current application info --- Version #{info["version"]} - Release date: #{info["release-date"]}" else info end)
16
+ (as_string ? "Current application info --- Version #{info["version"]} - Release date: #{info["release-date"]}" : info)
17
17
  end
18
18
 
19
19
  def self.set_version(info)
20
20
  puts "--- Setting application version ..."
21
21
  version = Cowtech::RubyOnRails::AppUtils.get_version(false)
22
- File.open(Rails.root + "config/application_info.yml", "w") do |f| f.write(version.merge(info.stringify_keys).to_yaml) end
22
+ File.open(Rails.root + "config/application_info.yml", "w") { |f| f.write(version.merge(info.stringify_keys).to_yaml) }
23
23
  puts Cowtech::RubyOnRails::AppUtils.get_version
24
24
  end
25
25
 
@@ -11,11 +11,11 @@ module Cowtech
11
11
  @@log_compressed_extension = "bz2"
12
12
 
13
13
  def self.generate_new_name(base, i = 0)
14
- (Rails.root + "backups/logs/#{base}#{if i > 0 then "-#{i}" else "" end}").to_s
14
+ (Rails.root + "backups/logs/#{base}#{i > 0 ? "-#{i}" : ""}").to_s
15
15
  end
16
16
 
17
17
  def self.run_command(cmd)
18
- IO.popen(cmd) do |f| print f.gets end
18
+ IO.popen(cmd) { |f| print f.gets }
19
19
  end
20
20
 
21
21
  def self.rotate(rake_args)
@@ -24,18 +24,18 @@ module Cowtech
24
24
 
25
25
  def self.save_config(args = nil)
26
26
  args = Cowtech::RubyOnRails::ServerUtils.load_config if !args
27
- File.open(Rails.root + @@yml_path, "w") do |f| f.write(YAML::dump(args)) end
27
+ File.open(Rails.root + @@yml_path, "w") { |f| f.write(YAML::dump(args)) }
28
28
  end
29
29
 
30
30
  def self.stringify_keys(hash)
31
31
  rv = {}
32
- hash.each do |k, v| rv[k.to_s] = v end
32
+ hash.each { |k, v| rv[k.to_s] = v }
33
33
  rv
34
34
  end
35
35
 
36
36
  def self.merge(base, other)
37
37
  rv = {}
38
- base.each do |k, v| rv[k] = if other[k] then other[k] else v end end
38
+ base.each { |k, v| rv[k] = (other[k] ? other[k] : v) }
39
39
  rv
40
40
  end
41
41
 
@@ -8,8 +8,8 @@ module Cowtech
8
8
  module Rails
9
9
  module Version
10
10
  MAJOR = 2
11
- MINOR = 7
12
- PATCH = 1
11
+ MINOR = 8
12
+ PATCH = 0
13
13
  BUILD = 0
14
14
 
15
15
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cowtech-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1.0
4
+ version: 2.8.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-07 00:00:00.000000000Z
12
+ date: 2012-01-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cowtech-extensions
16
- requirement: &70220120113560 !ruby/object:Gem::Requirement
16
+ requirement: &70338148676940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70220120113560
24
+ version_requirements: *70338148676940
25
25
  description: A general purpose Rails utility plugin.
26
26
  email: shogun_panda@me.com
27
27
  executables: []