pears 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7abec7354b67f08e28107cfb1fb8c94864d7ac207ff1b7fd64fc916768195544
4
- data.tar.gz: ecd79dde81cd9964d287aaa12e42bbc6c449403b4eded1f5a23d1d886d735066
3
+ metadata.gz: d7fc395542fa7edb5343dfc3a609289406dca92f8286b4db8c5dab540a514872
4
+ data.tar.gz: fcd9e6d1caef736a54bbb4debb3fd2a3d805d13d26e7e02f2a81df0ef6742a3e
5
5
  SHA512:
6
- metadata.gz: 3e5da3506aa2ae5fd633a8ef815b109bf317d6c9338a4730b0f3d304dce946158cac778e8cdb67c510c9ff02a69dec318f2c35eb6307f9ede9367fcc716cfb2d
7
- data.tar.gz: edf8f9e02d5c04de51c97400bcf666c362e92a5ce0b91ad8d6820360c0e111e8b83b5d9f155d75e473bf546acb7af8aa945a54cefe8e4f5fd89fb18faf8e0bab
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.1.3)
4
+ pears (0.2.0)
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 (7.0.2.3)
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)
@@ -17,16 +17,16 @@ GEM
17
17
  byebug (11.1.3)
18
18
  concurrent-ruby (1.1.10)
19
19
  diff-lcs (1.4.4)
20
- dry-configurable (0.14.0)
20
+ dry-configurable (0.15.0)
21
21
  concurrent-ruby (~> 1.0)
22
22
  dry-core (~> 0.6)
23
23
  dry-core (0.7.1)
24
24
  concurrent-ruby (~> 1.0)
25
25
  i18n (1.10.0)
26
26
  concurrent-ruby (~> 1.0)
27
- minitest (5.15.0)
27
+ minitest (5.16.2)
28
28
  rake (13.0.6)
29
- redis (4.6.0)
29
+ redis (4.7.1)
30
30
  rspec (3.10.0)
31
31
  rspec-core (~> 3.10.0)
32
32
  rspec-expectations (~> 3.10.0)
@@ -0,0 +1,10 @@
1
+ module Pears
2
+ module Commands
3
+ class << self
4
+ def purge_subjects
5
+ Pears.subjects.each(&:purge)
6
+ Pears.instance_variable_set('@subjects', [])
7
+ end
8
+ end
9
+ end
10
+ end
data/lib/pears/errors.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module Pears
2
2
  class Error < StandardError; end
3
3
  class RedisHasLeftTheBuilding < Error; end
4
+ class SubjectNotfound < Error; end
4
5
  class Pears::InvalidProviderData < Error; end
5
6
  end
@@ -19,6 +19,10 @@ module Pears
19
19
  @data[key]
20
20
  end
21
21
 
22
+ def purge
23
+ true
24
+ end
25
+
22
26
  private
23
27
 
24
28
  def parse_yaml(yaml_string)
@@ -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
+
@@ -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
- connection.subscribe(channel) do |on|
52
- on.message do |channel, message|
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
 
@@ -7,6 +7,7 @@ require_relative "provider/env"
7
7
  require_relative "provider/loco"
8
8
  require_relative "provider/hash"
9
9
  require_relative "provider/builder"
10
+ require_relative "provider/debugger"
10
11
 
11
12
  module Pears
12
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 translations.
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pears
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
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
- @subjects << yield(builder)
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.2.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-03-30 00:00:00.000000000 Z
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,10 +84,12 @@ 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
@@ -96,6 +98,8 @@ files:
96
98
  - lib/pears/provider/remote_file.rb
97
99
  - lib/pears/provider/subscription.rb
98
100
  - lib/pears/subject.rb
101
+ - lib/pears/testing.rb
102
+ - lib/pears/testing/subject.rb
99
103
  - lib/pears/version.rb
100
104
  - pears.gemspec
101
105
  homepage: https://bitbucket.org/ivaldi/rubygems-pears/src/master/