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.
- data/app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb +1 -1
- data/app/helpers/cowtech/ruby_on_rails/helpers/ar_crud_helper.rb +9 -9
- data/app/helpers/cowtech/ruby_on_rails/helpers/debug_helper.rb +1 -1
- data/app/helpers/cowtech/ruby_on_rails/helpers/format_helper.rb +2 -2
- data/app/helpers/cowtech/ruby_on_rails/helpers/mongoid_crud_helper.rb +4 -5
- data/app/models/cowtech/ruby_on_rails/models/ar/model_base.rb +1 -1
- data/app/models/cowtech/ruby_on_rails/models/e_mail.rb +3 -3
- data/lib/cowtech/scheduler.rb +4 -4
- data/lib/cowtech/tasks/app.rake +3 -3
- data/lib/cowtech/tasks/log.rake +2 -2
- data/lib/cowtech/tasks/server.rake +3 -3
- data/lib/cowtech/version.rb +2 -2
- metadata +4 -4
@@ -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
|
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
|
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
|
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
|
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
|
-
|
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 =
|
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 = (
|
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
|
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
|
-
(
|
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 #{
|
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 = {})
|
@@ -41,7 +41,7 @@ module Cowtech
|
|
41
41
|
end
|
42
42
|
|
43
43
|
# OTTENIAMO GLI ARGOMENTI
|
44
|
-
args = (
|
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
|
55
|
+
format.text { render :text => plain_body }
|
56
56
|
end
|
57
57
|
if html_body then # SE C'E' HTML
|
58
|
-
format.html
|
58
|
+
format.html { render :text => html_body }
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
data/lib/cowtech/scheduler.rb
CHANGED
@@ -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
|
data/lib/cowtech/tasks/app.rake
CHANGED
@@ -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")
|
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
|
-
(
|
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")
|
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
|
|
data/lib/cowtech/tasks/log.rake
CHANGED
@@ -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}#{
|
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)
|
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")
|
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
|
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
|
38
|
+
base.each { |k, v| rv[k] = (other[k] ? other[k] : v) }
|
39
39
|
rv
|
40
40
|
end
|
41
41
|
|
data/lib/cowtech/version.rb
CHANGED
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.
|
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-
|
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: &
|
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: *
|
24
|
+
version_requirements: *70338148676940
|
25
25
|
description: A general purpose Rails utility plugin.
|
26
26
|
email: shogun_panda@me.com
|
27
27
|
executables: []
|