pears 0.2.0 → 0.3.2

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: e90770f906724b64b6ae99ee1688230dd0d8b46727be9dd444ae026067cd814e
4
+ data.tar.gz: 37c6daf85a0aaba38e8d8ff8fe20cd281d0a3504f80fa679d818f6cab866904a
5
5
  SHA512:
6
- metadata.gz: 3e5da3506aa2ae5fd633a8ef815b109bf317d6c9338a4730b0f3d304dce946158cac778e8cdb67c510c9ff02a69dec318f2c35eb6307f9ede9367fcc716cfb2d
7
- data.tar.gz: edf8f9e02d5c04de51c97400bcf666c362e92a5ce0b91ad8d6820360c0e111e8b83b5d9f155d75e473bf546acb7af8aa945a54cefe8e4f5fd89fb18faf8e0bab
6
+ metadata.gz: 960a73a2741bc5febbcfaad6931f97475b2171bbddcb1d6460cf075e68dd3448a98462569042309223b8e2ed634bdd6414d781323905e9373c4baa7d1766d0d2
7
+ data.tar.gz: bcb0ee18a1938ea763a2597a3af626073d24735d2048898ec439c96d3caf6ea7ba4874e2612a02faad043ec7547303194429758535554cb234c1d5263bd8426c
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.3.1)
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.1)
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
- dry-core (0.7.1)
23
+ dry-core (0.8.0)
24
24
  concurrent-ruby (~> 1.0)
25
- i18n (1.10.0)
25
+ i18n (1.12.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)
@@ -42,7 +42,7 @@ GEM
42
42
  diff-lcs (>= 1.2.0, < 2.0)
43
43
  rspec-support (~> 3.10.0)
44
44
  rspec-support (3.10.3)
45
- tzinfo (2.0.4)
45
+ tzinfo (2.0.5)
46
46
  concurrent-ruby (~> 1.0)
47
47
 
48
48
  PLATFORMS
@@ -0,0 +1,14 @@
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
+
9
+ def reboot
10
+ Pears.subjects.each(&:reboot)
11
+ end
12
+ end
13
+ end
14
+ 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,15 +3,16 @@ 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
10
10
 
11
- def initialize(name, *layers)
11
+ def initialize(name, *layers, loader: ->(builder){} )
12
12
  @name = name
13
13
  @layers = layers
14
- Pears.subjects << self
14
+ @loader = loader
15
+ boot
15
16
  end
16
17
 
17
18
  def [](key)
@@ -30,6 +31,10 @@ module Pears
30
31
  project.dig(*args)
31
32
  end
32
33
 
34
+ def purge
35
+ @layers.each.each(&:purge)
36
+ end
37
+
33
38
  def push_layer(layer)
34
39
  @layers << layer
35
40
  end
@@ -45,8 +50,18 @@ module Pears
45
50
  project.each(&block)
46
51
  end
47
52
 
53
+ def reboot
54
+ purge
55
+ @layers = []
56
+ boot
57
+ end
58
+
48
59
  private
49
60
 
61
+ def boot
62
+ @loader.call(Provider::Builder.new(self))
63
+ end
64
+
50
65
  def layers
51
66
  @layers
52
67
  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.2"
5
5
  end
@@ -0,0 +1,23 @@
1
+ <html>
2
+ <head>
3
+ <style><%=render('style')%></style>
4
+ </head>
5
+ <body>
6
+ <header>
7
+ <h1> Pears::Subjects </h1>
8
+ </header>
9
+ <main>
10
+ <nav>
11
+ <% @subjects.each do |subject| %>
12
+ <p> <a href=<%="./subjects/#{subject.name}"%>><%= subject.name %></a> </p>
13
+ <% end %>
14
+ </nav>
15
+ <section>
16
+ <p> No subject selected </p>
17
+ </section>
18
+ </main>
19
+
20
+ <footer>
21
+ <p class='p--footer' > Pears web-interface </p>
22
+ </footer>
23
+ </body>
@@ -0,0 +1,23 @@
1
+ <html>
2
+ <head>
3
+ <style><%=render('style')%></style>
4
+ </head>
5
+ <body>
6
+ <header>
7
+ <h1> Pears::Subjects </h1>
8
+ <form method="post">
9
+ <input type='submit' value='Reboot <%= @subject.name.to_s.humanize %>' name="reboot-<%=@subject.name%>}">
10
+ </form>
11
+ </header>
12
+ <main>
13
+ <nav>
14
+ <% @subjects.each do |subject| %>
15
+ <p> <a href=<%=subject.name%>><%= subject.name.to_s.humanize.capitalize %></a> </p>
16
+ <% end %>
17
+ </nav>
18
+ <section>
19
+ <h3><%= @subject.name.capitalize %></h3>
20
+ <div class='serialization'><%= JSON.pretty_generate(@subject.project) %></div>
21
+ </section>
22
+ </main>
23
+ </body>
@@ -0,0 +1,58 @@
1
+ body {
2
+ font-family: "Avenir", "Arial", sans-serif;
3
+ color: 222;padding: 0px 30px 10px 30px;
4
+ margin: 0;
5
+ background-color: FFF;
6
+ }
7
+
8
+ header {
9
+ padding-top: 4px;
10
+ height: 60px;
11
+ display: flex;
12
+ justify-content: space-between;
13
+ align-items: center;
14
+ }
15
+
16
+ main {
17
+ height: calc(100vh - 160px);
18
+ display: flex;
19
+ }
20
+
21
+ footer {
22
+ margin: 20px 20px 10px 20px;
23
+ height: 20px;
24
+ }
25
+
26
+ .p--footer {
27
+ width: 100%;
28
+ text-align: right;
29
+ }
30
+
31
+ nav {
32
+ padding: 0px 10px 10px 0;
33
+ display: block;
34
+ border-right: 1px solid #CCC;
35
+ min-width: 15%;
36
+ min-height: 100%;
37
+ }
38
+
39
+ section {
40
+ padding: 0px 10px 10px 20px;
41
+ width: 85%;
42
+ min-height: 100%;
43
+ }
44
+
45
+ .serialization {
46
+ font-family: 'SF mono', 'Courier', monospace;
47
+ white-space: pre;
48
+ background-color: eeeeee;
49
+ border-radius: 11px;
50
+ padding: 15px;
51
+ }
52
+
53
+ input[type=submit]{
54
+ padding: 10px 22px;
55
+ background-color: fff;
56
+ border-radius: 6px;
57
+ border: 1px solid #666;
58
+ }
data/lib/pears/web.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'roda'
2
+ require 'json'
3
+
4
+ module Pears
5
+ class Web < Roda
6
+ plugin :render, views: "#{__FILE__}/../web/views"
7
+
8
+ route do |r|
9
+ r.root do
10
+ r.redirect "#{request.path}index"
11
+ end
12
+
13
+ r.get "index" do
14
+ @subjects = Pears.subjects
15
+ render('index')
16
+ end
17
+
18
+ r.on "subjects" do
19
+ r.is do
20
+ r.redirect "#{request.path.delete_suffix('/subjects')}/index"
21
+ end
22
+
23
+ r.get String do |subject|
24
+ @subjects = Pears.subjects
25
+ @subject = Pears[subject.to_sym]
26
+ render('show')
27
+ end
28
+
29
+ r.post String do |subject|
30
+ @subjects = Pears.subjects
31
+ @subject = Pears[subject.to_sym]
32
+ @subject.reboot
33
+ render('show')
34
+ end
35
+ end
36
+ end
37
+ end
38
+ 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
@@ -15,11 +16,15 @@ module Pears
15
16
  end
16
17
 
17
18
  # This is the main way of locating a subject.
18
- def self.subject(name)
19
- subjects
20
- Subject.new(name).tap do |subject|
21
- builder = Provider::Builder.new(subject)
22
- @subjects << yield(builder)
19
+ def self.subject(name, &block)
20
+ if subjects.any? { |sub| sub.name == name }
21
+ raise Pears::Error.new("subject name #{name} is already in use.")
23
22
  end
23
+
24
+ Subject.new(name, loader: block).tap { |sub| @subjects.push sub }
25
+ end
26
+
27
+ def self.[](name)
28
+ subjects.find { |subject| subject.name == name }
24
29
  end
25
30
  end
data/pears.gemspec CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency 'dry-configurable', '>= 0.13.0'
29
29
  spec.add_dependency 'activesupport'
30
30
  spec.add_dependency 'redis'
31
+ spec.add_dependency 'roda'
31
32
 
32
33
  spec.add_development_dependency 'byebug'
33
34
  # For more information and examples about making a new gem, checkout our
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.2
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-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: roda
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: byebug
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -84,10 +98,12 @@ files:
84
98
  - bin/console
85
99
  - bin/setup
86
100
  - lib/pears.rb
101
+ - lib/pears/commands.rb
87
102
  - lib/pears/errors.rb
88
103
  - lib/pears/provider.rb
89
104
  - lib/pears/provider/base.rb
90
105
  - lib/pears/provider/builder.rb
106
+ - lib/pears/provider/debugger.rb
91
107
  - lib/pears/provider/env.rb
92
108
  - lib/pears/provider/hash.rb
93
109
  - lib/pears/provider/local_file.rb
@@ -96,7 +112,13 @@ files:
96
112
  - lib/pears/provider/remote_file.rb
97
113
  - lib/pears/provider/subscription.rb
98
114
  - lib/pears/subject.rb
115
+ - lib/pears/testing.rb
116
+ - lib/pears/testing/subject.rb
99
117
  - lib/pears/version.rb
118
+ - lib/pears/web.rb
119
+ - lib/pears/web/views/index.erb
120
+ - lib/pears/web/views/show.erb
121
+ - lib/pears/web/views/style.erb
100
122
  - pears.gemspec
101
123
  homepage: https://bitbucket.org/ivaldi/rubygems-pears/src/master/
102
124
  licenses: