active_module 0.1.7 → 0.1.8

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: 191f7c2deb3a07261247a4302436cc734541ab62c3db9dd742974d58320dd763
4
- data.tar.gz: bd20cb4d1aa7b6437facfaefc8213485571497df5e9e607ce19d16b81db246b8
3
+ metadata.gz: b80aaae788c312746df8dcaba68bfda8f881fc2c22d7642b509546bdab198bc0
4
+ data.tar.gz: 84674ab108e9b639327f7531f678a12b8dbf31ab25c01088f8839458b71d1cac
5
5
  SHA512:
6
- metadata.gz: bc48c3f11e8f71321ab4abece1b5d58f671c96de7e494a5f2f7a8e55b9946c6e88af9e61970bdd2332eba12ee74dadec13485555dff0f05a4f74209c1327fd96
7
- data.tar.gz: 126c9c4a2d885cadbe472dc23caa5025415f2806411e9eecce37a5b40c28ce990c5956246646292e9780b6f30d6f77705ab681899a7532940dbe0cfe59f2a471
6
+ metadata.gz: a89843336735a230e13691069fd3a2e919403a140712476bb5176862fd0bb72df6ff069fa9d3ca9635c2dadc1a602863122a2ec384f8414754a560da02561698
7
+ data.tar.gz: f7b03c281aafba2a1bf187f7ed9b049c9dd3798bafdf411c3710964e2cbc087dedd72937c897925bdcbb9f4887e625f5d893b69640df853f738324b12b955e7d
data/README.md CHANGED
@@ -1,19 +1,21 @@
1
- # ActiveModule
2
1
 
3
- *"Let's turn modules and classes into first-class active record values!"*
2
+ # active_module
3
+ ![alt text](https://img.shields.io/badge/coverage-100%25-brightgreen)
4
+
5
+ #### *Modules and Classes as first-class active record values!*
4
6
 
5
7
  ActiveModel/ActiveRecord implementation of the Module attribute type.
6
8
 
7
- - Allows storing a reference to a `Module` or `Class` (because they are modules) in a `:string`
8
- database field in a safe and efficient way.
9
- - It automatically casts strings and symbols into modules when creating and querying objects.
10
- - Symbols or strings refer to the modules using unqualified names.
9
+ - Allows storing a reference to a `Module` or `Class` in a `:string` database field
10
+ - Automatically casts strings and symbols into modules when creating and querying objects
11
+ - Symbols or strings refer to the modules using unqualified names
12
+ - It is safe and efficient
11
13
 
12
14
  This is a very generic mechanism that enables many possible utilizations, for instance:
13
- - Strategy Pattern (composition-based polymorphism)
14
- - Rapid prototyping static domain objects
15
- - Static configuration management
16
- - Rich Java/C#-like enums
15
+ - **Composition-based polymorphism (Strategy design pattern)**
16
+ - **Rapid prototyping static domain objects**
17
+ - **Static configuration management**
18
+ - **Rich Java/C#-like enums**
17
19
 
18
20
  You can find examples of these in [Usage -> Examples :](#Examples)
19
21
 
@@ -36,8 +38,19 @@ object.module_field = "Module"
36
38
  object.module_field #=> Nested::Module:Module
37
39
  ```
38
40
 
39
- And compare them like this (optional):
41
+ Query them like this:
40
42
  ```ruby
43
+ MyARObject.where(module_field: Nested::Module)
44
+ MyARObject.where(module_field: :Module)
45
+ MyARObject.where(module_field: "Module")
46
+ object.module_field #=> Nested::Module:Module
47
+ ```
48
+
49
+ And compare them like this:
50
+
51
+ ```ruby
52
+ object.module_field == Nested::Module
53
+
41
54
  module MyNameSpace
42
55
  using ActiveModule::Comparison
43
56
 
@@ -51,7 +64,7 @@ end
51
64
  Add to your gemfile - and if you are using rails - that's all you need:
52
65
 
53
66
  ```ruby
54
- gem 'active_module', "~>0.1"
67
+ gem 'active_module', "~> 0.1"
55
68
  ```
56
69
 
57
70
  If you are not using rails, just issue this command after loading active record
@@ -77,7 +90,7 @@ create_table :my_ar_objects do |t|
77
90
  end
78
91
  ```
79
92
 
80
- Now given this module structure:
93
+ Now given this random module hierarchy:
81
94
  ```ruby
82
95
  class MyARObject < ActiveRecord::Base
83
96
  module MyModule1; end
@@ -169,23 +182,28 @@ my_ar_object.module_field == MyClass::MyModule1
169
182
 
170
183
  ## Examples
171
184
 
172
- ### Strategy Pattern (composition-based polymorphism)
185
+ ### Composition-based polymorphism (Strategy design pattern)
173
186
 
174
187
  [The Strategy design pattern](https://en.wikipedia.org/wiki/Strategy_pattern) allows composition based polymorphism. This enables runtime polymorphism (by changing the strategy in runtime),
175
188
  and multiple-polymorphism (by composing an object of multiple strategies).
176
189
 
177
- If you want to use classes this will do:
190
+ If you want to use classes this will do:
178
191
  ```ruby
179
192
  class MyARObject < ActiveRecord::Base
180
- attribute :strategy, :active_module, possible_modules: StrategySuperclass.subclasses
193
+ attribute :strategy_class, :active_module, possible_modules: StrategySuperclass.subclasses
194
+
195
+ def strategy
196
+ @strategy ||= strategy_class.new(some_args_from_the_instance)
197
+ end
181
198
 
182
199
  def run_strategy!(args)
183
- strategy.new(some_args).call(other_args)
200
+ strategy.call(args)
184
201
  end
185
202
  end
186
203
  ```
187
204
 
188
- But if you are not in the mood to define a class hierarchy for it, you can use modules instead:
205
+ But if you are not in the mood to define a class hierarchy for it (or if you are performance-savy),
206
+ you may use modules instead:
189
207
 
190
208
  ```ruby
191
209
  class MyARObject < ActiveRecord::Base
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveModule
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.8"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_module
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
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-18 00:00:00.000000000 Z
11
+ date: 2024-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '9'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: '7'
22
+ version: '7.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '9'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '7'
32
+ version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -44,7 +44,7 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: 1.15.0
47
- description: Let's turn modules and classes into first-class active record values!
47
+ description: ActiveModel/ActiveRecord module attribute type implementation
48
48
  email:
49
49
  - pedrorolo@gmail.com
50
50
  executables: []
@@ -89,5 +89,5 @@ requirements: []
89
89
  rubygems_version: 3.5.7
90
90
  signing_key:
91
91
  specification_version: 4
92
- summary: ActiveModel/ActiveRecord module attribute type implementation
92
+ summary: Modules and Classes as first-class active record values
93
93
  test_files: []