active_record_to_hash 0.6.1 → 1.2.0

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
  SHA256:
3
- metadata.gz: c9c9d98bbc5b3ed0685b3035223f5341bc53dfb34801cf29a8cb230a25da64a2
4
- data.tar.gz: f6c3418611ee57c74110e7476edddff951a79c7b907e989c345fa5914b7671b7
3
+ metadata.gz: 20265c61f8ff4e0694c84ab3ffaf7b7e18682a3691b96f2d2c308b9e5be3cd4f
4
+ data.tar.gz: 603bd1960eda432c40686cd7a34ec4ec03c45680f66a6195eb9ab021606832a6
5
5
  SHA512:
6
- metadata.gz: 9f0722328f1402d5d2f553b3a1dc67d38188d2b3e1222a78cd1939da18adff9c5528a07e0b89c3a0db7c5b5f7bbefbb3e62d193e50ed536fa5b5f728c01822ab
7
- data.tar.gz: c19513248e007a10fac4b2e8250d31b0c492e287257191185105cdd466770908c03b576037049a0eeeacdd8ccc8c775f7ad40c75f9710db5206d9358fa9d85e6
6
+ metadata.gz: 1659acaeb6f1eba556b735690b9f5aa1aabb0a4e19b5a71320e59dbf059a8b9c893a81fb8bef698b68e57a77f142843f025323b86cfb25233b27183cf7135f82
7
+ data.tar.gz: 60d3a968325e50cb34979f2abbd57ed6f450332ee58fc24d2c2457a9c43839185ea44dae1612e1eeba0f313025b87ddd5483ee8404188f85d5eeb6ebab9b1e12
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'bundler/setup'
3
5
  rescue LoadError
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecordToHash
2
4
  module ActiveRecord
3
5
  extend ActiveSupport::Concern
@@ -21,6 +23,8 @@ module ActiveRecordToHash
21
23
 
22
24
  ActiveRecordToHash.handle_with_options(options) do |hash_key, attr_name, child_options|
23
25
  child = ActiveRecordToHash.retrieve_child_attribute(self, attr_name, child_options, __callee__)
26
+ next if child_options[:optional] == true && child.blank?
27
+
24
28
  result[hash_key] = ActiveRecordToHash.handle_alter(child, child_options)
25
29
  end
26
30
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecordToHash
2
4
  module_function
3
5
 
@@ -18,7 +20,11 @@ module ActiveRecordToHash
18
20
  end
19
21
 
20
22
  def retrieve_child_attribute(record, attr_name, options, callee) # rubocop:disable Metrics/AbcSize
21
- return options[:value] if options[:value]
23
+ if options[:value]
24
+ return options[:value].call(record) if options[:value].is_a? Proc
25
+
26
+ return options[:value]
27
+ end
22
28
 
23
29
  args = options[:args] || []
24
30
  value = record.public_send(attr_name, *args)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecordToHash
2
- VERSION = '0.6.1'.freeze
4
+ VERSION = '1.2.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecordToHash
2
4
  class Railtie < ::Rails::Railtie
3
5
  config.active_record_to_hash = ActiveSupport::OrderedOptions.new
@@ -8,7 +10,7 @@ module ActiveRecordToHash
8
10
  require 'active_record_to_hash/version'
9
11
  require 'active_record_to_hash/utilities'
10
12
  require 'active_record_to_hash/active_record'
11
- ::ActiveRecord::Base.send(:include, ::ActiveRecordToHash::ActiveRecord)
13
+ ::ActiveRecord::Base.include ::ActiveRecordToHash::ActiveRecord
12
14
  end
13
15
  end
14
16
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # desc "Explaining what the task does"
2
3
  # task :active_record_to_hash do
3
4
  # # Task goes here
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_to_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masamoto Miyata
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-03 00:00:00.000000000 Z
11
+ date: 2022-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '5.0'
20
20
  - - "<="
21
21
  - !ruby/object:Gem::Version
22
- version: '6.1'
22
+ version: 6.1.4.4
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '5.0'
30
30
  - - "<="
31
31
  - !ruby/object:Gem::Version
32
- version: '6.1'
32
+ version: 6.1.4.4
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: database_cleaner
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -128,48 +128,62 @@ dependencies:
128
128
  - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: rspec
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '='
136
+ - !ruby/object:Gem::Version
137
+ version: '3.10'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '='
143
+ - !ruby/object:Gem::Version
144
+ version: '3.10'
131
145
  - !ruby/object:Gem::Dependency
132
146
  name: rspec-rails
133
147
  requirement: !ruby/object:Gem::Requirement
134
148
  requirements:
135
- - - "~>"
149
+ - - ">="
136
150
  - !ruby/object:Gem::Version
137
- version: '3.7'
151
+ version: '0'
138
152
  type: :development
139
153
  prerelease: false
140
154
  version_requirements: !ruby/object:Gem::Requirement
141
155
  requirements:
142
- - - "~>"
156
+ - - ">="
143
157
  - !ruby/object:Gem::Version
144
- version: '3.7'
158
+ version: '0'
145
159
  - !ruby/object:Gem::Dependency
146
160
  name: rubocop
147
161
  requirement: !ruby/object:Gem::Requirement
148
162
  requirements:
149
- - - "~>"
163
+ - - '='
150
164
  - !ruby/object:Gem::Version
151
- version: 0.67.2
165
+ version: 0.75.0
152
166
  type: :development
153
167
  prerelease: false
154
168
  version_requirements: !ruby/object:Gem::Requirement
155
169
  requirements:
156
- - - "~>"
170
+ - - '='
157
171
  - !ruby/object:Gem::Version
158
- version: 0.67.2
172
+ version: 0.75.0
159
173
  - !ruby/object:Gem::Dependency
160
- name: rubocop-performance
174
+ name: rubocop-rails
161
175
  requirement: !ruby/object:Gem::Requirement
162
176
  requirements:
163
- - - "~>"
177
+ - - ">="
164
178
  - !ruby/object:Gem::Version
165
- version: 1.0.0
179
+ version: '0'
166
180
  type: :development
167
181
  prerelease: false
168
182
  version_requirements: !ruby/object:Gem::Requirement
169
183
  requirements:
170
- - - "~>"
184
+ - - ">="
171
185
  - !ruby/object:Gem::Version
172
- version: 1.0.0
186
+ version: '0'
173
187
  - !ruby/object:Gem::Dependency
174
188
  name: sqlite3
175
189
  requirement: !ruby/object:Gem::Requirement
@@ -203,7 +217,7 @@ homepage: https://github.com/gomo/active_record_to_hash
203
217
  licenses:
204
218
  - MIT
205
219
  metadata: {}
206
- post_install_message:
220
+ post_install_message:
207
221
  rdoc_options: []
208
222
  require_paths:
209
223
  - lib
@@ -211,15 +225,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
211
225
  requirements:
212
226
  - - ">="
213
227
  - !ruby/object:Gem::Version
214
- version: '0'
228
+ version: 2.6.0
215
229
  required_rubygems_version: !ruby/object:Gem::Requirement
216
230
  requirements:
217
231
  - - ">="
218
232
  - !ruby/object:Gem::Version
219
233
  version: '0'
220
234
  requirements: []
221
- rubygems_version: 3.0.6
222
- signing_key:
235
+ rubygems_version: 3.2.32
236
+ signing_key:
223
237
  specification_version: 4
224
238
  summary: Add the `to_hash` function to active record.
225
239
  test_files: []