cowtech-rails 2.8.1.0 → 2.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,76 +5,76 @@
5
5
  #
6
6
 
7
7
  module Cowtech
8
- module RubyOnRails
9
- module Helpers
10
- module ValidationHelper
11
- def exists?(cls, query, params)
12
- cls.constantize.where(query, params).count > 0
13
- end
8
+ module RubyOnRails
9
+ module Helpers
10
+ module ValidationHelper
11
+ def exists?(cls, query, params)
12
+ cls.constantize.where(query, params).count > 0
13
+ end
14
14
 
15
- def json_is_available?(cls, query, params, must_exists = false, internal = false)
16
- rv = self.setup_json_response(:validator)
15
+ def json_is_available?(cls, query, params, must_exists = false, internal = false)
16
+ rv = self.setup_json_response(:validator)
17
17
 
18
- rv["success"] = true
19
- rv["valid"] = (self.exists?(cls, query, params) == must_exists)
18
+ rv["success"] = true
19
+ rv["valid"] = (self.exists?(cls, query, params) == must_exists)
20
20
 
21
- if internal then
22
- rv
23
- else
24
- custom_respond_with(rv.to_json)
25
- end
26
- end
27
-
28
- def valid_email?(field)
29
- /^([a-z0-9_\.\-\+]+)@([\da-z\.\-]+)\.([a-z\.]{2,6})$/i.match(field.to_s) != nil
30
- end
21
+ if internal then
22
+ rv
23
+ else
24
+ custom_respond_with(rv.to_json)
25
+ end
26
+ end
31
27
 
32
- def valid_phone?(field)
33
- /^(((\+|00)\d{1,4}\s?)?(\d{0,4}\s?)?(\d{5,}))?$/i.match(field.to_s) != nil
34
- end
28
+ def valid_email?(field)
29
+ /^([a-z0-9_\.\-\+]+)@([\da-z\.\-]+)\.([a-z\.]{2,6})$/i.match(field.to_s) != nil
30
+ end
35
31
 
36
- def valid_letter?(field)
37
- /^([a-z])$/i.match(field.to_s) != nil
38
- end
32
+ def valid_phone?(field)
33
+ /^(((\+|00)\d{1,4}\s?)?(\d{0,4}\s?)?(\d{5,}))?$/i.match(field.to_s) != nil
34
+ end
39
35
 
40
- def valid_number?(field)
41
- field.to_s.is_valid_float?
42
- end
36
+ def valid_letter?(field)
37
+ /^([a-z])$/i.match(field.to_s) != nil
38
+ end
43
39
 
44
- def valid_date?(field)
45
- begin
46
- DateTime.strptime(field.to_s, "%d/%m/%Y")
47
- true
48
- rescue ArgumentError
49
- false
50
- end
51
- end
40
+ def valid_number?(field)
41
+ field.to_s.is_valid_float?
42
+ end
52
43
 
53
- def valid_time?(field)
54
- begin
55
- DateTime.strptime(field.to_s, "%H:%M")
56
- true
57
- rescue ArgumentError
58
- false
59
- end
60
- end
44
+ def valid_date?(field)
45
+ begin
46
+ DateTime.strptime(field.to_s, "%d/%m/%Y")
47
+ true
48
+ rescue ArgumentError
49
+ false
50
+ end
51
+ end
61
52
 
62
- def valid_piva?(field)
63
- /^([0-9A-Z]{11,17})$/i.match(field.to_s) != nil
64
- end
53
+ def valid_time?(field)
54
+ begin
55
+ DateTime.strptime(field.to_s, "%H:%M")
56
+ true
57
+ rescue ArgumentError
58
+ false
59
+ end
60
+ end
65
61
 
66
- def valid_cf?(field)
67
- /^([0-9A-Z]{16})$/i.match(field.to_s) != nil
68
- end
62
+ def valid_piva?(field)
63
+ /^([0-9A-Z]{11,17})$/i.match(field.to_s) != nil
64
+ end
69
65
 
70
- def valid_cap?(field)
71
- /^([0-9]{5})$/i.match(field.to_s) != nil
72
- end
66
+ def valid_cf?(field)
67
+ /^([0-9A-Z]{16})$/i.match(field.to_s) != nil
68
+ end
73
69
 
74
- def valid_password?(field)
75
- field.to_s.length >= 8
76
- end
77
- end
78
- end
79
- end
70
+ def valid_cap?(field)
71
+ /^([0-9]{5})$/i.match(field.to_s) != nil
72
+ end
73
+
74
+ def valid_password?(field)
75
+ field.to_s.length >= 8
76
+ end
77
+ end
78
+ end
79
+ end
80
80
  end
@@ -5,61 +5,67 @@
5
5
  #
6
6
 
7
7
  module Cowtech
8
- module RubyOnRails
9
- module Models
10
- class EMail < ActionMailer::Base
11
- def self.setup(method = :smtp, file = nil)
12
- rv = YAML.load_file(file || (Rails.root + "config/email.yml"))
8
+ module RubyOnRails
9
+ module Models
10
+ class EMail < ActionMailer::Base
11
+ def self.setup(method = :smtp, file = nil, raise_config_errors = true)
12
+ begin
13
+ rv = YAML.load_file(file || (Rails.root + "config/email.yml"))
14
+ rescue Exception => e
15
+ raise e if raise_config_errors
16
+ rv = {}
17
+ end
13
18
 
14
- ActionMailer::Base.raise_delivery_errors = true
15
- ActionMailer::Base.delivery_method = method
16
19
 
17
- case method
18
- when :fail_test
19
- raise ArgumentError
20
- when :smtp
21
- ActionMailer::Base.smtp_settings = rv[:smtp]
22
- end
20
+ ActionMailer::Base.raise_delivery_errors = true
21
+ ActionMailer::Base.delivery_method = method
23
22
 
24
- rv
25
- end
23
+ case method
24
+ when :fail_test
25
+ raise ArgumentError
26
+ when :smtp
27
+ ActionMailer::Base.smtp_settings = rv[:smtp]
28
+ end
26
29
 
27
- def setup(method = :smtp, file = nil)
28
- @configuration ||= EMail.setup(method, file)
29
- end
30
+ rv
31
+ end
30
32
 
31
- def generic(args)
32
- # Load configuration
33
- if !@configuration then
34
- conf = args.delete(:configuration)
35
-
36
- if conf then
37
- @configuration = conf
38
- else
39
- self.setup(args.delete(:method) || :smtp, args.delete(:configuration_file))
40
- end
41
- end
42
-
43
- # OTTENIAMO GLI ARGOMENTI
44
- args = (args.is_a?(Hash) ? args : args[0]).delete_if { |k,v| v.blank? }
33
+ def setup(method = :smtp, file = nil, raise_config_errors = true)
34
+ @configuration ||= EMail.setup(method, file, raise_config_errors)
35
+ end
45
36
 
46
- # AGGIUSTIAMO REPLY TO
47
- args[:reply_to] = args[:from] if !args[:reply_to]
37
+ def generic(args)
38
+ # Load configuration
39
+ if !@configuration then
40
+ conf = args.delete(:configuration)
48
41
 
49
- # OTTENIAMO IL BODY
50
- plain_body = args.delete(:body) || args.delete(:plain_body) || args.delete(:text_body) || args.delete(:plain_text) || args.delete(:text)
51
- html_body = args.delete(:html_body) || args.delete(:html)
42
+ if conf then
43
+ @configuration = conf
44
+ else
45
+ self.setup(args.delete(:method) || :smtp, args.delete(:configuration_file))
46
+ end
47
+ end
52
48
 
53
- mail(args) do |format|
54
- if plain_body then # SE C'E' PLAIN BODY
55
- format.text { render :text => plain_body }
56
- end
57
- if html_body then # SE C'E' HTML
58
- format.html { render :text => html_body }
59
- end
60
- end
61
- end
62
- end
63
- end
64
- end
49
+ # OTTENIAMO GLI ARGOMENTI
50
+ args = (args.is_a?(Hash) ? args : args[0]).delete_if { |k,v| v.blank? }
51
+
52
+ # AGGIUSTIAMO REPLY TO
53
+ args[:reply_to] = args[:from] if !args[:reply_to]
54
+
55
+ # OTTENIAMO IL BODY
56
+ plain_body = args.delete(:body) || args.delete(:plain_body) || args.delete(:text_body) || args.delete(:plain_text) || args.delete(:text)
57
+ html_body = args.delete(:html_body) || args.delete(:html)
58
+
59
+ mail(args) do |format|
60
+ if plain_body then # SE C'E' PLAIN BODY
61
+ format.text { render :text => plain_body }
62
+ end
63
+ if html_body then # SE C'E' HTML
64
+ format.html { render :text => html_body }
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
65
71
  end
@@ -4,24 +4,24 @@
4
4
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
5
  #
6
6
 
7
- dir = File.dirname(__FILE__)
7
+ dir = File.dirname(__FILE__)
8
8
 
9
- require 'rake'
10
- require 'cowtech-extensions'
11
- require 'cowtech/extensions'
12
- require 'cowtech/monkey_patches'
13
- require 'cowtech/scheduler'
9
+ require "rake"
10
+ require "cowtech-extensions"
11
+ require "cowtech/extensions"
12
+ require "cowtech/monkey_patches"
13
+ require "cowtech/scheduler"
14
14
 
15
15
  module Cowtech
16
- class Engine < Rails::Engine
17
- rake_tasks do
18
- load "cowtech/tasks/app.rake"
19
- load "cowtech/tasks/log.rake"
20
- load "cowtech/tasks/server.rake"
21
- load "cowtech/tasks/sql.rake"
22
- load "cowtech/tasks/mongodb.rake"
23
- end
24
- end
16
+ class Engine < Rails::Engine
17
+ rake_tasks do
18
+ load "cowtech/tasks/app.rake"
19
+ load "cowtech/tasks/log.rake"
20
+ load "cowtech/tasks/server.rake"
21
+ load "cowtech/tasks/sql.rake"
22
+ load "cowtech/tasks/mongodb.rake"
23
+ end
24
+ end
25
25
  end
26
26
 
27
27
  Cowtech::Extensions.load!
@@ -5,44 +5,44 @@
5
5
  #
6
6
 
7
7
  module SubdomainFu
8
- def self.override_only_path?
9
- true
10
- end
8
+ def self.override_only_path?
9
+ true
10
+ end
11
11
  end
12
12
 
13
13
  module Cowtech
14
- module RubyOnRails
15
- module Extensions
16
- module AR
17
- extend ActiveSupport::Concern
18
-
19
- module ClassMethods
20
- def find_or_create(oid, attributes = nil)
21
- begin
22
- self.find(oid)
23
- rescue ActiveRecord::RecordNotFound
24
- self.new(attributes)
25
- end
26
- end
14
+ module RubyOnRails
15
+ module Extensions
16
+ module AR
17
+ extend ActiveSupport::Concern
27
18
 
28
- def safe_find(oid)
29
- begin
30
- rv = self.find(oid)
31
- rescue ActiveRecord::RecordNotFound
32
- nil
33
- end
34
- end
19
+ module ClassMethods
20
+ def find_or_create(oid, attributes = nil)
21
+ begin
22
+ self.find(oid)
23
+ rescue ActiveRecord::RecordNotFound
24
+ self.new(attributes)
25
+ end
26
+ end
35
27
 
36
- def random
37
- c = self.count
38
- c != 0 ? self.find(:first, :offset => rand(c)) : nil
39
- end
28
+ def safe_find(oid)
29
+ begin
30
+ rv = self.find(oid)
31
+ rescue ActiveRecord::RecordNotFound
32
+ nil
33
+ end
34
+ end
40
35
 
41
- def per_page
42
- 25
43
- end
44
- end
45
- end
46
- end
47
- end
36
+ def random
37
+ c = self.count
38
+ c != 0 ? self.find(:first, :offset => rand(c)) : nil
39
+ end
40
+
41
+ def per_page
42
+ 25
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
48
  end
@@ -6,66 +6,66 @@
6
6
 
7
7
  # To enable real SSL
8
8
  if defined?(Mail) then
9
- class Mail::SMTP
10
- def deliver!(mail)
9
+ class Mail::SMTP
10
+ def deliver!(mail)
11
11
 
12
- # Set the envelope from to be either the return-path, the sender or the first from address
13
- envelope_from = mail.return_path || mail.sender || mail.from_addrs.first
14
- if envelope_from.blank?
15
- raise ArgumentError.new('A sender (Return-Path, Sender or From) required to send a message')
16
- end
12
+ # Set the envelope from to be either the return-path, the sender or the first from address
13
+ envelope_from = mail.return_path || mail.sender || mail.from_addrs.first
14
+ if envelope_from.blank?
15
+ raise ArgumentError.new('A sender (Return-Path, Sender or From) required to send a message')
16
+ end
17
17
 
18
- destinations ||= mail.destinations if mail.respond_to?(:destinations) && mail.destinations
19
- if destinations.blank?
20
- raise ArgumentError.new('At least one recipient (To, Cc or Bcc) is required to send a message')
21
- end
18
+ destinations ||= mail.destinations if mail.respond_to?(:destinations) && mail.destinations
19
+ if destinations.blank?
20
+ raise ArgumentError.new('At least one recipient (To, Cc or Bcc) is required to send a message')
21
+ end
22
22
 
23
- message ||= mail.encoded if mail.respond_to?(:encoded)
24
- if message.blank?
25
- raise ArgumentError.new('A encoded content is required to send a message')
26
- end
23
+ message ||= mail.encoded if mail.respond_to?(:encoded)
24
+ if message.blank?
25
+ raise ArgumentError.new('A encoded content is required to send a message')
26
+ end
27
27
 
28
- smtp = Net::SMTP.new(settings[:address], settings[:port])
29
- if settings[:tls] || settings[:ssl]
30
- if smtp.respond_to?(:enable_tls)
31
- if !settings[:openssl_verify_mode]
32
- smtp.enable_tls
33
- else
34
- openssl_verify_mode = settings[:openssl_verify_mode]
35
- if openssl_verify_mode.kind_of?(String)
36
- openssl_verify_mode = "OpenSSL::SSL::VERIFY_#{openssl_verify_mode.upcase}".constantize
37
- end
38
- context = Net::SMTP.default_ssl_context
39
- context.verify_mode = openssl_verify_mode
40
- smtp.enable_tls(context)
41
- end
42
- end
43
- elsif settings[:enable_starttls_auto]
44
- if smtp.respond_to?(:enable_starttls_auto)
45
- if !settings[:openssl_verify_mode]
46
- smtp.enable_starttls_auto
47
- else
48
- openssl_verify_mode = settings[:openssl_verify_mode]
49
- if openssl_verify_mode.kind_of?(String)
50
- openssl_verify_mode = "OpenSSL::SSL::VERIFY_#{openssl_verify_mode.upcase}".constantize
51
- end
52
- context = Net::SMTP.default_ssl_context
53
- context.verify_mode = openssl_verify_mode
54
- smtp.enable_starttls_auto(context)
55
- end
56
- end
57
- end
58
- smtp.start(settings[:domain], settings[:user_name], settings[:password], settings[:authentication]) do |smtp|
59
- smtp.sendmail(message, envelope_from, destinations)
60
- end
28
+ smtp = Net::SMTP.new(settings[:address], settings[:port])
29
+ if settings[:tls] || settings[:ssl]
30
+ if smtp.respond_to?(:enable_tls)
31
+ if !settings[:openssl_verify_mode]
32
+ smtp.enable_tls
33
+ else
34
+ openssl_verify_mode = settings[:openssl_verify_mode]
35
+ if openssl_verify_mode.kind_of?(String)
36
+ openssl_verify_mode = "OpenSSL::SSL::VERIFY_#{openssl_verify_mode.upcase}".constantize
37
+ end
38
+ context = Net::SMTP.default_ssl_context
39
+ context.verify_mode = openssl_verify_mode
40
+ smtp.enable_tls(context)
41
+ end
42
+ end
43
+ elsif settings[:enable_starttls_auto]
44
+ if smtp.respond_to?(:enable_starttls_auto)
45
+ if !settings[:openssl_verify_mode]
46
+ smtp.enable_starttls_auto
47
+ else
48
+ openssl_verify_mode = settings[:openssl_verify_mode]
49
+ if openssl_verify_mode.kind_of?(String)
50
+ openssl_verify_mode = "OpenSSL::SSL::VERIFY_#{openssl_verify_mode.upcase}".constantize
51
+ end
52
+ context = Net::SMTP.default_ssl_context
53
+ context.verify_mode = openssl_verify_mode
54
+ smtp.enable_starttls_auto(context)
55
+ end
56
+ end
57
+ end
58
+ smtp.start(settings[:domain], settings[:user_name], settings[:password], settings[:authentication]) do |smtp|
59
+ smtp.sendmail(message, envelope_from, destinations)
60
+ end
61
61
 
62
- self
63
- end
64
- end
62
+ self
63
+ end
64
+ end
65
65
  end
66
66
 
67
67
  if defined?(ActiveRecord) then
68
- class ActiveRecord::Base
69
- include Cowtech::RubyOnRails::Extensions::AR
70
- end
68
+ class ActiveRecord::Base
69
+ include Cowtech::RubyOnRails::Extensions::AR
70
+ end
71
71
  end