active_module 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -3
- data/lib/active_module/base.rb +16 -16
- data/lib/active_module/register.rb +2 -0
- data/lib/active_module/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e84ab7b0e8dd2d33b4eb6dc9ade177bb57361eb23bd62aa774d5e57fab95b831
|
4
|
+
data.tar.gz: 02d82ee773888a155453d8765044661bffa180fc0aedf5465a034cc5b34ad03e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28f2e81b006c7928e176f8ff91491601fb21ac77223c5096905d703cb54b695ea5e463972d4102f3dd6ca119b2e4df032cfc3531f191d109fd1e6270436d93f9
|
7
|
+
data.tar.gz: e06b59e2b248d106e4928cd9d69a6c665d6022d11bba45c258a708b8e4e1a48d7fb29db934fc57ee32f7aaf65491fa6db9aa552c7ccda578b6a7167339e8c05d
|
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
|
2
|
-
# active_module
|
3
|
-
](https://rubygems.org/gems/active_module)
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
5
|
+
[](https://github.com/pedrorolo/active_module/blob/main/Rakefile)
|
6
|
+
[](https://github.com/pedrorolo/active_module/blob/main/spec/spec_helper.rb)
|
7
|
+
[](https://bestgems.org/gems/active_module)
|
8
|
+
|
9
|
+
|
4
10
|
|
5
11
|
#### *Modules and Classes as first-class active record values!*
|
6
12
|
|
@@ -64,7 +70,7 @@ end
|
|
64
70
|
Add to your gemfile - and if you are using rails - that's all you need:
|
65
71
|
|
66
72
|
```ruby
|
67
|
-
gem 'active_module', "~> 0.
|
73
|
+
gem 'active_module', "~> 0.3"
|
68
74
|
```
|
69
75
|
|
70
76
|
If you are not using rails, just issue this command after loading active record
|
data/lib/active_module/base.rb
CHANGED
@@ -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 =
|
10
|
+
def initialize(possible_modules_or_mapping = [],
|
11
11
|
possible_modules: [],
|
12
12
|
mapping: {})
|
13
|
-
|
14
|
-
|
15
|
-
possible_modules_or_mapping + possible_modules
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_module
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Rolo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activemodel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "<"
|