ruby-rails-extensions 2.4.0 → 3.0.0.rc.pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/ruby-rails-extensions/extensions/all_keys.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/all_values.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/any_key.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/any_value.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/compact_blank_join.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/compact_map.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/current_day.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/current_month.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/current_week.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/cutoff.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/day_of_week.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/display_military.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/display_user.rb +4 -4
- data/lib/ruby-rails-extensions/extensions/find_bang.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/find_dupes.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/first_dupe.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/flatten_compact.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/google_format.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/hash_only.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/humanize_symbol.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/in_utc.rb +3 -3
- data/lib/ruby-rails-extensions/extensions/input.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/invert_with_dups.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/left_deep_merge.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/month_and_year.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/month_year.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/nmerge.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/no_keys.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/no_values.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/only_some.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/overlaps.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/pipe.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/presence_bang.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/quarter_dates.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/quarter_str.rb +6 -4
- data/lib/ruby-rails-extensions/extensions/range_add.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/range_comparisons.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/range_multiply.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/range_round.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/remove_reserved_keywords.rb +21 -19
- data/lib/ruby-rails-extensions/extensions/safe_parse.rb +2 -15
- data/lib/ruby-rails-extensions/extensions/select_present.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/select_present_join.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/set_to_sentence.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/to_bool.rb +5 -5
- data/lib/ruby-rails-extensions/extensions/to_d.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/to_dec.rb +3 -3
- data/lib/ruby-rails-extensions/extensions/to_delimited.rb +4 -4
- data/lib/ruby-rails-extensions/extensions/to_i.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/to_local.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/to_money.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/to_negative_i.rb +3 -3
- data/lib/ruby-rails-extensions/extensions/to_new_date.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/to_new_time.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/to_nonzero_i.rb +3 -3
- data/lib/ruby-rails-extensions/extensions/to_or_sentence.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/to_percentage.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/to_positive_i.rb +3 -3
- data/lib/ruby-rails-extensions/extensions/to_sort_i.rb +3 -3
- data/lib/ruby-rails-extensions/extensions/to_x.rb +3 -3
- data/lib/ruby-rails-extensions/extensions/todays_date.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/uniq_map.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/usd_to_f.rb +3 -3
- data/lib/ruby-rails-extensions/extensions/usd_to_i.rb +2 -2
- data/lib/ruby-rails-extensions/extensions/utf8_encode.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/weighted_sum.rb +1 -1
- data/lib/ruby-rails-extensions/extensions/yesno.rb +3 -3
- data/lib/ruby-rails-extensions/extensions/zero_range.rb +1 -1
- data/lib/ruby-rails-extensions/version.rb +3 -3
- data/lib/ruby-rails-extensions.rb +0 -2
- metadata +2 -4
- data/lib/ruby-rails-extensions/extensions/assign_nil.rb +0 -70
- data/lib/ruby-rails-extensions/extensions/clean_string.rb +0 -61
|
@@ -2,35 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
require 'forwardable'
|
|
4
4
|
|
|
5
|
-
TrueClass
|
|
5
|
+
class TrueClass
|
|
6
6
|
# :nodoc:
|
|
7
7
|
def to_bool
|
|
8
8
|
true
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
FalseClass
|
|
12
|
+
class FalseClass
|
|
13
13
|
# :nodoc:
|
|
14
14
|
def to_bool
|
|
15
15
|
false
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
NilClass
|
|
19
|
+
class NilClass
|
|
20
20
|
# :nodoc:
|
|
21
21
|
def to_bool
|
|
22
22
|
false
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
String
|
|
26
|
+
class String
|
|
27
27
|
# :nodoc:
|
|
28
28
|
def to_bool
|
|
29
29
|
match?(/^(true|1|t|y|yes)$/i)
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
Numeric
|
|
33
|
+
class Numeric
|
|
34
34
|
extend Forwardable
|
|
35
35
|
|
|
36
36
|
def_delegators :to_s, :to_bool
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
require 'bigdecimal'
|
|
4
4
|
|
|
5
|
-
FalseClass
|
|
5
|
+
class FalseClass
|
|
6
6
|
# @return [BigDecimal]
|
|
7
7
|
def to_d
|
|
8
8
|
BigDecimal('0')
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
TrueClass
|
|
12
|
+
class TrueClass
|
|
13
13
|
# @return [BigDecimal]
|
|
14
14
|
def to_d
|
|
15
15
|
BigDecimal('1')
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
NilClass
|
|
3
|
+
class NilClass
|
|
4
4
|
# :nodoc:
|
|
5
5
|
def to_dec(*_args)
|
|
6
6
|
nil
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
Numeric
|
|
10
|
+
class Numeric
|
|
11
11
|
# :nodoc:
|
|
12
12
|
def to_dec(p = 4)
|
|
13
13
|
(to_f / 100.0).round(p)
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
String
|
|
17
|
+
class String
|
|
18
18
|
# :nodoc:
|
|
19
19
|
def to_dec(p = 4)
|
|
20
20
|
(to_f / 100.0).round(p)
|
|
@@ -6,7 +6,7 @@ require 'active_support/number_helper'
|
|
|
6
6
|
require 'bigdecimal'
|
|
7
7
|
require 'forwardable'
|
|
8
8
|
|
|
9
|
-
String
|
|
9
|
+
class String
|
|
10
10
|
include ActiveSupport::NumberHelper
|
|
11
11
|
|
|
12
12
|
# Converts a number to a delimited number string
|
|
@@ -21,15 +21,15 @@ String.class_eval do
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
# Adding this alias to follow {ActionView::Helpers::NumberHelper#number_with_delimiter}
|
|
24
|
-
|
|
24
|
+
alias with_delimiter to_delimited
|
|
25
25
|
|
|
26
26
|
# @deprecated This alias is only for Atlas and will be removed in future versions
|
|
27
|
-
|
|
27
|
+
alias with_sep to_delimited
|
|
28
28
|
|
|
29
29
|
deprecate :with_sep, deprecator: ActiveSupport::Deprecation.new('3.0', 'ruby-rails-extensions')
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
Numeric
|
|
32
|
+
class Numeric
|
|
33
33
|
extend Forwardable
|
|
34
34
|
|
|
35
35
|
def_delegators :to_s, :to_delimited, :with_delimiter, :with_sep
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
if defined?(ActiveSupport::TimeWithZone)
|
|
5
5
|
require 'forwardable'
|
|
6
6
|
|
|
7
|
-
Time
|
|
7
|
+
class Time
|
|
8
8
|
extend Forwardable
|
|
9
9
|
|
|
10
10
|
def_delegators :to_datetime, :to_local
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
DateTime
|
|
13
|
+
class DateTime
|
|
14
14
|
# Converts to an Eastern time zone
|
|
15
15
|
#
|
|
16
16
|
# @return [DateTime]
|
|
@@ -4,7 +4,7 @@ require 'active_support'
|
|
|
4
4
|
require 'active_support/number_helper'
|
|
5
5
|
require 'bigdecimal'
|
|
6
6
|
|
|
7
|
-
Numeric
|
|
7
|
+
class Numeric
|
|
8
8
|
include ActiveSupport::NumberHelper
|
|
9
9
|
|
|
10
10
|
# Converts a number to a money string
|
|
@@ -19,7 +19,7 @@ Numeric.class_eval do
|
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
String
|
|
22
|
+
class String
|
|
23
23
|
# @see Numeric#to_money
|
|
24
24
|
def to_money(...)
|
|
25
25
|
to_d.to_money(...)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
String
|
|
3
|
+
class String
|
|
4
4
|
# Calls `to_i` and returns the value if it is negative
|
|
5
5
|
#
|
|
6
6
|
# @return [Integer, Nil]
|
|
@@ -14,7 +14,7 @@ String.class_eval do
|
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
Numeric
|
|
17
|
+
class Numeric
|
|
18
18
|
# Calls `to_i` and returns the value if it is negative
|
|
19
19
|
#
|
|
20
20
|
# @return [Integer, Nil]
|
|
@@ -28,7 +28,7 @@ Numeric.class_eval do
|
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
NilClass
|
|
31
|
+
class NilClass
|
|
32
32
|
# Calls `to_i` and returns the value if it is negative
|
|
33
33
|
#
|
|
34
34
|
# @return [Nil]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
String
|
|
3
|
+
class String
|
|
4
4
|
# Calls `to_i` and returns the value if it is nonzero
|
|
5
5
|
#
|
|
6
6
|
# @return [Integer, Nil]
|
|
@@ -14,7 +14,7 @@ String.class_eval do
|
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
Numeric
|
|
17
|
+
class Numeric
|
|
18
18
|
# Calls `to_i` and returns the value if it is nonzero
|
|
19
19
|
#
|
|
20
20
|
# @return [Integer, Nil]
|
|
@@ -28,7 +28,7 @@ Numeric.class_eval do
|
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
NilClass
|
|
31
|
+
class NilClass
|
|
32
32
|
# Calls `to_i` and returns the value if it is nonzero
|
|
33
33
|
#
|
|
34
34
|
# @return [Integer, Nil]
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
require 'forwardable'
|
|
4
4
|
require 'set'
|
|
5
5
|
|
|
6
|
-
Array
|
|
6
|
+
class Array
|
|
7
7
|
# @return [String]
|
|
8
8
|
def to_or_sentence
|
|
9
9
|
to_sentence(two_words_connector: ' or ', last_word_connector: ', or ')
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
Set
|
|
13
|
+
class Set
|
|
14
14
|
extend Forwardable
|
|
15
15
|
|
|
16
16
|
def_delegators :to_a, :to_or_sentence
|
|
@@ -4,7 +4,7 @@ require 'active_support'
|
|
|
4
4
|
require 'active_support/number_helper'
|
|
5
5
|
require 'bigdecimal'
|
|
6
6
|
|
|
7
|
-
Numeric
|
|
7
|
+
class Numeric
|
|
8
8
|
# Converts an {#Integer}, {#Float}, or {#BigDecimal} into a percentage string.
|
|
9
9
|
# @see ActiveSupport::NumberHelper#number_to_percentage
|
|
10
10
|
#
|
|
@@ -20,5 +20,5 @@ Numeric.class_eval do
|
|
|
20
20
|
"#{(to_f * 100).round(options.fetch(:precision, 2))}%"
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
alias to_per to_percentage
|
|
24
24
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
String
|
|
3
|
+
class String
|
|
4
4
|
# Calls `to_i` and returns the value if it is positive
|
|
5
5
|
#
|
|
6
6
|
# @return [Integer, Nil]
|
|
@@ -14,7 +14,7 @@ String.class_eval do
|
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
Numeric
|
|
17
|
+
class Numeric
|
|
18
18
|
# Calls `to_i` and returns the value if it is positive
|
|
19
19
|
#
|
|
20
20
|
# @return [Integer, Nil]
|
|
@@ -28,7 +28,7 @@ Numeric.class_eval do
|
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
NilClass
|
|
31
|
+
class NilClass
|
|
32
32
|
# Calls `to_i` and returns the value if it is positive
|
|
33
33
|
#
|
|
34
34
|
# @return [Integer, Nil]
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
TrueClass
|
|
3
|
+
class TrueClass
|
|
4
4
|
# @see `to_i`
|
|
5
5
|
def to_sort_i
|
|
6
6
|
to_i
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
FalseClass
|
|
10
|
+
class FalseClass
|
|
11
11
|
# @see `to_i`
|
|
12
12
|
def to_sort_i
|
|
13
13
|
to_i
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
NilClass
|
|
17
|
+
class NilClass
|
|
18
18
|
# :nodoc:
|
|
19
19
|
def to_sort_i
|
|
20
20
|
-1
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
TrueClass
|
|
3
|
+
class TrueClass
|
|
4
4
|
# :nodoc:
|
|
5
5
|
def to_x(*_args)
|
|
6
6
|
'X'
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
FalseClass
|
|
10
|
+
class FalseClass
|
|
11
11
|
# :nodoc:
|
|
12
12
|
def to_x(unless_true = '')
|
|
13
13
|
unless_true
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
NilClass
|
|
17
|
+
class NilClass
|
|
18
18
|
# :nodoc:
|
|
19
19
|
def to_x(unless_true = nil)
|
|
20
20
|
unless_true
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
NilClass
|
|
3
|
+
class NilClass
|
|
4
4
|
# :nodoc:
|
|
5
5
|
def usd_to_f
|
|
6
6
|
nil
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
Numeric
|
|
10
|
+
class Numeric
|
|
11
11
|
# :nodoc:
|
|
12
12
|
def usd_to_f
|
|
13
13
|
to_f
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
String
|
|
17
|
+
class String
|
|
18
18
|
# :nodoc:
|
|
19
19
|
def usd_to_f
|
|
20
20
|
gsub(/[$,]/, '').to_f
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
TrueClass
|
|
3
|
+
class TrueClass
|
|
4
4
|
# :nodoc:
|
|
5
5
|
def yesno
|
|
6
6
|
'Yes'
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
FalseClass
|
|
10
|
+
class FalseClass
|
|
11
11
|
# :nodoc:
|
|
12
12
|
def yesno
|
|
13
13
|
'No'
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
NilClass
|
|
17
|
+
class NilClass
|
|
18
18
|
# :nodoc:
|
|
19
19
|
def yesno
|
|
20
20
|
'N/A'
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module RubyRailsExtensions
|
|
4
4
|
module VERSION
|
|
5
|
-
MAJOR =
|
|
6
|
-
MINOR =
|
|
5
|
+
MAJOR = 3
|
|
6
|
+
MINOR = 0
|
|
7
7
|
TINY = 0
|
|
8
8
|
|
|
9
9
|
# Set PRE to nil unless it's a pre-release (beta, rc, etc.)
|
|
10
|
-
PRE =
|
|
10
|
+
PRE = 'rc.pre.1'
|
|
11
11
|
|
|
12
12
|
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.').freeze
|
|
13
13
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-rails-extensions
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0.rc.pre.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brands Insurance
|
|
@@ -25,9 +25,7 @@ files:
|
|
|
25
25
|
- lib/ruby-rails-extensions/extensions/all_values.rb
|
|
26
26
|
- lib/ruby-rails-extensions/extensions/any_key.rb
|
|
27
27
|
- lib/ruby-rails-extensions/extensions/any_value.rb
|
|
28
|
-
- lib/ruby-rails-extensions/extensions/assign_nil.rb
|
|
29
28
|
- lib/ruby-rails-extensions/extensions/boolean_scope.rb
|
|
30
|
-
- lib/ruby-rails-extensions/extensions/clean_string.rb
|
|
31
29
|
- lib/ruby-rails-extensions/extensions/compact_blank_join.rb
|
|
32
30
|
- lib/ruby-rails-extensions/extensions/compact_map.rb
|
|
33
31
|
- lib/ruby-rails-extensions/extensions/current_day.rb
|
|
@@ -109,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
109
107
|
requirements:
|
|
110
108
|
- - ">="
|
|
111
109
|
- !ruby/object:Gem::Version
|
|
112
|
-
version: 3.0
|
|
110
|
+
version: 3.3.0
|
|
113
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
112
|
requirements:
|
|
115
113
|
- - ">="
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'active_support/deprecation'
|
|
4
|
-
|
|
5
|
-
# requires `ActiveModel::AttributeAssignment` and `Hash#stringify_keys`
|
|
6
|
-
module ActiveModel
|
|
7
|
-
module AttributeAssignment
|
|
8
|
-
# @deprecated Will be removed in ruby-rails-extensions 3.0
|
|
9
|
-
#
|
|
10
|
-
# Allows you to set nil attributes by passing in a hash of attributes with
|
|
11
|
-
# keys matching the attribute names.
|
|
12
|
-
#
|
|
13
|
-
# @raise [ActiveModel::ForbiddenAttributesError] If the passed hash responds to `permitted?` method
|
|
14
|
-
# and the return value of this method is +false+.
|
|
15
|
-
#
|
|
16
|
-
# @example
|
|
17
|
-
#
|
|
18
|
-
# class Cat
|
|
19
|
-
# include ActiveModel::AttributeAssignment
|
|
20
|
-
# attr_accessor :name, :status
|
|
21
|
-
# end
|
|
22
|
-
#
|
|
23
|
-
# cat = Cat.new
|
|
24
|
-
# cat.assign_nil_attributes(name: "Gorby")
|
|
25
|
-
# cat.name # => 'Gorby'
|
|
26
|
-
# cat.status # => nil
|
|
27
|
-
# cat.assign_nil_attributes(status: "yawning")
|
|
28
|
-
# cat.name # => 'Gorby'
|
|
29
|
-
# cat.status # => 'yawning'
|
|
30
|
-
# cat.assign_nil_attributes(status: "sleeping")
|
|
31
|
-
# cat.name # => 'Gorby'
|
|
32
|
-
# cat.status # => 'yawning'
|
|
33
|
-
#
|
|
34
|
-
# @param new_attributes
|
|
35
|
-
#
|
|
36
|
-
# @return [void]
|
|
37
|
-
#
|
|
38
|
-
def assign_nil_attributes(new_attributes)
|
|
39
|
-
ActiveSupport::Deprecation
|
|
40
|
-
.new('3.0', 'ruby-rails-extensions')
|
|
41
|
-
.warn('assign_nil_attributes is deprecated and will be removed from ruby-rails-extensions 3.0')
|
|
42
|
-
|
|
43
|
-
unless new_attributes.respond_to?(:stringify_keys)
|
|
44
|
-
raise(ArgumentError, 'When assigning attributes, you must pass a hash as an argument.')
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
return if new_attributes.empty?
|
|
48
|
-
|
|
49
|
-
attributes = new_attributes.stringify_keys
|
|
50
|
-
|
|
51
|
-
_assign_nil_attributes(sanitize_for_mass_assignment(attributes))
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
private
|
|
55
|
-
|
|
56
|
-
# Assign any `nil` attribute
|
|
57
|
-
#
|
|
58
|
-
# @param attributes [Hash]
|
|
59
|
-
#
|
|
60
|
-
# @return [void]
|
|
61
|
-
#
|
|
62
|
-
def _assign_nil_attributes(attributes)
|
|
63
|
-
attributes.each do |k, v|
|
|
64
|
-
next unless v.nil?
|
|
65
|
-
|
|
66
|
-
_assign_attribute(k, v)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
String.class_eval do
|
|
4
|
-
# @deprecated Use {String#utf8_encode!} instead
|
|
5
|
-
# Remove all non-UTF-8 chars from a string.
|
|
6
|
-
#
|
|
7
|
-
# @param replace_with [String, nil] What to replace invalid chars with.
|
|
8
|
-
#
|
|
9
|
-
# @return [String]
|
|
10
|
-
#
|
|
11
|
-
def clean!(replace_with = '')
|
|
12
|
-
utf8_encode_dep_warn('clean!')
|
|
13
|
-
|
|
14
|
-
replace(encode('UTF-8', invalid: :replace, undef: :replace, replace: replace_with))
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# @deprecated Use {String#utf8_encode} instead
|
|
18
|
-
# @see {#clean!}
|
|
19
|
-
def clean(replace_with = '')
|
|
20
|
-
utf8_encode_dep_warn('clean')
|
|
21
|
-
|
|
22
|
-
dup.clean!(replace_with)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# @deprecated Use {String#utf8_encode!} instead
|
|
26
|
-
# Remove all non-UTF-8 chars from a string and convert to binary.
|
|
27
|
-
#
|
|
28
|
-
# @param replace_with [String, nil] What to replace invalid chars with.
|
|
29
|
-
#
|
|
30
|
-
# @return [String]
|
|
31
|
-
#
|
|
32
|
-
def clean_binary!(replace_with = '')
|
|
33
|
-
utf8_encode_dep_warn('clean_binary!')
|
|
34
|
-
|
|
35
|
-
replace(encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: replace_with))
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# @deprecated Use {String#utf8_encode} instead
|
|
39
|
-
# @see {#clean_binary!}
|
|
40
|
-
def clean_binary(replace_with = '')
|
|
41
|
-
utf8_encode_dep_warn('clean_binary!')
|
|
42
|
-
|
|
43
|
-
dup.clean_binary!(replace_with)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
private
|
|
47
|
-
|
|
48
|
-
# Triggers a deprecation warning
|
|
49
|
-
#
|
|
50
|
-
# @param method_name [String]
|
|
51
|
-
# @param projected_version [String] Projected version methods will
|
|
52
|
-
# be removed / no longer supported.
|
|
53
|
-
#
|
|
54
|
-
# @return [void]
|
|
55
|
-
#
|
|
56
|
-
def utf8_encode_dep_warn(method_name, projected_version = '3.0')
|
|
57
|
-
dep = ActiveSupport::Deprecation.new(projected_version, 'ruby-rails-extensions')
|
|
58
|
-
|
|
59
|
-
dep.warn("#{method_name} is deprecated and will be removed from ruby-rails-extensions #{projected_version}")
|
|
60
|
-
end
|
|
61
|
-
end
|