brewer 0.0.91 β†’ 0.0.93

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
  SHA1:
3
- metadata.gz: 746d9ad1ef9499a452104dafee8d2050ee9e23e6
4
- data.tar.gz: 411773a35835954dd35f7052c039210b5293890d
3
+ metadata.gz: 4c755e13a364fc36a15b6b6bf8322eb659a0e989
4
+ data.tar.gz: 0cd30f9c517ba49a9c1df3fd85dc56d20274237b
5
5
  SHA512:
6
- metadata.gz: a0dc5c48f26a7ed2f82a474299b937c64cf7db558661e1d7655771db5119e856ca668652bf0574d19a5f2e292405245c5a3d2532ae5c6e8c17603ba2c34bdceb
7
- data.tar.gz: 344adf9d708285bfd486fd3852dfae0100c5d639dab074a7e8a7c089f9d2a298f3f4339d8f485c33198cf0c144362d879122785a328eddb999408ab9a5bf4500
6
+ metadata.gz: 1faa193fad4f23676479df686d0116df05197a8fd5bb22232ffbcc3dd937068e5ed7f0125913c28b2ef9e4540236037cb20a800e78dd642f5f8f7e173a321087
7
+ data.tar.gz: 7a2d2de0a3b03a981f2569958c505be5313c5312f51492252a9f52eb4c92766caa0397a864ad47dc43648fea6d5a0733d37234d3518289c35ac35c858c55b637
data/bin/brewer CHANGED
@@ -6,6 +6,5 @@ slack = Brewer::Slacker.new
6
6
  brewer = Brewer::Brewer.new
7
7
  procedures = Brewer::Procedures.new
8
8
 
9
- puts "🍺 have fun 🍺"
10
9
  binding.pry(quiet: true)
11
10
  # 🍺🍺🍺
@@ -3,50 +3,49 @@ require_relative "helpers.rb"
3
3
  include Helpers
4
4
 
5
5
  module Brewer
6
- # This class handles the adaptibrew repo
7
- # It is stored in ~/.brewer/adaptibrew/
8
6
  class Adaptibrew
9
7
 
8
+ attr_accessor :disable_network_operations
9
+
10
10
  def initialize
11
+ @disable_network_operations = network? ? false : true
12
+ @adaptibrew_url = 'https://github.com/llamicron/adaptibrew.git'
13
+
11
14
  if !Dir.exists?(adaptibrew_dir)
12
15
  Dir.mkdir(adaptibrew_dir)
13
16
  end
14
17
  end
15
18
 
16
- # This will clone adaptibrew into ~/.brewer/adaptibrew/
17
19
  def clone
18
- raise "πŸ›‘ Cannot clone, no network connection" unless network?
20
+ if @disable_network_operations
21
+ return false
22
+ end
19
23
 
20
24
  if !Dir.exists?(adaptibrew_dir)
21
- Git.clone('https://github.com/llamicron/adaptibrew.git', 'adaptibrew', :path => brewer_dir)
25
+ Git.clone(@adaptibrew_url, 'adaptibrew', :path => brewer_dir)
26
+ return true
22
27
  end
23
-
24
- self
28
+ false
25
29
  end
26
30
 
27
- # Danger zone...
28
- # This deletes adaptibrew
29
31
  def clear
30
- # :nocov: since this requires network to be off
31
- if !network?
32
- print "Warning: you have no network connection. If you clear, you will not be able to clone again, and you'll be stuck without the adaptibrew source. Are you sure? "
33
- confirm ? nil : abort
32
+ if @disable_network_operations
33
+ return false
34
+ end
35
+ if present?
36
+ FileUtils.rm_rf(adaptibrew_dir)
37
+ return true
34
38
  end
35
- # :nocov:
36
- FileUtils.rm_rf(adaptibrew_dir)
37
- self
39
+ false
38
40
  end
39
41
 
40
- # This is a good catch-all method
41
- # This deletes and re-clones adaptibrew
42
42
  def refresh
43
- raise "πŸ›‘ Cannot refresh, no network connection" unless network?
44
- clear
45
- clone
46
- self
43
+ if clear and clone
44
+ return true
45
+ end
46
+ false
47
47
  end
48
48
 
49
- # Returns true if adaptibrew is present
50
49
  def present?
51
50
  return Dir.exists?(adaptibrew_dir) ? true : false
52
51
  end
@@ -36,7 +36,7 @@ module Brewer
36
36
  # Turning the pump off will turn the pid off too, as it should not be on when the pump is off
37
37
  def pump(state="status")
38
38
  if state == "status"
39
- return relay_status($settings['pumpRelay'])
39
+ return relay_status($settings['pump'])
40
40
  end
41
41
 
42
42
  if state == 1
@@ -150,7 +150,7 @@ module Brewer
150
150
  statuses = {}
151
151
  all_relays_status.shift(4).each do |status|
152
152
  relay_num, status = status.match(/relay [0-9+]([0-9]+): (on|off)/).captures
153
- relay_names = $settings.select { |key, value| key.to_s.match(/Relay/) }
153
+ relay_names = $settings.select { |key, value| key.to_s.match(/hlt|rims[^A]|pump/) }
154
154
  statuses[relay_names.key(relay_num.to_i)] = status
155
155
  end
156
156
  statuses
@@ -173,9 +173,9 @@ module Brewer
173
173
  def rims_to(location)
174
174
  if location == "mash"
175
175
  # we ended up swapping this relay, so the name is backwards
176
- relay($settings['rimsToMashRelay'], 0)
176
+ relay($settings['rimsToMash'], 0)
177
177
  elsif location == "boil"
178
- relay($settings['rimsToMashRelay'], 1)
178
+ relay($settings['rimsToMash'], 1)
179
179
  else
180
180
  raise "Not a valid location for rims valve"
181
181
  end
@@ -185,9 +185,9 @@ module Brewer
185
185
  # Diverts hlt valve to mash or boil tun
186
186
  def hlt_to(location)
187
187
  if location == "mash"
188
- relay($settings['spargeToMashRelay'], 0)
188
+ relay($settings['hltToMash'], 0)
189
189
  elsif location == "boil"
190
- relay($settings['spargeToMashRelay'], 1)
190
+ relay($settings['hltToMash'], 1)
191
191
  else
192
192
  raise "Not a valid location for the hlt valve"
193
193
  end
@@ -196,7 +196,7 @@ module Brewer
196
196
 
197
197
  # Opens or closes hlt valve
198
198
  def hlt(state)
199
- relay($settings['spargeRelay'], state)
199
+ relay($settings['hlt'], state)
200
200
  self
201
201
  end
202
202
 
@@ -31,7 +31,10 @@ module Brewer
31
31
  return true
32
32
  end
33
33
 
34
- print "Enter a recipe name to load an existing recipe, or nothing to start a new one: "
34
+ clear_screen
35
+ puts "Enter a recipe name to load an existing recipe, or nothing to start a new one."
36
+ puts list_as_table
37
+ print "> "
35
38
  name = gets.chomp.strip
36
39
 
37
40
  unless name.empty?
@@ -123,6 +126,12 @@ module Brewer
123
126
  recipes
124
127
  end
125
128
 
129
+ def list_as_table
130
+ recipes_table_rows = list_recipes.each_slice(5).to_a
131
+ recipes_table = Terminal::Table.new :title => "All Recipes", :rows => recipes_table_rows
132
+ return recipes_table
133
+ end
134
+
126
135
  def loaded_recipe?
127
136
  if File.exists?(recipe_dir(@vars['name']) + ".yml")
128
137
  return true
@@ -8,7 +8,7 @@ module Brewer
8
8
 
9
9
  def initialize(testing=false)
10
10
 
11
- @source = adaptibrew_dir('settings.py')
11
+ @source = adaptibrew_dir('print_settings.py')
12
12
  @cache_file = brewer_dir('settings.yml')
13
13
 
14
14
  @settings = Hash.new
@@ -51,19 +51,15 @@ module Brewer
51
51
  false
52
52
  end
53
53
 
54
- # Parse the settings from the source file into @settings
54
+ # Parse the settings from @source into @settings
55
55
  def parse
56
- File.open(@source, 'r') do |file|
57
- file.each_line do |line|
58
- if line.include? "=" and line[0] != "#"
59
- key, value = line.match(/(.+)=(.+)/).captures
60
- @settings[key.strip.chomp] = value.strip.chomp
61
- end
62
- end
63
- type_cast
64
- return true
56
+ settings_file_output = `python #{@source}`.chomp
57
+ settings_array = settings_file_output.split("\n")
58
+ settings_array.each do |setting|
59
+ key, value = setting.match(/(.+)=(.+)/).captures
60
+ @settings[key.strip.chomp] = value.strip.chomp
65
61
  end
66
- false
62
+ true
67
63
  end
68
64
 
69
65
  # Creates the cache if there isn't one already
@@ -108,6 +104,7 @@ module Brewer
108
104
  # and for backwards compatability purposes
109
105
  def load_global
110
106
  raise "settings instance variable does not exist yet. Run Settings#parse first" unless !@settings.empty?
107
+ type_cast
111
108
  $settings = @settings
112
109
  end
113
110
 
@@ -123,14 +120,14 @@ module Brewer
123
120
  def type_cast
124
121
  # Super janky
125
122
  change({
126
- 'rimsaddressint' => @settings['rimsaddressint'].to_i,
127
- 'switchaddressint' => @settings['switchaddressint'].to_i,
128
- 'baudrate' => @settings['baudrate'].to_i,
123
+ 'rimsAddress' => @settings['rimsAddress'].to_i,
124
+ 'switchAddress' => @settings['switchAddress'].to_i,
125
+ 'baudRate' => @settings['baudRate'].to_i,
129
126
  'timeout' => @settings['timeout'].to_i,
130
- 'spargeToMashRelay' => @settings['spargeToMashRelay'].to_i,
131
- 'spargeRelay' => @settings['spargeRelay'].to_i,
132
- 'rimsToMashRelay' => @settings['rimsToMashRelay'].to_i,
133
- 'pumpRelay' => @settings['pumpRelay'].to_i,
127
+ 'hltToMash' => @settings['hltToMash'].to_i,
128
+ 'hlt' => @settings['hlt'].to_i,
129
+ 'rimsToMash' => @settings['rimsToMash'].to_i,
130
+ 'pump' => @settings['pump'].to_i,
134
131
  'DEBUG' => @settings['DEBUG'].to_b,
135
132
  })
136
133
  end
File without changes
@@ -1,89 +1,98 @@
1
1
  require_relative 'spec_helper'
2
2
 
3
- describe Adaptibrew do
3
+ include Helpers
4
+
5
+ describe Brewer::Adaptibrew do
4
6
 
5
7
  before :each do
6
- @adaptibrew = Adaptibrew.new.refresh
8
+ @adaptibrew = Adaptibrew.new
9
+ @adaptibrew.refresh
10
+ end
11
+
12
+ after :all do
13
+ Adaptibrew.new.clone
7
14
  end
8
15
 
9
16
  describe "#new" do
10
- specify { expect(Adaptibrew.new).to be_an_instance_of Adaptibrew }
17
+ it "makes a new Adaptibrew object" do
18
+ expect(Adaptibrew.new).to be_an_instance_of Adaptibrew
19
+ end
11
20
  end
12
21
 
13
22
  describe ".clear" do
14
23
  context "when the repo exists" do
15
- let(:adaptibrew) { Adaptibrew.new }
16
- specify { expect(adaptibrew.present?).to be true }
17
-
18
- it "deletes the repo" do
19
- @adaptibrew.clear
24
+ before { @adaptibrew.clone }
25
+ specify { expect(@adaptibrew.present?).to be true }
26
+ it "deletes the repo and returns true" do
27
+ expect(@adaptibrew.clear).to be true
20
28
  expect(@adaptibrew.present?).to be false
21
29
  end
22
30
  end
23
31
 
24
32
  context "when the repo does not exist" do
25
- let(:adaptibrew) { Adaptibrew.new }
26
- before { adaptibrew.clear }
27
- specify { expect(adaptibrew.present?).to be false }
28
-
29
- it "does nothing" do
30
- @adaptibrew.clear
33
+ before { @adaptibrew.clear }
34
+ specify { expect(@adaptibrew.present?).to be false }
35
+ it "does nothing and returns false" do
36
+ expect(@adaptibrew.clear).to be false
31
37
  expect(@adaptibrew.present?).to be false
32
38
  end
33
39
  end
34
40
  end
35
41
 
36
42
  describe ".clone" do
37
- context "when the repo does not exist" do
38
- let(:adaptibrew) { Adaptibrew.new }
39
- before { adaptibrew.clear }
40
- specify { expect(adaptibrew.present?).to be false }
41
-
42
- it "clones the repo" do
43
- @adaptibrew.clone
43
+ context "when the repo exists" do
44
+ before { @adaptibrew.clone }
45
+ it "does nothing and returns false" do
46
+ expect(@adaptibrew.clone).to be false
44
47
  expect(@adaptibrew.present?).to be true
45
48
  end
46
49
  end
47
50
 
48
- context "when the repo exists" do
49
- let(:adaptibrew) { Adaptibrew.new }
50
- before { adaptibrew.clone }
51
- specify { expect(adaptibrew.present?).to be true }
52
-
53
- it "does nothing" do
54
- @adaptibrew.clone
51
+ context "when the repo does not exist" do
52
+ before { @adaptibrew.clear }
53
+ it "clones it and returns true" do
54
+ expect(@adaptibrew.clone).to be true
55
55
  expect(@adaptibrew.present?).to be true
56
56
  end
57
57
  end
58
+
59
+ context "when network operations are disabled" do
60
+ # Clearing it here so that @adaptibrew.clone would otherwise return true
61
+ before { @adaptibrew.clear}
62
+ before { @adaptibrew.disable_network_operations = true}
63
+ it "does nothing and returns false" do
64
+ expect(@adaptibrew.clone).to be false
65
+ end
66
+ after { @adaptibrew.disable_network_operations = false}
67
+ end
58
68
  end
59
69
 
60
70
  describe ".refresh" do
61
- let(:adaptibrew) { Adaptibrew.new }
62
- before { adaptibrew.refresh }
63
-
64
- it "clears and clones the repo" do # regardless of wether or not it's there
65
- expect(@adaptibrew.present?).to be true
66
- @adaptibrew.refresh
67
- expect(@adaptibrew.present?).to be true
71
+ context "when network operations are disabled" do
72
+ before { @adaptibrew.disable_network_operations = true}
73
+ it "does nothing and returns false" do
74
+ expect(@adaptibrew.refresh).to be false
75
+ end
76
+ after { @adaptibrew.disable_network_operations = false}
68
77
  end
69
78
 
79
+ it "clears and clones the repo then returns true" do
80
+ expect(@adaptibrew.refresh).to be true
81
+ end
70
82
  end
71
83
 
72
84
  describe ".present?" do
73
85
  context "when the exists" do
74
- let(:adaptibrew) { Adaptibrew.new }
75
- before { adaptibrew.refresh }
76
- specify { expect(Dir.exists?(Dir.home + '/.brewer/adaptibrew')).to be true }
77
-
86
+ before { @adaptibrew.clone }
87
+ specify { expect(Dir.exists?(adaptibrew_dir)).to be true }
78
88
  it "returns true" do
79
89
  expect(@adaptibrew.present?).to be true
80
90
  end
81
91
  end
82
92
 
83
93
  context "when the repo does not exist" do
84
- let(:adaptibrew) { Adaptibrew.new }
85
- before { adaptibrew.clear }
86
- specify { expect(Dir.exists?('adaptibrew')).to be false }
94
+ before { @adaptibrew.clear }
95
+ specify { expect(Dir.exists?(adaptibrew_dir)).to be false }
87
96
  it "returns false" do
88
97
  expect(@adaptibrew.present?).to be false
89
98
  end
@@ -92,10 +92,10 @@ describe Brewer do
92
92
 
93
93
  describe ".relay_status" do
94
94
  it "returns the status of a relay" do
95
- @brewer.relay($settings['rimsToMashRelay'], 1)
96
- expect(@brewer.relay_status($settings['rimsToMashRelay'].to_i)).to eq("on")
97
- @brewer.relay($settings['rimsToMashRelay'], 0)
98
- expect(@brewer.relay_status($settings['rimsToMashRelay'].to_i)).to eq("off")
95
+ @brewer.relay($settings['rimsToMash'], 1)
96
+ expect(@brewer.relay_status($settings['rimsToMash'].to_i)).to eq("on")
97
+ @brewer.relay($settings['rimsToMash'], 0)
98
+ expect(@brewer.relay_status($settings['rimsToMash'].to_i)).to eq("off")
99
99
  end
100
100
  end
101
101
 
@@ -104,7 +104,7 @@ describe Brewer do
104
104
  statuses = @brewer.relays_status
105
105
  expect(statuses).to be_an_instance_of Hash
106
106
  expect(statuses).to_not be_empty
107
- expect(statuses['spargeRelay']).to be_an_instance_of String
107
+ expect(statuses['hlt']).to be_an_instance_of String
108
108
  end
109
109
  end
110
110
 
@@ -120,25 +120,25 @@ describe Brewer do
120
120
  'hlt' => 1,
121
121
  'pump' => 0,
122
122
  })
123
- expect(@brewer.relay_status($settings['spargeRelay'])).to eq("on")
123
+ expect(@brewer.relay_status($settings['hlt'])).to eq("on")
124
124
  end
125
125
  end
126
126
 
127
127
  describe ".hlt" do
128
128
  it "opens or closes the hlt valve" do
129
129
  @brewer.hlt(0)
130
- expect(@brewer.relay_status($settings['spargeRelay'])).to eq("off")
130
+ expect(@brewer.relay_status($settings['hlt'])).to eq("off")
131
131
  @brewer.hlt(1)
132
- expect(@brewer.relay_status($settings['spargeRelay'])).to eq("on")
132
+ expect(@brewer.relay_status($settings['hlt'])).to eq("on")
133
133
  end
134
134
  end
135
135
 
136
136
  describe ".rims_to" do
137
137
  it "diverts the rims relay to boil or mash tuns" do
138
138
  @brewer.rims_to("boil")
139
- expect(@brewer.relay_status($settings['rimsToMashRelay'])).to eq("on")
139
+ expect(@brewer.relay_status($settings['rimsToMash'])).to eq("on")
140
140
  @brewer.rims_to("mash")
141
- expect(@brewer.relay_status($settings['rimsToMashRelay'])).to eq("off")
141
+ expect(@brewer.relay_status($settings['rimsToMash'])).to eq("off")
142
142
  end
143
143
 
144
144
  context "when the location is not valid" do
@@ -151,9 +151,9 @@ describe Brewer do
151
151
  describe ".hlt_to" do
152
152
  it "diverts the hlt relay to boil or mash tuns" do
153
153
  @brewer.hlt_to("boil")
154
- expect(@brewer.relay_status($settings['spargeToMashRelay'])).to eq("on")
154
+ expect(@brewer.relay_status($settings['hltToMash'])).to eq("on")
155
155
  @brewer.hlt_to("mash")
156
- expect(@brewer.relay_status($settings['spargeToMashRelay'])).to eq("off")
156
+ expect(@brewer.relay_status($settings['hltToMash'])).to eq("off")
157
157
  end
158
158
 
159
159
  context "when the location is not valid" do
@@ -7,4 +7,5 @@ SimpleCov.start
7
7
 
8
8
  require_relative "../lib/brewer"
9
9
 
10
+ include Helpers
10
11
  include Brewer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brewer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.91
4
+ version: 0.0.93
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Sweeney