active_module 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 743570de05b5e510d10408fe3b95eaab2789e4432311538bda978bf52d893355
4
- data.tar.gz: 72057e516212b80260b45fe9b2bd5c97530fc5f6ceaab42c0578d48581bf3b50
3
+ metadata.gz: fb059e4cacb00c0531503dbc9994110e4c735ba4e70dd926571998381f8977d4
4
+ data.tar.gz: 9182e410141940ad1beccbbb9556cca0fe0b801eaa6f9bb2b461005f59b75f12
5
5
  SHA512:
6
- metadata.gz: 7c4ee2bc7ae24fb246f9744f161088222af6c02d85c99d62e39f196257b90d24abcea21de0217ea578d8755acfd61bf4d078d9f7290f3cc0cc28110bca893cd9
7
- data.tar.gz: '02582a7cbe08a616e35828e0537bacf41714cd4cfae0d5272188fb9feb8aa970c44670391b1cef6926781ebe53f28ce966a0eeda46d32e2149be22370cf19daf'
6
+ metadata.gz: 5b11253775eb6a2ddb1d20664784a62f9528ab0213d1670a9c8d31187719106fe27d0eb926f71bd4233da08e817820a52a7dbe74521c58b4b0b6f3d0a3ee19c8
7
+ data.tar.gz: 9ddad0a60a5afb1dc3e5b923bac3fb8800aa9af022e2312fbc44928e55a0b5eb5fd0c3b5941ed15d8965f747769fdc9aa280c8446085611131722c2360b2be5c
@@ -7,24 +7,20 @@ module ActiveModule
7
7
  class Base < ActiveModel::Type::Value
8
8
  attr_reader :possible_modules, :mapping
9
9
 
10
- def initialize(possible_modules_or_mapping = nil,
10
+ def initialize(possible_modules_or_mapping = [],
11
11
  possible_modules: [],
12
12
  mapping: {})
13
- @possible_modules =
14
- if possible_modules_or_mapping.is_a?(Array)
15
- possible_modules_or_mapping + possible_modules
16
- else
17
- possible_modules
18
- end
19
- mapping_arg = if possible_modules_or_mapping.is_a?(Hash)
20
- possible_modules_or_mapping.merge(mapping)
21
- else
22
- mapping
23
- end
24
- @mapping =
25
- @possible_modules.each_with_object(mapping_arg.dup) do |mod, result|
26
- result[mod] ||= mod.name
27
- end
13
+ if possible_modules_or_mapping.is_a?(Array)
14
+ @possible_modules =
15
+ (possible_modules_or_mapping + possible_modules + mapping.keys).uniq
16
+ @mapping = default_mapping.merge(mapping)
17
+ else
18
+ @possible_modules =
19
+ (possible_modules_or_mapping.keys + possible_modules + mapping.keys)
20
+ .uniq
21
+ @mapping = default_mapping.merge(possible_modules_or_mapping)
22
+ .merge(mapping)
23
+ end
28
24
  super()
29
25
  end
30
26
 
@@ -104,5 +100,9 @@ module ActiveModule
104
100
  def from_db
105
101
  @from_db ||= mapping.invert
106
102
  end
103
+
104
+ def default_mapping
105
+ @possible_modules.index_by(&:name).invert
106
+ end
107
107
  end
108
108
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveModule
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_module
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Rolo