active_module 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/active_module/comparison.rb +30 -0
- data/lib/active_module/version.rb +1 -1
- data/lib/active_module.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31dff5b0baa89fa4624fc7b974f5261d483cdaf48f7b7fe9a5d1f0a7f256d7fa
|
4
|
+
data.tar.gz: fbb6655e9de6c118ee99e199ed4ce78441cd55d151d839f7bf0040fa48519df5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ed009054605141713db46f3d768dc044f42d5bc8ac479ae8004408eaa9ad4657694d661299ba600868975bf7f254da00315d64564d1dfcd96a942ad6622dada
|
7
|
+
data.tar.gz: 4053a0f71c9b2b8db76c1f7637a989646c7b8ad531fa5da680c9795e61ec967fe9db13c74b566350039c13cdaf16d1a0c80f58e04944650e5e2c2f78d73a017f
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ You can find examples of these in [Usage -> Examples :](#Examples)
|
|
19
19
|
|
20
20
|
## Installation
|
21
21
|
|
22
|
-
Add to your gemfile:
|
22
|
+
Add to your gemfile - and if you are using rails - that's all you need:
|
23
23
|
|
24
24
|
```ruby
|
25
25
|
gem 'active_module', "~>0.1"
|
@@ -109,6 +109,20 @@ my_ar_object.module_field = "MyClass::MyModule1"
|
|
109
109
|
my_ar_object.module_field #=> MyARObject::MyClass::MyModule::Module
|
110
110
|
```
|
111
111
|
|
112
|
+
### Comparing modules with strings and symbols
|
113
|
+
|
114
|
+
In order to compare modules with Strings or Symbols you'll have to use the `ActiveModule::Comparison`
|
115
|
+
refinement. This refinement adds the method `Module#=~` to the `Module` class, but this change is
|
116
|
+
only available within the namespace that includes the refinement.
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
module YourClassOrModuleThatWantsToCompare
|
120
|
+
using ActiveModule::Comparison
|
121
|
+
def method_that_compares
|
122
|
+
my_ar_object.module_field =~ :MyModule1
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
112
126
|
## Examples
|
113
127
|
|
114
128
|
### Strategy Pattern (composition-based polymorphism)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveModule
|
4
|
+
module Comparison
|
5
|
+
refine ::Module do
|
6
|
+
using ActiveModule::ModuleRefinement
|
7
|
+
|
8
|
+
def =~(other)
|
9
|
+
case other
|
10
|
+
when nil
|
11
|
+
false
|
12
|
+
when ::Module
|
13
|
+
super(other)
|
14
|
+
when ::String
|
15
|
+
(@possible_names ||= possible_names).include?(other)
|
16
|
+
when ::Symbol
|
17
|
+
(@possible_names ||= possible_names).include?(other.to_s)
|
18
|
+
else
|
19
|
+
false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
using self
|
25
|
+
|
26
|
+
def self.compare(module1, module2)
|
27
|
+
module1 =~ module2
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/active_module.rb
CHANGED
@@ -4,6 +4,7 @@ require_relative "active_module/version"
|
|
4
4
|
require_relative "active_module/base"
|
5
5
|
require_relative "active_module/invalid_module_value"
|
6
6
|
require_relative "active_module/register"
|
7
|
+
require_relative "active_module/comparison"
|
7
8
|
require "active_module/railtie" if defined?(Rails::Railtie)
|
8
9
|
|
9
10
|
module ActiveModule
|
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.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Rolo
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- Rakefile
|
59
59
|
- lib/active_module.rb
|
60
60
|
- lib/active_module/base.rb
|
61
|
+
- lib/active_module/comparison.rb
|
61
62
|
- lib/active_module/invalid_module_value.rb
|
62
63
|
- lib/active_module/module_refinement.rb
|
63
64
|
- lib/active_module/modules_index.rb
|
@@ -65,7 +66,8 @@ files:
|
|
65
66
|
- lib/active_module/register.rb
|
66
67
|
- lib/active_module/version.rb
|
67
68
|
homepage: https://github.com/pedrorolo/active_module
|
68
|
-
licenses:
|
69
|
+
licenses:
|
70
|
+
- MIT
|
69
71
|
metadata:
|
70
72
|
homepage_uri: https://github.com/pedrorolo/active_module
|
71
73
|
source_code_uri: https://github.com/pedrorolo/active_module
|