plugs 0.1.0
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 +7 -0
- data/lib/plug.rb +17 -0
- data/lib/plugs.rb +38 -0
- data/lib/version.rb +5 -0
- metadata +46 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c81be8b0475267381d393f250def37b876ef358e534c5e645b1715ad11cfc019
|
|
4
|
+
data.tar.gz: 1bd993051f7a21157998b22d392c2b1c603dafa924afde6dbd53aaed0abdeb6b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5e1c50904d9e030755c37db1ef6041fdd9a58c4ac11987884c581efcb0063e105509b63712bd5f4b4a4f84229c4ad7f2bf1c3a5dabbcaabacb885000020e860b
|
|
7
|
+
data.tar.gz: 0c5d1bda47cc590873c14847a31b34c84eeb5257e5c9f668f91fb0ad2c99b7b3c97d69d33f096b4a7fdb08216dd5af16559caec66c3e80f20f3355962a70630d
|
data/lib/plug.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Plugs
|
|
4
|
+
class Plug
|
|
5
|
+
attr_reader :key, :result
|
|
6
|
+
|
|
7
|
+
def initialize(key:, eager: false, &block)
|
|
8
|
+
@key = key
|
|
9
|
+
@proc = block
|
|
10
|
+
@result = eager ? block.call : nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def result
|
|
14
|
+
@result ||= @proc.call
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/plugs.rb
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'plug'
|
|
4
|
+
|
|
5
|
+
module Plugs
|
|
6
|
+
attr_accessor :plugs
|
|
7
|
+
|
|
8
|
+
def [](*keys)
|
|
9
|
+
@plugs.values_at(*keys)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.included(base)
|
|
13
|
+
@plugs = {}
|
|
14
|
+
base.extend(ClassMethods)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
module ClassMethods
|
|
18
|
+
def [](*keys)
|
|
19
|
+
instance = new
|
|
20
|
+
instance.plugs = plugs.values_at(*keys).flatten
|
|
21
|
+
instance
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def plug(key, &block)
|
|
25
|
+
plug = Plug.new(key:, eager: true, &block)
|
|
26
|
+
|
|
27
|
+
plugs[key] ||= []
|
|
28
|
+
plugs[key] << plug
|
|
29
|
+
|
|
30
|
+
plug.result
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def plugs
|
|
34
|
+
@plugs ||= {}
|
|
35
|
+
@plugs
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: plugs
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- maedi
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: "Plugs are dependencies that are loosely coupled internally but externally
|
|
13
|
+
appear as one entity such as a feature, config object or plugin. \nA plug is reusable,
|
|
14
|
+
shareable and overridable.\n"
|
|
15
|
+
email:
|
|
16
|
+
- maediprichard@gmail.com
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- lib/plug.rb
|
|
22
|
+
- lib/plugs.rb
|
|
23
|
+
- lib/version.rb
|
|
24
|
+
homepage: https://github.com/raindeer-rb/plugs
|
|
25
|
+
licenses: []
|
|
26
|
+
metadata:
|
|
27
|
+
homepage_uri: https://github.com/raindeer-rb/plugs
|
|
28
|
+
source_code_uri: https://github.com/raindeer-rb/plugs/src/branch/main
|
|
29
|
+
rdoc_options: []
|
|
30
|
+
require_paths:
|
|
31
|
+
- lib
|
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- - ">="
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: 3.3.0
|
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
42
|
+
requirements: []
|
|
43
|
+
rubygems_version: 4.0.6
|
|
44
|
+
specification_version: 4
|
|
45
|
+
summary: Keep code loosely coupled, keep features tightly coupled
|
|
46
|
+
test_files: []
|