ruby-rails-extensions 2.1.0.pre.rc.8 → 2.1.0.pre.rc.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4924afbe4a7a485556e5b773fadd2f3119168faf0af0fd7963e6d30dcd38fb49
4
- data.tar.gz: 0a3c69358e4895b12e65034e47d06fbbe417b8877014b256c55c2a9bbcc84eda
3
+ metadata.gz: 5b3a4f70a6e3a5dee5a465b1d7e53dc163118c71f8da1b67ef3a9086f7b1ec55
4
+ data.tar.gz: 39feabe026daa75b4e8fd5a3197eae29c18b8c28deacafc845b9f2b26bf8adb0
5
5
  SHA512:
6
- metadata.gz: b6df635f383c654e4966942bc01a0200e80a1e7f49013a60afa1ebb5a7132a2e73e80d540a64baaaf85b91b57d61191027244851c895c5027f857f8774d2fe20
7
- data.tar.gz: 3973b6bbb600e313b21f3963f848639152b342e4174340bccfac418f26a011fa2107f4d1d4a1c84edad5892e7d184a977badb47fbd17a3f44fa8e7722c107cc3
6
+ metadata.gz: c295fea115ef77cebfbd42b3fb1f36631ee040ca9a697630be671e17737dc31b4d4335186ba66defbdca3d795b27f59429cd58c18dea462be1a32600b1ea4bb7
7
+ data.tar.gz: 721b32f34431371b2cad8dd3264b73808262a3447f74d8542bb22c261d638da3ea50f75380bf20a997e0573726227774ef8aa6f213d9c09c7650009dfa8c09d6
data/CHANGELOG.md CHANGED
@@ -10,6 +10,7 @@ Unreleased Changes
10
10
  * `Hash#invert_with_dups`
11
11
  * `FalseClass#to_d` and `TrueClass#to_d`
12
12
  * `Range#>`, `Range#<`, `Range#<=`, `Range#>=`
13
+ * `Range#round`
13
14
 
14
15
  2.0.1 (2024-07-29)
15
16
  ------------------
@@ -12,7 +12,7 @@ Hash.class_eval do
12
12
  if block_given?
13
13
  yield(key, this_val, other_val)
14
14
  else
15
- other_val.presence || this_val
15
+ RubyRailsExtensions.presence(other_val) || this_val
16
16
  end
17
17
  end
18
18
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ Range.class_eval do
4
+ # Rounds a range. Rounds the beginning and ending values only
5
+ # and creates a new range with the rounded values.
6
+ #
7
+ # @param precision [Integer]
8
+ #
9
+ # @return [Range]
10
+ #
11
+ def round(precision = 0)
12
+ Range.new(self.begin.round(precision), self.end.round(precision), exclude_end?)
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyRailsExtensions
4
- VERSION = '2.1.0-rc.8'
4
+ VERSION = '2.1.0-rc.10'
5
5
  end
@@ -45,6 +45,7 @@ module RubyRailsExtensions
45
45
  range_add
46
46
  range_comparisons
47
47
  range_multiply
48
+ range_round
48
49
  remove_reserved_keywords
49
50
  safe_parse
50
51
  select_present
@@ -111,13 +112,15 @@ module RubyRailsExtensions
111
112
  end
112
113
  end
113
114
 
115
+ module_function
116
+
114
117
  # @return [Configuration]
115
- def self.configuration
118
+ def configuration
116
119
  @configuration ||= Configuration.new
117
120
  end
118
121
 
119
122
  # @yield [Configuration]
120
- def self.configure
123
+ def configure
121
124
  yield(configuration)
122
125
 
123
126
  Configuration::BOOLEAN_GEMS.each do |extension|
@@ -132,5 +135,28 @@ module RubyRailsExtensions
132
135
  configuration.flags
133
136
  end
134
137
 
135
- module_function :configuration_flags
138
+ # @see Object#presence from active_support/core_ext/object/blank.rb
139
+ def presence(item)
140
+ return item if present?(item)
141
+
142
+ nil
143
+ end
144
+
145
+ # @see Object#blank? from active_support/core_ext/object/blank.rb
146
+ def blank?(item)
147
+ if item.respond_to?(:blank?)
148
+ return item.blank?
149
+ end
150
+
151
+ item.respond_to?(:empty?) ? !!item.empty? : !item
152
+ end
153
+
154
+ # @see Object#present? from active_support/core_ext/object/blank.rb
155
+ def present?(item)
156
+ if item.respond_to?(:present?)
157
+ return item.present?
158
+ end
159
+
160
+ !blank?(item)
161
+ end
136
162
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-rails-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.pre.rc.8
4
+ version: 2.1.0.pre.rc.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brands Insurance
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-02 00:00:00.000000000 Z
11
+ date: 2024-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -93,6 +93,7 @@ files:
93
93
  - lib/ruby-rails-extensions/extensions/range_add.rb
94
94
  - lib/ruby-rails-extensions/extensions/range_comparisons.rb
95
95
  - lib/ruby-rails-extensions/extensions/range_multiply.rb
96
+ - lib/ruby-rails-extensions/extensions/range_round.rb
96
97
  - lib/ruby-rails-extensions/extensions/remove_reserved_keywords.rb
97
98
  - lib/ruby-rails-extensions/extensions/safe_parse.rb
98
99
  - lib/ruby-rails-extensions/extensions/select_present.rb