pears 0.1.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -9
- data/lib/pears/commands.rb +10 -0
- data/lib/pears/errors.rb +1 -0
- data/lib/pears/provider/base.rb +4 -0
- data/lib/pears/provider/builder.rb +15 -1
- data/lib/pears/provider/debugger.rb +14 -0
- data/lib/pears/provider/rails_config.rb +23 -0
- data/lib/pears/provider/remote_file.rb +2 -1
- data/lib/pears/provider/subscription.rb +12 -4
- data/lib/pears/provider.rb +2 -0
- data/lib/pears/subject.rb +5 -2
- data/lib/pears/testing/subject.rb +24 -0
- data/lib/pears/testing.rb +32 -0
- data/lib/pears/version.rb +1 -1
- data/lib/pears.rb +7 -2
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7fc395542fa7edb5343dfc3a609289406dca92f8286b4db8c5dab540a514872
|
4
|
+
data.tar.gz: fcd9e6d1caef736a54bbb4debb3fd2a3d805d13d26e7e02f2a81df0ef6742a3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54cb6031fe170893891123588cd2bb1b2f9e4fd350a5bc9e54b081af3609c8fc80b092756dd9025ef1f497de750bb2c760e5d3c9fddcf7817da0f4898c21056b
|
7
|
+
data.tar.gz: 6ea523856f8af120dd3569c735603d5735448e6ac28a27db1f7af99236d1ca6104d6ece4142d3807a89c306533646da62877c3bd0449887909e4928f07e914e9
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pears (0.0
|
4
|
+
pears (0.2.0)
|
5
5
|
activesupport
|
6
6
|
dry-configurable (>= 0.13.0)
|
7
7
|
redis
|
@@ -9,25 +9,24 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (
|
12
|
+
activesupport (7.0.3)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 1.6, < 2)
|
15
15
|
minitest (>= 5.1)
|
16
16
|
tzinfo (~> 2.0)
|
17
|
-
zeitwerk (~> 2.3)
|
18
17
|
byebug (11.1.3)
|
19
|
-
concurrent-ruby (1.1.
|
18
|
+
concurrent-ruby (1.1.10)
|
20
19
|
diff-lcs (1.4.4)
|
21
|
-
dry-configurable (0.
|
20
|
+
dry-configurable (0.15.0)
|
22
21
|
concurrent-ruby (~> 1.0)
|
23
22
|
dry-core (~> 0.6)
|
24
23
|
dry-core (0.7.1)
|
25
24
|
concurrent-ruby (~> 1.0)
|
26
|
-
i18n (1.
|
25
|
+
i18n (1.10.0)
|
27
26
|
concurrent-ruby (~> 1.0)
|
28
|
-
minitest (5.
|
27
|
+
minitest (5.16.2)
|
29
28
|
rake (13.0.6)
|
30
|
-
redis (4.
|
29
|
+
redis (4.7.1)
|
31
30
|
rspec (3.10.0)
|
32
31
|
rspec-core (~> 3.10.0)
|
33
32
|
rspec-expectations (~> 3.10.0)
|
@@ -45,7 +44,6 @@ GEM
|
|
45
44
|
rspec-support (3.10.3)
|
46
45
|
tzinfo (2.0.4)
|
47
46
|
concurrent-ruby (~> 1.0)
|
48
|
-
zeitwerk (2.5.1)
|
49
47
|
|
50
48
|
PLATFORMS
|
51
49
|
arm64-darwin-20
|
data/lib/pears/errors.rb
CHANGED
data/lib/pears/provider/base.rb
CHANGED
@@ -7,13 +7,23 @@ module Pears
|
|
7
7
|
def self.enable_provider(provider, yielder: false)
|
8
8
|
method_name = provider.name.split('::').last.underscore.to_sym
|
9
9
|
if yielder
|
10
|
-
define_method(method_name) do |*args, &block|
|
10
|
+
define_method(method_name) do |*args, **opts, &block|
|
11
|
+
# Skip if Rails environment should not use this perticular setting
|
12
|
+
if defined?(Rails)
|
13
|
+
return if Array.wrap(opts[:skip_env]).include?(Rails.env.to_sym)
|
14
|
+
end
|
15
|
+
|
11
16
|
pr = provider.new(builder: self, &block)
|
12
17
|
push pr
|
13
18
|
pr
|
14
19
|
end
|
15
20
|
else
|
16
21
|
define_method(method_name) do |*args, **opts, &block|
|
22
|
+
# Skip if Rails environment should not use this perticular setting
|
23
|
+
if defined?(Rails)
|
24
|
+
return if Array.wrap(opts[:skip_env]).include?(Rails.env.to_sym)
|
25
|
+
end
|
26
|
+
|
17
27
|
pr = provider.new(*args, **opts, &block)
|
18
28
|
push pr
|
19
29
|
pr
|
@@ -26,6 +36,10 @@ module Pears
|
|
26
36
|
enable_provider RemoteFile
|
27
37
|
enable_provider Subscription, yielder: true
|
28
38
|
|
39
|
+
if defined?(Rails) == "constant"
|
40
|
+
enable_provider RailsConfig
|
41
|
+
end
|
42
|
+
|
29
43
|
delegate :name, to: :subject
|
30
44
|
|
31
45
|
def initialize(subject)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Pears
|
2
|
+
# Move this one into Pears, its really handy!
|
3
|
+
module Provider
|
4
|
+
class Debuggy < Pears::Provider::Base
|
5
|
+
def data
|
6
|
+
puts "Pears Debugger was called."
|
7
|
+
puts @data
|
8
|
+
@data
|
9
|
+
end
|
10
|
+
end
|
11
|
+
Provider::Builder.enable_provider Pears::Provider::Debuggy
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
3
|
+
|
4
|
+
module Pears
|
5
|
+
module Provider
|
6
|
+
# Used for loading simple YAML file locally.
|
7
|
+
class RailsConfig < Base
|
8
|
+
def initialize(*path_parts, on_failure: :raise)
|
9
|
+
file = path_parts.pop
|
10
|
+
file_path = Rails.root.join('config', *path_parts, "#{file}.yml")
|
11
|
+
yaml_data = File.read(file_path)
|
12
|
+
@data = parse_yaml(yaml_data)
|
13
|
+
rescue Errno::ENOENT,
|
14
|
+
Pears::InvalidProviderData => error
|
15
|
+
if on_failure == :null
|
16
|
+
@data = {}
|
17
|
+
else
|
18
|
+
raise error
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -44,16 +44,24 @@ module Pears
|
|
44
44
|
@subscription.terminate
|
45
45
|
end
|
46
46
|
|
47
|
+
def purge
|
48
|
+
unsubscribe
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
47
52
|
private
|
48
53
|
|
49
54
|
def subscribe
|
55
|
+
nth = 0
|
50
56
|
@subscription = Thread.new do
|
51
|
-
|
52
|
-
|
53
|
-
load_config
|
57
|
+
loop do
|
58
|
+
connection.subscribe(channel) do |on|
|
59
|
+
on.message { |_channel, _message| load_config }
|
54
60
|
end
|
61
|
+
|
62
|
+
nth += 1
|
63
|
+
puts "Pears connection was lost for the #{nth}th time"
|
55
64
|
end
|
56
|
-
puts "Redis connection died!"
|
57
65
|
end
|
58
66
|
end
|
59
67
|
|
data/lib/pears/provider.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require_relative "provider/base"
|
2
2
|
require_relative "provider/local_file"
|
3
3
|
require_relative "provider/remote_file"
|
4
|
+
require_relative "provider/rails_config"
|
4
5
|
require_relative "provider/subscription"
|
5
6
|
require_relative "provider/env"
|
6
7
|
require_relative "provider/loco"
|
7
8
|
require_relative "provider/hash"
|
8
9
|
require_relative "provider/builder"
|
10
|
+
require_relative "provider/debugger"
|
9
11
|
|
10
12
|
module Pears
|
11
13
|
module Provider
|
data/lib/pears/subject.rb
CHANGED
@@ -3,7 +3,7 @@ require 'active_support/core_ext/hash/indifferent_access'
|
|
3
3
|
module Pears
|
4
4
|
# A subject is a collection of settings.
|
5
5
|
# You could different Pears::Subjects in your application for different parts
|
6
|
-
# of its domain. for instance: application_settings, theming or
|
6
|
+
# of its domain. for instance: application_settings, theming or translaions.
|
7
7
|
class Subject
|
8
8
|
include Enumerable
|
9
9
|
attr_reader :name
|
@@ -11,7 +11,6 @@ module Pears
|
|
11
11
|
def initialize(name, *layers)
|
12
12
|
@name = name
|
13
13
|
@layers = layers
|
14
|
-
Pears.subjects << self
|
15
14
|
end
|
16
15
|
|
17
16
|
def [](key)
|
@@ -30,6 +29,10 @@ module Pears
|
|
30
29
|
project.dig(*args)
|
31
30
|
end
|
32
31
|
|
32
|
+
def purge
|
33
|
+
@layers.each.each(&:purge)
|
34
|
+
end
|
35
|
+
|
33
36
|
def push_layer(layer)
|
34
37
|
@layers << layer
|
35
38
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Pears
|
2
|
+
module Testing
|
3
|
+
module Subject
|
4
|
+
def prepend *address, is:
|
5
|
+
@layers = @layers.unshift Pears::Provider::Hash.new(hasher(address, is: is))
|
6
|
+
end
|
7
|
+
|
8
|
+
def shift
|
9
|
+
@layers.shift
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def hasher(address, is:)
|
15
|
+
local = address.shift
|
16
|
+
if address.empty?
|
17
|
+
{ local => is }
|
18
|
+
else
|
19
|
+
{ local => hasher(address, is: is) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'pears/testing/subject'
|
2
|
+
|
3
|
+
module Pears
|
4
|
+
module Testing
|
5
|
+
def self.prepend_subject subject_name, *address, is:
|
6
|
+
subject = find_subject!(subject_name)
|
7
|
+
subject.prepend *address, is: is
|
8
|
+
begin
|
9
|
+
yield
|
10
|
+
ensure
|
11
|
+
subject.shift
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find_subject!(name)
|
16
|
+
Pears.subjects
|
17
|
+
.find { |subject| subject.name.to_sym == name.to_sym }.tap do |sub|
|
18
|
+
unless sub.present?
|
19
|
+
raise SubjectNotfound.new(
|
20
|
+
message: "No subject with the name #{subject_name} exists."
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module Pears
|
29
|
+
class Subject
|
30
|
+
include Pears::Testing::Subject
|
31
|
+
end
|
32
|
+
end
|
data/lib/pears/version.rb
CHANGED
data/lib/pears.rb
CHANGED
@@ -4,6 +4,7 @@ require_relative "pears/version"
|
|
4
4
|
require_relative "pears/errors"
|
5
5
|
require_relative "pears/provider"
|
6
6
|
require_relative "pears/subject"
|
7
|
+
require_relative "pears/commands"
|
7
8
|
|
8
9
|
module Pears
|
9
10
|
extend Dry::Configurable
|
@@ -16,10 +17,14 @@ module Pears
|
|
16
17
|
|
17
18
|
# This is the main way of locating a subject.
|
18
19
|
def self.subject(name)
|
19
|
-
subjects
|
20
|
+
if subjects.any? { |sub| sub.name == name }
|
21
|
+
raise Pears::Error.new("subject name #{name} is already in use.")
|
22
|
+
end
|
23
|
+
|
20
24
|
Subject.new(name).tap do |subject|
|
21
25
|
builder = Provider::Builder.new(subject)
|
22
|
-
|
26
|
+
yield(builder)
|
27
|
+
@subjects.push subject
|
23
28
|
end
|
24
29
|
end
|
25
30
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Kemp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|
@@ -84,17 +84,22 @@ files:
|
|
84
84
|
- bin/console
|
85
85
|
- bin/setup
|
86
86
|
- lib/pears.rb
|
87
|
+
- lib/pears/commands.rb
|
87
88
|
- lib/pears/errors.rb
|
88
89
|
- lib/pears/provider.rb
|
89
90
|
- lib/pears/provider/base.rb
|
90
91
|
- lib/pears/provider/builder.rb
|
92
|
+
- lib/pears/provider/debugger.rb
|
91
93
|
- lib/pears/provider/env.rb
|
92
94
|
- lib/pears/provider/hash.rb
|
93
95
|
- lib/pears/provider/local_file.rb
|
94
96
|
- lib/pears/provider/loco.rb
|
97
|
+
- lib/pears/provider/rails_config.rb
|
95
98
|
- lib/pears/provider/remote_file.rb
|
96
99
|
- lib/pears/provider/subscription.rb
|
97
100
|
- lib/pears/subject.rb
|
101
|
+
- lib/pears/testing.rb
|
102
|
+
- lib/pears/testing/subject.rb
|
98
103
|
- lib/pears/version.rb
|
99
104
|
- pears.gemspec
|
100
105
|
homepage: https://bitbucket.org/ivaldi/rubygems-pears/src/master/
|