better_record 0.10.2 → 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/better_record/concerns/active_record_extensions/base_extensions/attribute_methods.rb +8 -0
- data/lib/better_record/concerns/active_record_extensions/base_extensions/attribute_methods/write.rb +46 -0
- data/lib/better_record/version.rb +1 -1
- metadata +5 -4
- data/lib/better_record/concerns/active_record_extensions/attribute_methods/write.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 868f2ca1bb72db17669260a1d1ef913960d92f6f91c75ea48dcaa8f0bb5d1000
|
4
|
+
data.tar.gz: 1d504c0352fe3e2bbf64b5a0bfc027ce6c6de76e959cc58f62ee06949b6abcd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 330ebdd9bd1c8c1772d03290236705affbedb1f45c3fa7b99cc6b365365541cbe2d9afef7119d3fc862ab412d62ec1e89199cdaf8eba5fb21a94f6c531b1a854
|
7
|
+
data.tar.gz: c502594671fcfa886bf481366121ffa568d5bf19ceef39a393c5ab66e9ababdfc686300f6320cc4c9426c181de7e59e740c3df819b5736c2f0f2ac285f3aa61d
|
data/lib/better_record/concerns/active_record_extensions/base_extensions/attribute_methods/write.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BetterRecord
|
4
|
+
module BaseExtensions
|
5
|
+
module AttributeMethods
|
6
|
+
module Write
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
def _write_attribute(attr_name, value)
|
10
|
+
if should_normalize? attr_name
|
11
|
+
super(attr_name, normalize_attribute_value(attr_name, value))
|
12
|
+
else
|
13
|
+
super(attr_name, value)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def normalize_attribute_value(attr_name, value)
|
18
|
+
case type_for_attribute(attr_name)
|
19
|
+
when ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array
|
20
|
+
[value].flatten.select(&:present?)
|
21
|
+
when ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb
|
22
|
+
value.presence || {}
|
23
|
+
when ActiveRecord::Type::Boolean
|
24
|
+
BetterRecord.strict_booleans ? Boolean.strict_parse(value) : Boolean.parse(value)
|
25
|
+
else
|
26
|
+
value.presence
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def should_normalize?(attr_name)
|
31
|
+
if !respond_to?(:normalize_columns?) || normalize_columns?
|
32
|
+
if respond_to?(:normalized_columns)
|
33
|
+
normalized_columns.is_a?(Array) ?
|
34
|
+
normalized_columns.include?(attr_name.to_sym) :
|
35
|
+
normalized_columns[attr_name]
|
36
|
+
else
|
37
|
+
true
|
38
|
+
end
|
39
|
+
else
|
40
|
+
false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sampson Crowley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -267,8 +267,9 @@ files:
|
|
267
267
|
- lib/better_record/concerns/active_record_extensions/associations_extensions/association_scope_extensions.rb
|
268
268
|
- lib/better_record/concerns/active_record_extensions/associations_extensions/belongs_to_polymorphic_extensions.rb
|
269
269
|
- lib/better_record/concerns/active_record_extensions/associations_extensions/builder_extensions/association_extensions.rb
|
270
|
-
- lib/better_record/concerns/active_record_extensions/attribute_methods/write.rb
|
271
270
|
- lib/better_record/concerns/active_record_extensions/base_extensions.rb
|
271
|
+
- lib/better_record/concerns/active_record_extensions/base_extensions/attribute_methods.rb
|
272
|
+
- lib/better_record/concerns/active_record_extensions/base_extensions/attribute_methods/write.rb
|
272
273
|
- lib/better_record/concerns/active_record_extensions/connection_adapter_extensions.rb
|
273
274
|
- lib/better_record/concerns/active_record_extensions/reflection_extensions.rb
|
274
275
|
- lib/better_record/concerns/controllers/authenticatable.rb
|
@@ -333,7 +334,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
333
334
|
version: '0'
|
334
335
|
requirements: []
|
335
336
|
rubyforge_project:
|
336
|
-
rubygems_version: 2.7.
|
337
|
+
rubygems_version: 2.7.6
|
337
338
|
signing_key:
|
338
339
|
specification_version: 4
|
339
340
|
summary: Fix functions that are lacking in Active record to be compatible with multi-app
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module BetterRecord
|
4
|
-
module AttributeMethods
|
5
|
-
module Write
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
def _write_attribute(attr_name, value)
|
9
|
-
if should_normalize? attr_name
|
10
|
-
super(attr_name, normalize_attribute_value(attr_name, value))
|
11
|
-
else
|
12
|
-
super(attr_name, value)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def normalize_attribute_value(attr_name, value)
|
17
|
-
case type_for_attribute(attr_name)
|
18
|
-
when ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array
|
19
|
-
[value].flatten.select(&:present?)
|
20
|
-
when ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb
|
21
|
-
value.presence || {}
|
22
|
-
when ActiveRecord::Type::Boolean
|
23
|
-
BetterRecord.strict_booleans ? Boolean.strict_parse(value) : Boolean.parse(value)
|
24
|
-
else
|
25
|
-
value.presence
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def should_normalize?(attr_name)
|
30
|
-
if !respond_to?(:normalize_columns?) || normalize_columns?
|
31
|
-
if respond_to?(:normalized_columns)
|
32
|
-
normalized_columns.is_a?(Array) ?
|
33
|
-
normalized_columns.include?(attr_name.to_sym) :
|
34
|
-
normalized_columns[attr_name]
|
35
|
-
else
|
36
|
-
true
|
37
|
-
end
|
38
|
-
else
|
39
|
-
false
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|