pears 0.0.3 → 0.0.7
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/Gemfile.lock +3 -3
- data/lib/pears/provider/builder.rb +32 -23
- data/lib/pears/provider/subscription.rb +21 -6
- data/lib/pears/provider.rb +3 -0
- data/lib/pears/version.rb +1 -1
- data/lib/pears.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19c55e7f744c1a5403452f6c6d3a88246e185ce2e1abad292b66146347fac14a
|
4
|
+
data.tar.gz: 2bf8070b221f5bb58b843c83ff3d9a19e355f4134fbca2920622b1898a93a433
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0b5d6f09fe5f6c1aca571afed5f5c3576441f370ef27d67083ae7e9f98ddd270c0e55404dad2afa9c6ae0ca8f92af275504261dc3e87c6ddaa26c644d544e01
|
7
|
+
data.tar.gz: 940068ae86b7ba75f7290fea87d0f36b5c38d02bf39946c2bb253d469c017175307abd58e3c3ee7f10a31764e644bcd69cb0d25afdaeb51976d9c57b32ebb529
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pears (0.
|
4
|
+
pears (0.0.7)
|
5
5
|
activesupport
|
6
6
|
dry-configurable (>= 0.13.0)
|
7
7
|
redis
|
@@ -9,7 +9,7 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (6.1.4.
|
12
|
+
activesupport (6.1.4.3)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 1.6, < 2)
|
15
15
|
minitest (>= 5.1)
|
@@ -25,7 +25,7 @@ GEM
|
|
25
25
|
concurrent-ruby (~> 1.0)
|
26
26
|
i18n (1.8.11)
|
27
27
|
concurrent-ruby (~> 1.0)
|
28
|
-
minitest (5.
|
28
|
+
minitest (5.15.0)
|
29
29
|
rake (13.0.6)
|
30
30
|
redis (4.5.1)
|
31
31
|
rspec (3.10.0)
|
@@ -1,44 +1,53 @@
|
|
1
1
|
require 'active_support/core_ext/module'
|
2
2
|
|
3
3
|
module Pears
|
4
|
-
module
|
4
|
+
module Provider
|
5
5
|
class Builder
|
6
|
+
# Evil meta programming.
|
7
|
+
def self.enable_provider(provider, yielder: false)
|
8
|
+
method_name = provider.name.split('::').last.underscore.to_sym
|
9
|
+
if yielder
|
10
|
+
define_method(method_name) do |*args, &block|
|
11
|
+
pr = provider.new(builder: self, &block)
|
12
|
+
push pr
|
13
|
+
pr
|
14
|
+
end
|
15
|
+
else
|
16
|
+
define_method(method_name) do |*args, **opts, &block|
|
17
|
+
pr = provider.new(*args, **opts, &block)
|
18
|
+
push pr
|
19
|
+
pr
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# define Providers
|
25
|
+
enable_provider LocalFile
|
26
|
+
enable_provider RemoteFile
|
27
|
+
enable_provider Subscription, yielder: true
|
28
|
+
|
6
29
|
delegate :name, to: :subject
|
7
30
|
|
8
31
|
def initialize(subject)
|
9
32
|
@subject = subject
|
10
33
|
end
|
11
34
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def loco
|
17
|
-
raise 'not yet implemented'
|
18
|
-
end
|
19
|
-
|
20
|
-
def env
|
21
|
-
raise 'not yet implemented'
|
22
|
-
end
|
23
|
-
|
24
|
-
def local_file(file_path)
|
25
|
-
register Provider::LocalFile.new(file_path)
|
26
|
-
end
|
27
|
-
|
28
|
-
def remote_file(file_url)
|
29
|
-
register Provider::RemoteFile.new(file_url)
|
35
|
+
def freeze_layers
|
36
|
+
@skip_push = true
|
37
|
+
yield
|
38
|
+
@skip_push = false
|
30
39
|
end
|
31
40
|
|
32
|
-
def
|
33
|
-
|
41
|
+
def subject_name
|
42
|
+
@subject.name
|
34
43
|
end
|
35
44
|
|
36
45
|
private
|
37
46
|
|
38
|
-
def
|
47
|
+
def push provider
|
39
48
|
return provider unless @subject.is_a? Subject
|
40
49
|
|
41
|
-
@subject.push_layer provider
|
50
|
+
@subject.push_layer provider unless @skip_push
|
42
51
|
end
|
43
52
|
end
|
44
53
|
end
|
@@ -1,27 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'redis'
|
3
3
|
|
4
|
+
|
4
5
|
module Pears
|
5
6
|
module Provider
|
6
7
|
# Config using redis subscription. This updates automatically upon Redis
|
7
8
|
# channel updates.
|
9
|
+
# This class would register as "alternative classes with different interfaces".
|
10
|
+
# I ought to clean this up and maybe make "triggers" a different entity
|
11
|
+
# from a provider available in the builder.
|
12
|
+
|
8
13
|
class Subscription < Base
|
9
14
|
attr_reader :subscription
|
10
|
-
|
11
|
-
def initialize(channel,
|
15
|
+
def initialize(channel=nil,
|
12
16
|
redis_host: Pears.config.redis_host,
|
17
|
+
**opts,
|
13
18
|
&fetcher)
|
19
|
+
@builder = opts[:builder] || Builder.new(nil)
|
14
20
|
@channel = channel
|
21
|
+
|
22
|
+
# Fetcher is a "Provider" of some sort.
|
15
23
|
@fetcher = fetcher
|
16
24
|
|
25
|
+
# Setup redis subscription
|
17
26
|
establish_connection(redis_host)
|
18
|
-
subscribe
|
19
27
|
reload
|
28
|
+
subscribe
|
29
|
+
end
|
30
|
+
|
31
|
+
def channel
|
32
|
+
@channel ||= @builder.subject_name
|
20
33
|
end
|
21
34
|
|
22
35
|
def reload
|
23
|
-
@
|
24
|
-
|
36
|
+
@builder.freeze_layers do
|
37
|
+
@data = @fetcher.call.data
|
38
|
+
end
|
25
39
|
end
|
26
40
|
|
27
41
|
# This seems a bit "rough" of an approach. we should check if
|
@@ -34,11 +48,12 @@ module Pears
|
|
34
48
|
|
35
49
|
def subscribe
|
36
50
|
@subscription = Thread.new do
|
37
|
-
connection.subscribe(
|
51
|
+
connection.subscribe(channel) do |on|
|
38
52
|
on.message do |channel, message|
|
39
53
|
reload
|
40
54
|
end
|
41
55
|
end
|
56
|
+
puts "Redis connection died!"
|
42
57
|
end
|
43
58
|
end
|
44
59
|
|
data/lib/pears/provider.rb
CHANGED
data/lib/pears/version.rb
CHANGED
data/lib/pears.rb
CHANGED
@@ -16,8 +16,8 @@ module Pears
|
|
16
16
|
|
17
17
|
# This is the main way of locating a subject.
|
18
18
|
def self.subject(name)
|
19
|
-
Subject.new(name
|
20
|
-
builder =
|
19
|
+
Subject.new(name).tap do |subject|
|
20
|
+
builder = Provider::Builder.new(subject)
|
21
21
|
yield(builder)
|
22
22
|
end
|
23
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pears
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Kemp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|