cowtech-rails 1.9.1.0 → 1.9.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,7 @@ module Cowtech
9
9
  module Version
10
10
  MAJOR = 1
11
11
  MINOR = 9
12
- PATCH = 1
12
+ PATCH = 5
13
13
  BUILD = 0
14
14
 
15
15
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
data/lib/cowtech.rb CHANGED
@@ -16,38 +16,4 @@ module Cowtech
16
16
  end
17
17
  end
18
18
 
19
- Object.class_eval do
20
- include Cowtech::RubyOnRails::Extensions::Object
21
- end
22
-
23
- TrueClass.class_eval do
24
- include Cowtech::RubyOnRails::Extensions::True
25
- end
26
-
27
- FalseClass.class_eval do
28
- include Cowtech::RubyOnRails::Extensions::False
29
- end
30
-
31
- String.class_eval do
32
- include Cowtech::RubyOnRails::Extensions::String
33
- end
34
-
35
- Time.class_eval do
36
- include Cowtech::RubyOnRails::Extensions::DateTime
37
- end
38
-
39
- Date.class_eval do
40
- include Cowtech::RubyOnRails::Extensions::DateTime
41
- end
42
-
43
- DateTime.class_eval do
44
- include Cowtech::RubyOnRails::Extensions::DateTime
45
- end
46
-
47
- Hash.class_eval do
48
- include Cowtech::RubyOnRails::Extensions::Hash
49
- end
50
-
51
- Pathname.class_eval do
52
- include Cowtech::RubyOnRails::Extensions::Pathname
53
- end
19
+ Cowtech::Extensions.load!
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: 1.9.1.0
4
+ version: 1.9.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-22 00:00:00.000000000Z
13
- dependencies: []
12
+ date: 2011-07-29 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cowtech-extensions
16
+ requirement: &70317688371300 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70317688371300
14
25
  description: A general purpose Rails utility plugin.
15
26
  email: shogun_panda@me.com
16
27
  executables: []
@@ -26,7 +37,6 @@ files:
26
37
  - app/models/cowtech/ruby_on_rails/models/e_mail.rb
27
38
  - app/models/cowtech/ruby_on_rails/models/model_base.rb
28
39
  - lib/cowtech.rb
29
- - lib/cowtech/extensions.rb
30
40
  - lib/cowtech/monkey_patches.rb
31
41
  - lib/cowtech/version.rb
32
42
  - rails/init.rb
@@ -1,301 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # This file is part of the cowtech-rails gem. Copyright (C) 2011 and above Shogun <shogun_panda@me.com>.
4
- # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
- #
6
-
7
- module Cowtech
8
- module RubyOnRails
9
- module Extensions
10
- module Object
11
- include ActionView::Helpers::NumberHelper
12
-
13
- def nil_as_string
14
- if self.blank? then "" else self end
15
- end
16
-
17
- def is_valid_number?
18
- self.is_valid_float?
19
- end
20
-
21
- def is_valid_integer?
22
- self.is_a?(Integer) || (!self.blank? && /^([+-]?)(\d+)$/.match(self.to_s.strip) != nil)
23
- end
24
-
25
- def is_valid_float?
26
- self.is_a?(Float) || (!self.blank? && /^([+-]?)(\d+)([.,]\d*)?$/.match(self.to_s.strip) != nil)
27
- end
28
-
29
- def is_valid_boolean?
30
- self.is_a?(TrueClass) || self.is_a?(FalseClass) || self.is_a?(NilClass) || /^(1|0|true|false|yes|no|t|f|y|n)$/i.match(self.to_s.strip) != nil
31
- end
32
-
33
- def ensure_array
34
- self.is_a?(Array) ? self : [self]
35
- end
36
-
37
- def to_float
38
- self.is_valid_float? ? Kernel.Float(self.respond_to?(:gsub) ? self.gsub(",", ".") : self) : 0.0
39
- end
40
-
41
- def to_integer
42
- self.is_valid_integer? ? Kernel.Integer(self, self.is_a?(String) ? 10 : 0) : 0
43
- end
44
-
45
- def to_boolean
46
- (self.is_a?(TrueClass) || /^(1|on|true|yes|t|y)$/i.match(self.to_s.strip)) ? true : false
47
- end
48
-
49
- def round_to_precision(prec = 2)
50
- number_with_precision(self, :precision => prec)
51
- end
52
-
53
- def format_number(prec = 2, decimal_separator = ",", add_string = "€", k_separator = ".")
54
- number_to_currency(self,
55
- {
56
- :precision => prec,
57
- :separator => decimal_separator,
58
- :delimiter => k_separator,
59
- :format => if add_string.blank? then "%n" else "%n %u" end,
60
- :unit => if add_string.blank? then "" else add_string.strip end
61
- })
62
- end
63
-
64
- def format_boolean
65
- self.to_boolean ? "Yes" : "No"
66
- end
67
-
68
- def dump
69
- raise Exception.new("DUMP: #{self.to_yaml}")
70
- end
71
- end
72
-
73
- module True
74
- def to_i
75
- 1
76
- end
77
-
78
- def value
79
- self
80
- end
81
- end
82
-
83
- module False
84
- def to_i
85
- 0
86
- end
87
-
88
- def value
89
- self
90
- end
91
- end
92
-
93
- module String
94
- def remove_accents
95
- self.mb_chars.normalize(:kd).gsub(/[^\-x00-\x7F]/n, '').to_s
96
- end
97
-
98
- def untitleize
99
- self.downcase.gsub(" ", "-")
100
- end
101
-
102
- def replace_ampersands
103
- self.gsub(/&amp;(\S+);/, "&\\1;")
104
- end
105
- end
106
-
107
- module Hash
108
- def method_missing(method, *args, &block)
109
- if self.has_key?(method.to_sym) || self.has_key?(method.to_s) then
110
- self[method.to_sym] || self[method.to_s]
111
- else
112
- super(method, *args, &block)
113
- end
114
- end
115
-
116
- def respond_to?(method)
117
- if self.has_key?(method.to_sym) || self.has_key?(method.to_s) then
118
- true
119
- else
120
- super(method)
121
- end
122
- end
123
- end
124
-
125
- module Pathname
126
- def components
127
- rv = []
128
- self.each_filename do |p| rv << p end
129
- rv
130
- end
131
- end
132
-
133
- module DateTime
134
- module ClassMethods
135
- def months
136
- i = 0
137
- months = localized_months
138
- months.keys.collect do |k|
139
- i+= 1
140
- {:value => i.to_s.rjust(2, "0"), :description => months[k][0, 3]}
141
- end
142
- end
143
-
144
- def localized_months
145
- {"January" => "January", "February" => "February", "March" => "March", "April" => "April", "May" => "May", "June" => "June",
146
- "July" => "July", "August" => "August", "September" => "September", "October" => "October", "November" => "November", "December" => "December"}
147
- end
148
-
149
- def localized_days
150
- {"Sunday" => "Sunday", "Monday" => "Monday", "Tuesday" => "Tuesday", "Wednesday" => "Wednesday", "Thursday" => "Thursday", "Friday" => "Friday", "Saturday" => "Saturday"}
151
- end
152
-
153
- def custom_format(key="date")
154
- {
155
- "date" => "%d/%m/%Y",
156
- "time" => "%H:%M:%S",
157
- "date-8601" => "%Y-%m-%d",
158
- "date-time-8601" => "%Y-%m-%d %H:%M:%S",
159
- "iso-8601" => "%FT%T%z",
160
- "update" => "%d/%m/%Y %H:%M"
161
- }.fetch(key.to_s, "%d/%m/%Y")
162
- end
163
-
164
- def years(offset = 10, also_future = true)
165
- rv = []
166
- y = Date.today.year
167
- (y - offset..(also_future ? y + offset : y)).each do |year| rv << {:value => year} end
168
- rv
169
- end
170
-
171
- def localized_short_months
172
- rv = {}
173
- self.localized_months.each do |k,v| rv[k[0, 3]] = v[0, 3] end
174
- rv
175
- end
176
-
177
- def localized_short_days
178
- rv = {}
179
- self.localized_days.each do |k,v| rv[k[0, 3]] = v[0, 3] end
180
- rv
181
- end
182
-
183
- def easter(year = nil)
184
- day = 1
185
- month = 3
186
- year = Date.today.year if !year.is_valid_integer?
187
-
188
- # GAUSS METHOD
189
- m = 24
190
- n = 5
191
- a = year % 19
192
- b = year % 4
193
- c = year % 7
194
- d = ((19 * a) + m) % 30
195
- e = ((2 * b) + (4 * c) + (6 * d) + n) % 7
196
-
197
- if d + e < 10 then
198
- day = d + e + 22
199
- else
200
- day = d + e - 9
201
- month = 4
202
- end
203
-
204
- if day == 26 && month == 4 then
205
- day = 19
206
- elsif day == 25 && month == 4 && d == 28 && e == 6 && a > 10 then
207
- day = 18
208
- end
209
- #END
210
-
211
- Date.civil(year, month, day)
212
- end
213
- end
214
-
215
- def self.included(receiver)
216
- receiver.extend ClassMethods
217
- end
218
-
219
- def lstrftime(format = nil)
220
- format = self.class.custom_format($1) if format =~ /^custom::(.+)/
221
- unlocal = self.strftime(format || self.class.custom_format("update"))
222
-
223
- # CHANGE LONG DAYS AND MONTHS
224
- unlocal.gsub!(/(#{self.class.localized_months.keys.join("|")})/i) do |s| self.class.localized_months[$1] end
225
- unlocal.gsub!(/(#{self.class.localized_days.keys.join("|")})/i) do |s| self.class.localized_days[$1] end
226
-
227
- # CHANGE SHORT DAYS AND MONTHS
228
- unlocal.gsub!(/(#{self.class.localized_short_months.keys.join("|")})/i) do |s| self.class.localized_short_months[$1] end
229
- unlocal.gsub!(/(#{self.class.localized_short_days.keys.join("|")})/i) do |s| self.class.localized_short_days[$1] end
230
-
231
- unlocal
232
- end
233
-
234
- def padded_month
235
- self.month.to_s.rjust(2, "0")
236
- end
237
-
238
- def in_months
239
- ((self.year - 1) % 2000) * 12 + self.month
240
- end
241
-
242
- def utc_time
243
- (self.respond_to?(:utc) ? self : self.to_datetime).utc.to_time
244
- end
245
- end
246
- end
247
- end
248
- end
249
-
250
- module Math
251
- def self.max(a, b)
252
- if a > b then a else b end
253
- end
254
-
255
- def self.min(a, b)
256
- if a < b then a else b end
257
- end
258
- end
259
-
260
- if defined?(ActiveRecord) then
261
- class ActiveRecord::Base
262
- def self.table_prefix
263
- p = ActiveRecord::Base.configurations[Rails.env]["table_prefix"]
264
- !p.blank? ? p + "_" : ""
265
- end
266
-
267
- def self.table_suffix
268
- p = ActiveRecord::Base.configurations[Rails.env]["table_suffix"]
269
- !p.blank? ? p + "_" : ""
270
- end
271
-
272
- def self.set_table_name(value = nil, &block)
273
- define_attr_method :table_name, "#{ActiveRecord::Base.table_prefix}#{value}#{ActiveRecord::Base.table_suffix}", &block
274
- end
275
-
276
- def self.find_or_create(oid, attributes = nil)
277
- begin
278
- self.find(oid)
279
- rescue ActiveRecord::RecordNotFound
280
- self.new(attributes)
281
- end
282
- end
283
-
284
- def self.safe_find(oid)
285
- begin
286
- rv = self.find(oid)
287
- rescue ActiveRecord::RecordNotFound
288
- nil
289
- end
290
- end
291
-
292
- def self.random
293
- c = self.count
294
- c != 0 ? self.find(:first, :offset => rand(c)) : nil
295
- end
296
-
297
- def self.per_page
298
- 25
299
- end
300
- end
301
- end