plugs 0.3.0 → 0.4.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 +4 -4
- data/lib/lazy.rb +19 -0
- data/lib/plugs.rb +18 -5
- data/lib/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 819e6b94b7d18042ac02651f7bba2343df9cf06ae0995b8ffa6117a7804da78d
|
|
4
|
+
data.tar.gz: a54bf7cf98c86de4252a5c3ef13daace7e55a9caea2084c9b30d4aeeda10c29f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: deec428d6c997e6913000451d6a5b2dade3dfa054a2d68f4b541650634ad1564d70bccb500932fde80c46c72cf0a69dccae448ce87e189fdab1d00b252cd13b3
|
|
7
|
+
data.tar.gz: 77a808b75ac1da073b2656492dafcb2dbb29bbe09dd6801f1783639a7f3c0b7c6f1a2770f9415932d429cacb0f64aea65a31958ff7c6c79dde1337d8bf3e4d43
|
data/lib/lazy.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Plugs
|
|
4
|
+
class Lazy
|
|
5
|
+
def self.unwrap(value)
|
|
6
|
+
value.is_a?(self) ? value.call : value
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def initialize(&block)
|
|
10
|
+
@proc = block
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def call
|
|
14
|
+
return @call if defined?(@call)
|
|
15
|
+
|
|
16
|
+
@call = @proc.call
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/plugs.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'lazy'
|
|
3
4
|
require_relative 'plug'
|
|
4
5
|
require_relative 'sub_selector'
|
|
5
6
|
|
|
@@ -15,21 +16,25 @@ module Plugs
|
|
|
15
16
|
self.class.new(plugs: SubSelector.sub_select(plugs:, keys:), keys:)
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
def
|
|
19
|
-
|
|
19
|
+
def key?(key)
|
|
20
|
+
!!@plugs[key]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def +(new_plugs)
|
|
24
|
+
@plugs.merge!(new_plugs.plugs) { |_key, a_values, b_values| [*a_values, *b_values] }
|
|
20
25
|
|
|
21
26
|
self
|
|
22
27
|
end
|
|
23
28
|
|
|
24
29
|
def to_a
|
|
25
|
-
plugs.values.flatten.map(&:result)
|
|
30
|
+
plugs.values.flatten.map(&:result).map { |value| Lazy.unwrap(value) }
|
|
26
31
|
end
|
|
27
32
|
|
|
28
33
|
def to_h
|
|
29
34
|
plugs.values.each_with_object({}) do |values, hash|
|
|
30
35
|
values.each do |plug|
|
|
31
36
|
hash[plug.key] ||= []
|
|
32
|
-
hash[plug.key] << plug.result
|
|
37
|
+
hash[plug.key] << Lazy.unwrap(plug.result)
|
|
33
38
|
end
|
|
34
39
|
end
|
|
35
40
|
end
|
|
@@ -54,12 +59,20 @@ module Plugs
|
|
|
54
59
|
nil
|
|
55
60
|
end
|
|
56
61
|
|
|
62
|
+
def lazy(&block)
|
|
63
|
+
Lazy.new(&block)
|
|
64
|
+
end
|
|
65
|
+
|
|
57
66
|
def [](*keys)
|
|
58
67
|
new(plugs: SubSelector.sub_select(plugs:, keys:), keys:)
|
|
59
68
|
end
|
|
60
69
|
|
|
70
|
+
def key?(key)
|
|
71
|
+
!!plugs[key]
|
|
72
|
+
end
|
|
73
|
+
|
|
61
74
|
def to_a
|
|
62
|
-
plugs.values.flatten.map(&:result)
|
|
75
|
+
plugs.values.flatten.map(&:result).map { |value| Lazy.unwrap(value) }
|
|
63
76
|
end
|
|
64
77
|
|
|
65
78
|
def plugs
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: plugs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- maedi
|
|
@@ -10,7 +10,7 @@ cert_chain: []
|
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: "Plugs are dependencies that are loosely coupled internally but externally
|
|
13
|
-
appear as one entity such as a feature, configuration or plugin.
|
|
13
|
+
appear as one entity such as a feature, configuration or plugin. \nA plug is reusable,
|
|
14
14
|
shareable and overridable.\n"
|
|
15
15
|
email:
|
|
16
16
|
- maediprichard@gmail.com
|
|
@@ -18,6 +18,7 @@ executables: []
|
|
|
18
18
|
extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
|
20
20
|
files:
|
|
21
|
+
- lib/lazy.rb
|
|
21
22
|
- lib/plug.rb
|
|
22
23
|
- lib/plugs.rb
|
|
23
24
|
- lib/refinements.rb
|
|
@@ -42,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
42
43
|
- !ruby/object:Gem::Version
|
|
43
44
|
version: '0'
|
|
44
45
|
requirements: []
|
|
45
|
-
rubygems_version: 4.0.
|
|
46
|
+
rubygems_version: 4.0.20
|
|
46
47
|
specification_version: 4
|
|
47
48
|
summary: Keep code loosely coupled. Keep features tightly coupled
|
|
48
49
|
test_files: []
|