rmtools 2.4.6 → 2.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 462fa51db69a84fe8f257bbaac98df036d08a1e4
4
- data.tar.gz: 3f10da60daaebaa0a70ee9c878a9f9bf41c5813c
3
+ metadata.gz: e1f4419c1717d05e6a3d242549d07990f8d78ed6
4
+ data.tar.gz: 58638b18e7c04d78fcd70c410570db7c2ec93843
5
5
  SHA512:
6
- metadata.gz: 4f23db7cd425392c4581341527d95870cda4e633029127b88cf1c5daf5ad15b15b6c4c8ca53c30ff7fe8602131e37f4167812dcf4fe361e723ea82c3ff16b835
7
- data.tar.gz: 1914047c1a63963c127b0b1d710867d37108f780ea0110c9f843d1115bb25706db2b2282b540e9bc4b0a1e0e2ae3f4109888976427ac8107fc67f637382cae5b
6
+ metadata.gz: 9cbf952f1d4d010ea366cdafbacdff9e0da4d770d239b0f2c73d9043143199de3f903374d04824d218d2bcfe03e1b0740397453394c7443435462c81e7e11b47
7
+ data.tar.gz: c6012f35f2d7a64066da100e39c10e35fa63b67daf8f87dac49e579e12988a057534466e57d02bfb45bf7f75e326b57a957e47625099fbb4bc01fdd17108f5f3
@@ -120,7 +120,7 @@ module ActiveRecord
120
120
  def boolean_scopes!
121
121
  columns.select_by_type(:boolean).names.to_syms.each {|col|
122
122
  unless respond_to? col
123
- scope col, where("#{quoted_table_name}.#{col} = 1")
123
+ scope col, lambda {where "#{quoted_table_name}.#{col} = 1"}
124
124
  end
125
125
  }
126
126
  rescue
@@ -133,7 +133,7 @@ module ActiveRecord
133
133
  boolean_scopes!
134
134
  columns.select_null.names.to_syms.each {|col|
135
135
  unless respond_to? col
136
- scope col, where("#{quoted_table_name}.#{col} is not null")
136
+ scope col, lambda {where "#{quoted_table_name}.#{col} is not null"}
137
137
  end
138
138
  }
139
139
  rescue
@@ -191,16 +191,18 @@ module ActiveRecord
191
191
 
192
192
  end
193
193
 
194
- class Relation
195
-
196
- def any?
197
- limit(1).count != 0
198
- end
199
-
200
- def empty?
201
- limit(1).count == 0
194
+ if ActiveRecord::VERSION::MAJOR < 4
195
+ class Relation
196
+
197
+ def any?
198
+ limit(1).count != 0
199
+ end
200
+
201
+ def empty?
202
+ limit(1).count == 0
203
+ end
204
+
202
205
  end
203
-
204
206
  end
205
207
 
206
208
  end
@@ -1,5 +1,5 @@
1
1
  # Overwrites slow ActiveSupport ActiveSupport::JSON.encode by faster Yajl or JSON libraries
2
- if Rails.version < '4'
2
+ if ActiveSupport.version.to_s < '4'
3
3
  require 'active_support/core_ext/object/to_json'
4
4
  else
5
5
  require 'active_support/core_ext/object/json'
@@ -72,6 +72,55 @@ class Object
72
72
  end
73
73
 
74
74
 
75
+ # def hard_method(args)
76
+ # ... hard_calculation ...
77
+ # end
78
+ #
79
+ # object.cached(:hard_method, *args1)
80
+ # > ... hard calculation ...
81
+ # => result with args1
82
+ # object.cached(:hard_method, *args1)
83
+ # => instant result with args1
84
+ # object.cached?(:hard_method, *args2)
85
+ # => false
86
+ # object.cached(:hard_method, *args2)
87
+ # > ... hard calculation ...
88
+ # => result with args2
89
+ # object.cached?(:hard_method, *args2)
90
+ # => true
91
+ # object.clear_cache(:hard_method, *args1)
92
+ # => result with args1
93
+ # object.cached?(:hard_method, *args1)
94
+ # => false
95
+ # object.cached(:hard_method, *args1)
96
+ # > ... hard calculation ...
97
+ # => result with args1
98
+ # object.cached(:hard_method, *args2)
99
+ # => instant result with args2
100
+ # object.clear_cache(:hard_method)
101
+ # => {args1 => result with args1, args2 => result with args2}
102
+ # [object.cached?(:hard_method, *args1), object.cached?(:hard_method, *args2)]
103
+ # => [false, false]
104
+ def cached(method, *args)
105
+ ((@__method_cache__ ||= {})[method.to_sym] ||= {})[args] ||= __send__ method, *args
106
+ end
107
+
108
+ def clear_cache(method, *args)
109
+ if @__method_cache__
110
+ if args.empty?
111
+ @__method_cache__.delete method.to_sym
112
+ elsif method_cache = @__method_cache__[method.to_sym]
113
+ method_cache.delete args
114
+ end
115
+ end
116
+ end
117
+
118
+ def cached?(method, *args)
119
+ ((@__method_cache__ ||= {})[method.to_sym] ||= {}).include? args
120
+ end
121
+
122
+
123
+
75
124
 
76
125
  def deep_clone
77
126
  _deep_clone({})
@@ -19,20 +19,24 @@ class Array
19
19
  end
20
20
  @@iterators_names = []
21
21
 
22
- private
23
-
24
- # It's here just because it's simplier and faster (40 times)
25
- # than ActiveSupport's singularization.
26
- # If you want to use latter one, run
27
- # Array.use_active_support_singularize!
22
+ private
23
+
28
24
  def simple_inplace_singularize!(noun)
29
- noun.sub!(/(ss|[sc]h|[xo])es([=!?]?)$/, '\1\2') or
30
- noun.sub!(/ies([=!?]?)$/, 'y\1') or
31
- noun.sub!(/s([=!?]?)$/, '\1')
25
+ Array.simple_inplace_singularize!(noun)
32
26
  end
33
27
 
34
28
  class << self
35
29
 
30
+ # It's here just because it's simplier and faster (40 times)
31
+ # than ActiveSupport's singularization.
32
+ # If you want to use latter one, run
33
+ # Array.use_active_support_singularize!
34
+ def simple_inplace_singularize!(noun)
35
+ noun.sub!(/(ss|[sc]h|[xo])es([=!?]?)$/, '\1\2') or
36
+ noun.sub!(/ies([=!?]?)$/, 'y\1') or
37
+ noun.sub!(/s([=!?]?)$/, '\1')
38
+ end
39
+
36
40
  def add_iterator_name(name_or_list)
37
41
  name_or_list = [name_or_list] if !name_or_list.is Array
38
42
  @@iterators_names |= name_or_list
@@ -123,6 +127,16 @@ private
123
127
  end
124
128
  end # class_eval
125
129
  end # def fallback_to_clean_iterators!
130
+
131
+ alias object_method_defined? method_defined?
132
+ def method_defined?(method, *private)
133
+ if object_method_defined?(method, *private)
134
+ true
135
+ else
136
+ method_str = method.to_s
137
+ !!method_str.match(@@iterators_pattern) or !!simple_inplace_singularize!(method_str)
138
+ end
139
+ end
126
140
 
127
141
  end # << self
128
142
 
@@ -1,3 +1,3 @@
1
1
  module RMTools
2
- VERSION = '2.4.6'
2
+ VERSION = '2.4.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.6
4
+ version: 2.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Baev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RMTools is a collection of helpers for debug, text/array/file processing
14
14
  and simply easing a coding process