rails_settlement 1.2.0 → 1.3.0

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: 5f6997e50cad74b6bfb65514e1efc59a454db83eca5d903fed3cee4ae35326aa
4
- data.tar.gz: 0f372b19be2e0f3614c9c55b01394d38b6aebb915bf9905857b6cc5c746266a5
3
+ metadata.gz: 8a6695df770d40dfaff82ecab8bc78d0c8094be1c1bb5396a3065627394d3b2a
4
+ data.tar.gz: 816e133bd3c262c8ca33f77b1d2629e11f3980a14a903111b93d22fb1c7d8f66
5
5
  SHA512:
6
- metadata.gz: 8bf231039431dbf2c302aab711be354ef8373cbf9570cf053d32100e3f3660b2399a9067f8be965c2dd553b303f4333a5fe06fe2ebe031ed12e54523bce86b78
7
- data.tar.gz: 881deb50b91a6628596d9767a55ad4e57a15cf6055a8452d1a2275f0bd051b84eba7aa8bf429629e306fdd4b79073112a939abb73460f350c8b1a55262b0df1c
6
+ metadata.gz: 0524dceb140d2e07286d2cac1adfde6d4c24a1b4f10b9103cd0509b0475551e263e14e2deb51c530961f8c5092ff06469723373eb1f391aaaaa862a26bbe311c
7
+ data.tar.gz: 2ffc3f8ddacc5ce63232670febdb4223f968760ce9da686c20553fd6cfc9b75150b7d2c9cbfffafe2cf865f4745b6a238a61c17ea70343d09085943bbca776a4
data/.rubocop.yml CHANGED
@@ -10,7 +10,7 @@ Style/StringLiteralsInInterpolation:
10
10
  EnforcedStyle: double_quotes
11
11
 
12
12
  Layout/LineLength:
13
- Max: 130
13
+ Max: 150
14
14
 
15
15
  Metrics/AbcSize:
16
16
  Max: 22
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsSettlement
4
- VERSION = "1.2.0"
4
+ VERSION = "1.3.0"
5
5
  end
@@ -10,17 +10,17 @@ module RailsSettlement
10
10
 
11
11
  SETTABLE_REGEX = /\Aset_(?<object>[a-z_]+)(?<raisable>!?)\z/.freeze
12
12
 
13
- class_methods do
13
+ class_methods do # rubocop:disable Metrics/BlockLength
14
14
  def method_missing(method, **options)
15
15
  super unless (matches = method.to_s.match(SETTABLE_REGEX))
16
16
 
17
17
  variable, raisable = _handle_match_data(matches)
18
- klass = _klass(variable)
18
+ klass = _klass(variable, **options.extract!(:namespace))
19
19
  param_options = _param_options(klass: klass, options: options)
20
+ scoped_klass = _handle_scopes(klass: klass, scopes: param_options[:scope_to])
20
21
 
21
22
  before_action(**options) do
22
- klass = _handle_scopes(klass, param_options[:scope_to])
23
- instance_variable_set("@#{variable}", klass.find_by(param_options[:model_key] => params[param_options[:params_key]]))
23
+ instance_variable_set("@#{variable}", scoped_klass.find_by(param_options[:model_key] => params[param_options[:params_key]]))
24
24
  raise ActiveRecord::RecordNotFound if raisable && instance_variable_get("@#{variable}").nil?
25
25
  end
26
26
 
@@ -37,22 +37,24 @@ module RailsSettlement
37
37
  [match_data[:object], match_data[:raisable].present?]
38
38
  end
39
39
 
40
- def _klass(variable)
41
- variable.classify.constantize
40
+ def _klass(variable, namespace: nil)
41
+ variable = variable.classify
42
+ variable = "#{namespace.to_s.classify}::#{variable}" if namespace.present?
43
+ variable.constantize
42
44
  end
43
45
 
44
46
  def _param_options(klass:, options:)
45
47
  (klass.try(:settable_params) || {}).merge(options.extract!(:model_key, :params_key, :scope_to))
46
48
  end
47
- end
48
49
 
49
- def _handle_scopes(klass, scopes)
50
- return klass if scopes.blank?
50
+ def _handle_scopes(klass:, scopes:)
51
+ return klass if scopes.blank?
51
52
 
52
- scopes = [scopes] unless scopes.is_a?(Array)
53
- scopes.each { |scope| klass = klass.public_send(scope) }
53
+ scopes = [scopes] unless scopes.is_a?(Array)
54
+ scopes.each { |scope| klass = klass.public_send(scope) }
54
55
 
55
- klass
56
+ klass
57
+ end
56
58
  end
57
59
  end
58
60
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_settlement
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tejas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-11 00:00:00.000000000 Z
11
+ date: 2024-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord