activerecord 4.1.15 → 4.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +634 -2176
  3. data/README.rdoc +15 -10
  4. data/lib/active_record/aggregations.rb +12 -8
  5. data/lib/active_record/associations/association.rb +1 -1
  6. data/lib/active_record/associations/association_scope.rb +53 -21
  7. data/lib/active_record/associations/belongs_to_association.rb +15 -5
  8. data/lib/active_record/associations/builder/association.rb +16 -5
  9. data/lib/active_record/associations/builder/belongs_to.rb +7 -29
  10. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +2 -11
  11. data/lib/active_record/associations/builder/has_one.rb +2 -2
  12. data/lib/active_record/associations/builder/singular_association.rb +8 -1
  13. data/lib/active_record/associations/collection_association.rb +32 -44
  14. data/lib/active_record/associations/collection_proxy.rb +1 -10
  15. data/lib/active_record/associations/has_many_association.rb +60 -14
  16. data/lib/active_record/associations/has_many_through_association.rb +34 -23
  17. data/lib/active_record/associations/has_one_association.rb +0 -1
  18. data/lib/active_record/associations/join_dependency/join_association.rb +18 -14
  19. data/lib/active_record/associations/join_dependency.rb +7 -9
  20. data/lib/active_record/associations/preloader/association.rb +9 -5
  21. data/lib/active_record/associations/preloader/through_association.rb +3 -3
  22. data/lib/active_record/associations/preloader.rb +2 -2
  23. data/lib/active_record/associations/singular_association.rb +16 -1
  24. data/lib/active_record/associations/through_association.rb +6 -22
  25. data/lib/active_record/associations.rb +58 -33
  26. data/lib/active_record/attribute.rb +131 -0
  27. data/lib/active_record/attribute_assignment.rb +19 -11
  28. data/lib/active_record/attribute_decorators.rb +66 -0
  29. data/lib/active_record/attribute_methods/before_type_cast.rb +2 -2
  30. data/lib/active_record/attribute_methods/dirty.rb +85 -42
  31. data/lib/active_record/attribute_methods/primary_key.rb +6 -8
  32. data/lib/active_record/attribute_methods/read.rb +14 -57
  33. data/lib/active_record/attribute_methods/serialization.rb +12 -146
  34. data/lib/active_record/attribute_methods/time_zone_conversion.rb +32 -40
  35. data/lib/active_record/attribute_methods/write.rb +8 -23
  36. data/lib/active_record/attribute_methods.rb +53 -90
  37. data/lib/active_record/attribute_set/builder.rb +32 -0
  38. data/lib/active_record/attribute_set.rb +77 -0
  39. data/lib/active_record/attributes.rb +122 -0
  40. data/lib/active_record/autosave_association.rb +11 -21
  41. data/lib/active_record/base.rb +9 -19
  42. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +69 -45
  43. data/lib/active_record/connection_adapters/abstract/database_statements.rb +22 -42
  44. data/lib/active_record/connection_adapters/abstract/quoting.rb +59 -60
  45. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +37 -2
  46. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +102 -21
  47. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +9 -33
  48. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +178 -55
  49. data/lib/active_record/connection_adapters/abstract/transaction.rb +120 -115
  50. data/lib/active_record/connection_adapters/abstract_adapter.rb +143 -57
  51. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +156 -107
  52. data/lib/active_record/connection_adapters/column.rb +13 -244
  53. data/lib/active_record/connection_adapters/connection_specification.rb +6 -20
  54. data/lib/active_record/connection_adapters/mysql2_adapter.rb +12 -15
  55. data/lib/active_record/connection_adapters/mysql_adapter.rb +55 -143
  56. data/lib/active_record/connection_adapters/postgresql/array_parser.rb +15 -27
  57. data/lib/active_record/connection_adapters/postgresql/column.rb +20 -0
  58. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +39 -20
  59. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +96 -0
  60. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +52 -0
  61. data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +13 -0
  62. data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +14 -0
  63. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +46 -0
  64. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +11 -0
  65. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +27 -0
  66. data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +13 -0
  67. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +17 -0
  68. data/lib/active_record/connection_adapters/postgresql/oid/float.rb +21 -0
  69. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +59 -0
  70. data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +13 -0
  71. data/lib/active_record/connection_adapters/postgresql/oid/infinity.rb +13 -0
  72. data/lib/active_record/connection_adapters/postgresql/oid/integer.rb +11 -0
  73. data/lib/active_record/connection_adapters/postgresql/oid/json.rb +35 -0
  74. data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +23 -0
  75. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +43 -0
  76. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +43 -0
  77. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +76 -0
  78. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +15 -0
  79. data/lib/active_record/connection_adapters/postgresql/oid/time.rb +11 -0
  80. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +85 -0
  81. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +26 -0
  82. data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +26 -0
  83. data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +28 -0
  84. data/lib/active_record/connection_adapters/postgresql/oid.rb +29 -388
  85. data/lib/active_record/connection_adapters/postgresql/quoting.rb +42 -122
  86. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +4 -4
  87. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +154 -0
  88. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +86 -34
  89. data/lib/active_record/connection_adapters/postgresql/utils.rb +66 -0
  90. data/lib/active_record/connection_adapters/postgresql_adapter.rb +188 -452
  91. data/lib/active_record/connection_adapters/schema_cache.rb +14 -28
  92. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +54 -47
  93. data/lib/active_record/connection_handling.rb +1 -1
  94. data/lib/active_record/core.rb +119 -22
  95. data/lib/active_record/counter_cache.rb +60 -6
  96. data/lib/active_record/enum.rb +9 -10
  97. data/lib/active_record/errors.rb +27 -26
  98. data/lib/active_record/explain.rb +1 -1
  99. data/lib/active_record/fixtures.rb +52 -45
  100. data/lib/active_record/gem_version.rb +3 -3
  101. data/lib/active_record/inheritance.rb +33 -8
  102. data/lib/active_record/integration.rb +4 -4
  103. data/lib/active_record/locking/optimistic.rb +34 -16
  104. data/lib/active_record/migration/command_recorder.rb +19 -2
  105. data/lib/active_record/migration/join_table.rb +1 -1
  106. data/lib/active_record/migration.rb +22 -32
  107. data/lib/active_record/model_schema.rb +39 -48
  108. data/lib/active_record/nested_attributes.rb +8 -18
  109. data/lib/active_record/persistence.rb +39 -22
  110. data/lib/active_record/query_cache.rb +3 -3
  111. data/lib/active_record/querying.rb +1 -8
  112. data/lib/active_record/railtie.rb +17 -10
  113. data/lib/active_record/railties/databases.rake +47 -42
  114. data/lib/active_record/readonly_attributes.rb +0 -1
  115. data/lib/active_record/reflection.rb +225 -92
  116. data/lib/active_record/relation/batches.rb +0 -2
  117. data/lib/active_record/relation/calculations.rb +28 -32
  118. data/lib/active_record/relation/delegation.rb +1 -1
  119. data/lib/active_record/relation/finder_methods.rb +42 -20
  120. data/lib/active_record/relation/merger.rb +0 -1
  121. data/lib/active_record/relation/predicate_builder/array_handler.rb +16 -11
  122. data/lib/active_record/relation/predicate_builder/relation_handler.rb +0 -4
  123. data/lib/active_record/relation/predicate_builder.rb +1 -22
  124. data/lib/active_record/relation/query_methods.rb +98 -62
  125. data/lib/active_record/relation/spawn_methods.rb +6 -7
  126. data/lib/active_record/relation.rb +35 -11
  127. data/lib/active_record/result.rb +16 -9
  128. data/lib/active_record/sanitization.rb +8 -1
  129. data/lib/active_record/schema.rb +0 -1
  130. data/lib/active_record/schema_dumper.rb +51 -9
  131. data/lib/active_record/schema_migration.rb +4 -0
  132. data/lib/active_record/scoping/default.rb +5 -4
  133. data/lib/active_record/serializers/xml_serializer.rb +3 -7
  134. data/lib/active_record/statement_cache.rb +79 -5
  135. data/lib/active_record/store.rb +5 -5
  136. data/lib/active_record/tasks/database_tasks.rb +37 -5
  137. data/lib/active_record/tasks/mysql_database_tasks.rb +1 -1
  138. data/lib/active_record/tasks/postgresql_database_tasks.rb +2 -2
  139. data/lib/active_record/timestamp.rb +9 -7
  140. data/lib/active_record/transactions.rb +35 -21
  141. data/lib/active_record/type/binary.rb +40 -0
  142. data/lib/active_record/type/boolean.rb +19 -0
  143. data/lib/active_record/type/date.rb +46 -0
  144. data/lib/active_record/type/date_time.rb +43 -0
  145. data/lib/active_record/type/decimal.rb +40 -0
  146. data/lib/active_record/type/decimal_without_scale.rb +11 -0
  147. data/lib/active_record/type/float.rb +19 -0
  148. data/lib/active_record/type/hash_lookup_type_map.rb +19 -0
  149. data/lib/active_record/type/integer.rb +23 -0
  150. data/lib/active_record/type/mutable.rb +16 -0
  151. data/lib/active_record/type/numeric.rb +36 -0
  152. data/lib/active_record/type/serialized.rb +51 -0
  153. data/lib/active_record/type/string.rb +36 -0
  154. data/lib/active_record/type/text.rb +11 -0
  155. data/lib/active_record/type/time.rb +26 -0
  156. data/lib/active_record/type/time_value.rb +38 -0
  157. data/lib/active_record/type/type_map.rb +48 -0
  158. data/lib/active_record/type/value.rb +101 -0
  159. data/lib/active_record/type.rb +20 -0
  160. data/lib/active_record/validations/uniqueness.rb +9 -23
  161. data/lib/active_record/validations.rb +21 -16
  162. data/lib/active_record.rb +2 -1
  163. data/lib/rails/generators/active_record/migration/migration_generator.rb +8 -4
  164. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +1 -1
  165. data/lib/rails/generators/active_record/model/templates/model.rb +1 -1
  166. metadata +71 -14
  167. data/lib/active_record/connection_adapters/postgresql/cast.rb +0 -168
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.15
4
+ version: 4.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-07 00:00:00.000000000 Z
11
+ date: 2014-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,42 +16,48 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.15
19
+ version: 4.2.0.beta1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 4.1.15
26
+ version: 4.2.0.beta1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 4.1.15
33
+ version: 4.2.0.beta1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 4.1.15
40
+ version: 4.2.0.beta1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: arel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 5.0.0
47
+ version: 6.0.0.beta1
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '6.1'
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - "~>"
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 6.0.0.beta1
58
+ - - "<"
53
59
  - !ruby/object:Gem::Version
54
- version: 5.0.0
60
+ version: '6.1'
55
61
  description: Databases on Rails. Build a persistent domain model by mapping database
56
62
  tables to Ruby classes. Strong conventions for associations, validations, aggregations,
57
63
  migrations, and testing come baked-in.
@@ -104,7 +110,9 @@ files:
104
110
  - lib/active_record/associations/preloader/through_association.rb
105
111
  - lib/active_record/associations/singular_association.rb
106
112
  - lib/active_record/associations/through_association.rb
113
+ - lib/active_record/attribute.rb
107
114
  - lib/active_record/attribute_assignment.rb
115
+ - lib/active_record/attribute_decorators.rb
108
116
  - lib/active_record/attribute_methods.rb
109
117
  - lib/active_record/attribute_methods/before_type_cast.rb
110
118
  - lib/active_record/attribute_methods/dirty.rb
@@ -114,6 +122,9 @@ files:
114
122
  - lib/active_record/attribute_methods/serialization.rb
115
123
  - lib/active_record/attribute_methods/time_zone_conversion.rb
116
124
  - lib/active_record/attribute_methods/write.rb
125
+ - lib/active_record/attribute_set.rb
126
+ - lib/active_record/attribute_set/builder.rb
127
+ - lib/active_record/attributes.rb
117
128
  - lib/active_record/autosave_association.rb
118
129
  - lib/active_record/base.rb
119
130
  - lib/active_record/callbacks.rb
@@ -137,12 +148,39 @@ files:
137
148
  - lib/active_record/connection_adapters/mysql2_adapter.rb
138
149
  - lib/active_record/connection_adapters/mysql_adapter.rb
139
150
  - lib/active_record/connection_adapters/postgresql/array_parser.rb
140
- - lib/active_record/connection_adapters/postgresql/cast.rb
151
+ - lib/active_record/connection_adapters/postgresql/column.rb
141
152
  - lib/active_record/connection_adapters/postgresql/database_statements.rb
142
153
  - lib/active_record/connection_adapters/postgresql/oid.rb
154
+ - lib/active_record/connection_adapters/postgresql/oid/array.rb
155
+ - lib/active_record/connection_adapters/postgresql/oid/bit.rb
156
+ - lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb
157
+ - lib/active_record/connection_adapters/postgresql/oid/bytea.rb
158
+ - lib/active_record/connection_adapters/postgresql/oid/cidr.rb
159
+ - lib/active_record/connection_adapters/postgresql/oid/date.rb
160
+ - lib/active_record/connection_adapters/postgresql/oid/date_time.rb
161
+ - lib/active_record/connection_adapters/postgresql/oid/decimal.rb
162
+ - lib/active_record/connection_adapters/postgresql/oid/enum.rb
163
+ - lib/active_record/connection_adapters/postgresql/oid/float.rb
164
+ - lib/active_record/connection_adapters/postgresql/oid/hstore.rb
165
+ - lib/active_record/connection_adapters/postgresql/oid/inet.rb
166
+ - lib/active_record/connection_adapters/postgresql/oid/infinity.rb
167
+ - lib/active_record/connection_adapters/postgresql/oid/integer.rb
168
+ - lib/active_record/connection_adapters/postgresql/oid/json.rb
169
+ - lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
170
+ - lib/active_record/connection_adapters/postgresql/oid/money.rb
171
+ - lib/active_record/connection_adapters/postgresql/oid/point.rb
172
+ - lib/active_record/connection_adapters/postgresql/oid/range.rb
173
+ - lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb
174
+ - lib/active_record/connection_adapters/postgresql/oid/time.rb
175
+ - lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb
176
+ - lib/active_record/connection_adapters/postgresql/oid/uuid.rb
177
+ - lib/active_record/connection_adapters/postgresql/oid/vector.rb
178
+ - lib/active_record/connection_adapters/postgresql/oid/xml.rb
143
179
  - lib/active_record/connection_adapters/postgresql/quoting.rb
144
180
  - lib/active_record/connection_adapters/postgresql/referential_integrity.rb
181
+ - lib/active_record/connection_adapters/postgresql/schema_definitions.rb
145
182
  - lib/active_record/connection_adapters/postgresql/schema_statements.rb
183
+ - lib/active_record/connection_adapters/postgresql/utils.rb
146
184
  - lib/active_record/connection_adapters/postgresql_adapter.rb
147
185
  - lib/active_record/connection_adapters/schema_cache.rb
148
186
  - lib/active_record/connection_adapters/sqlite3_adapter.rb
@@ -213,6 +251,25 @@ files:
213
251
  - lib/active_record/timestamp.rb
214
252
  - lib/active_record/transactions.rb
215
253
  - lib/active_record/translation.rb
254
+ - lib/active_record/type.rb
255
+ - lib/active_record/type/binary.rb
256
+ - lib/active_record/type/boolean.rb
257
+ - lib/active_record/type/date.rb
258
+ - lib/active_record/type/date_time.rb
259
+ - lib/active_record/type/decimal.rb
260
+ - lib/active_record/type/decimal_without_scale.rb
261
+ - lib/active_record/type/float.rb
262
+ - lib/active_record/type/hash_lookup_type_map.rb
263
+ - lib/active_record/type/integer.rb
264
+ - lib/active_record/type/mutable.rb
265
+ - lib/active_record/type/numeric.rb
266
+ - lib/active_record/type/serialized.rb
267
+ - lib/active_record/type/string.rb
268
+ - lib/active_record/type/text.rb
269
+ - lib/active_record/type/time.rb
270
+ - lib/active_record/type/time_value.rb
271
+ - lib/active_record/type/type_map.rb
272
+ - lib/active_record/type/value.rb
216
273
  - lib/active_record/validations.rb
217
274
  - lib/active_record/validations/associated.rb
218
275
  - lib/active_record/validations/presence.rb
@@ -243,12 +300,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
300
  version: 1.9.3
244
301
  required_rubygems_version: !ruby/object:Gem::Requirement
245
302
  requirements:
246
- - - ">="
303
+ - - ">"
247
304
  - !ruby/object:Gem::Version
248
- version: '0'
305
+ version: 1.3.1
249
306
  requirements: []
250
307
  rubyforge_project:
251
- rubygems_version: 2.5.1
308
+ rubygems_version: 2.2.2
252
309
  signing_key:
253
310
  specification_version: 4
254
311
  summary: Object-relational mapper framework (part of Rails).
@@ -1,168 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- class PostgreSQLColumn < Column
4
- module Cast
5
- def point_to_string(point)
6
- "(#{point[0]},#{point[1]})"
7
- end
8
-
9
- def string_to_point(string)
10
- if string[0] == '(' && string[-1] == ')'
11
- string = string[1...-1]
12
- end
13
- string.split(',').map{ |v| Float(v) }
14
- end
15
-
16
- def string_to_time(string)
17
- return string unless String === string
18
-
19
- case string
20
- when 'infinity'; Float::INFINITY
21
- when '-infinity'; -Float::INFINITY
22
- when / BC$/
23
- super("-" + string.sub(/ BC$/, ""))
24
- else
25
- super
26
- end
27
- end
28
-
29
- def string_to_bit(value)
30
- case value
31
- when /^0x/i
32
- value[2..-1].hex.to_s(2) # Hexadecimal notation
33
- else
34
- value # Bit-string notation
35
- end
36
- end
37
-
38
- def hstore_to_string(object, array_member = false)
39
- if Hash === object
40
- string = object.map { |k, v| "#{escape_hstore(k)}=>#{escape_hstore(v)}" }.join(',')
41
- string = escape_hstore(string) if array_member
42
- string
43
- else
44
- object
45
- end
46
- end
47
-
48
- def string_to_hstore(string)
49
- if string.nil?
50
- nil
51
- elsif String === string
52
- Hash[string.scan(HstorePair).map { |k, v|
53
- v = v.upcase == 'NULL' ? nil : v.gsub(/\A"(.*)"\Z/m,'\1').gsub(/\\(.)/, '\1')
54
- k = k.gsub(/\A"(.*)"\Z/m,'\1').gsub(/\\(.)/, '\1')
55
- [k, v]
56
- }]
57
- else
58
- string
59
- end
60
- end
61
-
62
- def json_to_string(object)
63
- if Hash === object || Array === object
64
- ActiveSupport::JSON.encode(object)
65
- else
66
- object
67
- end
68
- end
69
-
70
- def array_to_string(value, column, adapter)
71
- casted_values = value.map do |val|
72
- if String === val
73
- if val == "NULL"
74
- "\"#{val}\""
75
- else
76
- quote_and_escape(adapter.type_cast(val, column, true))
77
- end
78
- else
79
- adapter.type_cast(val, column, true)
80
- end
81
- end
82
- "{#{casted_values.join(',')}}"
83
- end
84
-
85
- def range_to_string(object)
86
- from = object.begin.respond_to?(:infinite?) && object.begin.infinite? ? '' : object.begin
87
- to = object.end.respond_to?(:infinite?) && object.end.infinite? ? '' : object.end
88
- "[#{from},#{to}#{object.exclude_end? ? ')' : ']'}"
89
- end
90
-
91
- def string_to_json(string)
92
- if String === string
93
- ActiveSupport::JSON.decode(string)
94
- else
95
- string
96
- end
97
- end
98
-
99
- def string_to_cidr(string)
100
- if string.nil?
101
- nil
102
- elsif String === string
103
- begin
104
- IPAddr.new(string)
105
- rescue ArgumentError
106
- nil
107
- end
108
- else
109
- string
110
- end
111
- end
112
-
113
- def cidr_to_string(object)
114
- if IPAddr === object
115
- "#{object.to_s}/#{object.instance_variable_get(:@mask_addr).to_s(2).count('1')}"
116
- else
117
- object
118
- end
119
- end
120
-
121
- def string_to_array(string, oid)
122
- parse_pg_array(string).map {|val| type_cast_array(oid, val)}
123
- end
124
-
125
- private
126
-
127
- HstorePair = begin
128
- quoted_string = /"[^"\\]*(?:\\.[^"\\]*)*"/
129
- unquoted_string = /(?:\\.|[^\s,])[^\s=,\\]*(?:\\.[^\s=,\\]*|=[^,>])*/
130
- /(#{quoted_string}|#{unquoted_string})\s*=>\s*(#{quoted_string}|#{unquoted_string})/
131
- end
132
-
133
- def escape_hstore(value)
134
- if value.nil?
135
- 'NULL'
136
- else
137
- if value == ""
138
- '""'
139
- else
140
- '"%s"' % value.to_s.gsub(/(["\\])/, '\\\\\1')
141
- end
142
- end
143
- end
144
-
145
- ARRAY_ESCAPE = "\\" * 2 * 2 # escape the backslash twice for PG arrays
146
-
147
- def quote_and_escape(value)
148
- case value
149
- when "NULL", Numeric
150
- value
151
- else
152
- value = value.gsub(/\\/, ARRAY_ESCAPE)
153
- value.gsub!(/"/,"\\\"")
154
- "\"#{value}\""
155
- end
156
- end
157
-
158
- def type_cast_array(oid, value)
159
- if ::Array === value
160
- value.map {|item| type_cast_array(oid, item)}
161
- else
162
- oid.type_cast value
163
- end
164
- end
165
- end
166
- end
167
- end
168
- end