brewer 0.0.74 → 0.0.76
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +71 -0
- data/bin/brewer +2 -1
- data/lib/adaptibrew.rb +11 -14
- data/lib/brewer.rb +6 -15
- data/lib/communicator.rb +8 -7
- data/lib/helpers.rb +8 -0
- data/lib/procedures.rb +8 -48
- data/lib/recipe.rb +58 -0
- data/lib/settings.rb +125 -35
- data/spec/brewer_spec.rb +2 -15
- data/spec/helpers_spec.rb +12 -0
- data/spec/settings_spec.rb +136 -12
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e8c3bb14cd07613d6767c44df01faad56704d42
|
4
|
+
data.tar.gz: 65dd5797401e39bba59a9f34efd563e8a2020502
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10c1faa2145a960e0390a8c76e4d6842d9b5334b49814dffbc1cc740acf1b777e0c177e74c0a94c784a63561c892536d868c96d1bfb0629b7e30657baa07237d
|
7
|
+
data.tar.gz: bb3d4ed2ffcc180917b7c39380934b511281aa7103d282bce09011c56e59ad1604cea6f4125bd9e261fa554ac6f2eb096bf35c6429253e45c42d11b0cd678dbf
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
brewer (0.0.74)
|
5
|
+
git (~> 1.3, >= 1.3.0)
|
6
|
+
net-ping (~> 1.7)
|
7
|
+
rainbow
|
8
|
+
require_all
|
9
|
+
ripl (~> 0.7.0)
|
10
|
+
slack-notifier
|
11
|
+
terminal-table
|
12
|
+
wannabe_bool
|
13
|
+
|
14
|
+
GEM
|
15
|
+
remote: https://rubygems.org/
|
16
|
+
specs:
|
17
|
+
addressable (2.5.1)
|
18
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
19
|
+
bond (0.5.1)
|
20
|
+
diff-lcs (1.3)
|
21
|
+
docile (1.1.5)
|
22
|
+
git (1.3.0)
|
23
|
+
json (2.0.4)
|
24
|
+
launchy (2.4.3)
|
25
|
+
addressable (~> 2.3)
|
26
|
+
net-ping (1.7.8)
|
27
|
+
public_suffix (2.0.5)
|
28
|
+
rainbow (2.2.1)
|
29
|
+
rake (12.0.0)
|
30
|
+
rdoc (5.1.0)
|
31
|
+
require_all (1.4.0)
|
32
|
+
ripl (0.7.1)
|
33
|
+
bond (~> 0.5.1)
|
34
|
+
rspec (3.5.0)
|
35
|
+
rspec-core (~> 3.5.0)
|
36
|
+
rspec-expectations (~> 3.5.0)
|
37
|
+
rspec-mocks (~> 3.5.0)
|
38
|
+
rspec-core (3.5.4)
|
39
|
+
rspec-support (~> 3.5.0)
|
40
|
+
rspec-expectations (3.5.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.5.0)
|
43
|
+
rspec-mocks (3.5.0)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.5.0)
|
46
|
+
rspec-support (3.5.0)
|
47
|
+
simplecov (0.13.0)
|
48
|
+
docile (~> 1.1.0)
|
49
|
+
json (>= 1.8, < 3)
|
50
|
+
simplecov-html (~> 0.10.0)
|
51
|
+
simplecov-html (0.10.0)
|
52
|
+
slack-notifier (2.1.0)
|
53
|
+
terminal-table (1.7.3)
|
54
|
+
unicode-display_width (~> 1.1.1)
|
55
|
+
unicode-display_width (1.1.3)
|
56
|
+
wannabe_bool (0.6.0)
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
brewer!
|
63
|
+
launchy (~> 2.4, >= 2.4.0)
|
64
|
+
rake (~> 12.0, >= 12.0.0)
|
65
|
+
rdoc (~> 5.1, >= 5.1.0)
|
66
|
+
rspec (~> 3.5.0, >= 3.5.0)
|
67
|
+
simplecov (~> 0.13.0)
|
68
|
+
simplecov-html (~> 0.10.0)
|
69
|
+
|
70
|
+
BUNDLED WITH
|
71
|
+
1.14.6
|
data/bin/brewer
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require_relative "../lib/autoload"
|
3
3
|
|
4
|
+
adaptibrew = Adaptibrew.new.refresh
|
4
5
|
com = Communicator.new
|
5
6
|
brewer = Brewer.new
|
6
|
-
|
7
|
+
settings = Settings.new
|
7
8
|
procedures = Procedures.new
|
8
9
|
|
9
10
|
puts "🍺 have fun 🍺"
|
data/lib/adaptibrew.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
require_relative "autoload"
|
2
2
|
|
3
|
+
include Helpers
|
4
|
+
|
3
5
|
# This is the 'manager' for the adaptibrew repo. It handles cloning and such.
|
4
6
|
class Adaptibrew
|
5
7
|
|
6
|
-
attr_accessor :install_dir
|
7
|
-
|
8
8
|
def initialize
|
9
|
-
@install_dir = Dir.home + "/.brewer/"
|
10
9
|
refresh
|
11
10
|
end
|
12
11
|
|
13
|
-
#
|
12
|
+
# This will clone adaptibrew into ~/.brewer/adaptibrew/
|
14
13
|
def clone
|
15
14
|
raise "🛑 Cannot clone, no network connection" unless network?
|
16
|
-
if !Dir.exists?(
|
17
|
-
Git.clone('https://github.com/llamicron/adaptibrew.git', 'adaptibrew', :path =>
|
15
|
+
if !Dir.exists?(adaptibrew_dir)
|
16
|
+
Git.clone('https://github.com/llamicron/adaptibrew.git', 'adaptibrew', :path => brewer_dir)
|
18
17
|
end
|
19
18
|
self
|
20
19
|
end
|
@@ -24,15 +23,16 @@ class Adaptibrew
|
|
24
23
|
# :nocov: since this requires network to be off
|
25
24
|
if !network?
|
26
25
|
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? "
|
27
|
-
|
28
|
-
exit
|
29
|
-
end
|
26
|
+
confirm ? nil : abort
|
30
27
|
end
|
31
28
|
# :nocov:
|
32
|
-
FileUtils.rm_rf(
|
29
|
+
FileUtils.rm_rf(adaptibrew_dir)
|
33
30
|
self
|
34
31
|
end
|
35
32
|
|
33
|
+
# This is a good catch-all method
|
34
|
+
# If it's not there, it will clone.
|
35
|
+
# If it is, it will delete and re-clone
|
36
36
|
def refresh
|
37
37
|
raise "🛑 Cannot refresh, no network connection" unless network?
|
38
38
|
clear
|
@@ -41,10 +41,7 @@ class Adaptibrew
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def present?
|
44
|
-
|
45
|
-
return true
|
46
|
-
end
|
47
|
-
false
|
44
|
+
return Dir.exists?(adaptibrew_dir) ? true : false
|
48
45
|
end
|
49
46
|
|
50
47
|
end
|
data/lib/brewer.rb
CHANGED
@@ -3,12 +3,11 @@ require_relative "autoload"
|
|
3
3
|
class Brewer
|
4
4
|
|
5
5
|
attr_reader :base_path
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :temps
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
@base_path = Dir.home + '/.brewer'
|
10
|
-
|
11
|
-
@out = []
|
10
|
+
Settings.new
|
12
11
|
@temps = {}
|
13
12
|
end
|
14
13
|
|
@@ -27,12 +26,7 @@ class Brewer
|
|
27
26
|
# you may see `echo` quite a bit. This will almost always be directly after calling a script
|
28
27
|
# It will be set to the output of the last script. I can't just return the output because i need to return self
|
29
28
|
def script(script, params=nil)
|
30
|
-
|
31
|
-
@out.first
|
32
|
-
end
|
33
|
-
|
34
|
-
def clear
|
35
|
-
@out = []
|
29
|
+
`python #{@base_path}/adaptibrew/#{script}.py #{params}`.chomp
|
36
30
|
end
|
37
31
|
|
38
32
|
# Adaptibrew methods ----------------------------------------------
|
@@ -48,7 +42,6 @@ class Brewer
|
|
48
42
|
else
|
49
43
|
if pid['pid_running'].to_b
|
50
44
|
pid(0)
|
51
|
-
echo
|
52
45
|
end
|
53
46
|
return script("set_pump_off")
|
54
47
|
end
|
@@ -95,15 +88,13 @@ class Brewer
|
|
95
88
|
end
|
96
89
|
|
97
90
|
def all_relays_status
|
98
|
-
script("get_relay_status_test")
|
99
|
-
puts
|
100
|
-
@out.shift
|
91
|
+
output = script("get_relay_status_test")
|
92
|
+
puts output.split('\n')
|
101
93
|
true
|
102
94
|
end
|
103
95
|
|
104
96
|
def relay_status(relay)
|
105
|
-
script("get_relay_status", "#{relay}")
|
106
|
-
if @out.include? "on"
|
97
|
+
if script("get_relay_status", "#{relay}").include? "on"
|
107
98
|
return "on"
|
108
99
|
else
|
109
100
|
return "off"
|
data/lib/communicator.rb
CHANGED
@@ -5,19 +5,20 @@ class Communicator
|
|
5
5
|
attr_accessor :slack, :brewer
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@
|
8
|
+
@settings = Settings.new
|
9
9
|
@brewer = Brewer.new
|
10
|
+
@slack = configure_slack
|
10
11
|
end
|
11
12
|
|
12
13
|
def configure_slack
|
13
|
-
|
14
|
-
|
15
|
-
store = YAML::Store.new $settings['settings_cache']
|
16
|
-
print "Enter your Slack webhook url: "
|
14
|
+
unless @settings.settings['webhook_url']
|
15
|
+
print "Slack Webhook URL: "
|
17
16
|
webhook_url = gets.chomp
|
18
|
-
|
17
|
+
@settings.add({
|
18
|
+
'webhook_url' => webhook_url
|
19
|
+
})
|
19
20
|
end
|
20
|
-
return Slack::Notifier.new
|
21
|
+
return Slack::Notifier.new @settings.settings['webhook_url']
|
21
22
|
end
|
22
23
|
|
23
24
|
def ping(message="ping at #{Time.now}")
|
data/lib/helpers.rb
CHANGED
data/lib/procedures.rb
CHANGED
@@ -9,49 +9,11 @@ class Procedures
|
|
9
9
|
def initialize
|
10
10
|
@brewer = Brewer.new
|
11
11
|
@com = Communicator.new
|
12
|
-
@recipe =
|
13
|
-
end
|
14
|
-
|
15
|
-
def get_recipe_vars
|
16
|
-
puts "Variables for heating strike water ---"
|
17
|
-
get_strike_temp
|
18
|
-
|
19
|
-
puts "Variables for mash ---"
|
20
|
-
print "Enter mash temperature: "
|
21
|
-
@recipe['mash_temp'] = gets.chomp.to_f
|
22
|
-
print "Enter mash time in minutes: "
|
23
|
-
@recipe['mash_time'] = to_seconds(gets.chomp.to_f)
|
24
|
-
|
25
|
-
puts "Variables for mashout ---"
|
26
|
-
print "Enter mashout temp: "
|
27
|
-
@recipe['mashout_temp'] = gets.chomp.to_f
|
28
|
-
end
|
29
|
-
|
30
|
-
def get_strike_temp
|
31
|
-
print "Input amount of water in quarts: "
|
32
|
-
@recipe['water'] = gets.chomp.to_f
|
33
|
-
|
34
|
-
print "Input amount of grain in lbs: "
|
35
|
-
@recipe['grain'] = gets.chomp.to_f
|
36
|
-
|
37
|
-
print "Input current grain temp (#{pv.to_s} F): "
|
38
|
-
@recipe['grain_temp'] = gets.chomp.to_f
|
39
|
-
if @recipe['grain_temp'] == ""
|
40
|
-
@recipe['grain_temp'] = pv
|
41
|
-
end
|
42
|
-
|
43
|
-
print "Input desired mash temp (150 F): "
|
44
|
-
@recipe['desired_mash_temp'] = gets.chomp
|
45
|
-
if @recipe['desired_mash_temp'] == ""
|
46
|
-
@recipe['desired_mash_temp'] = 150
|
47
|
-
end
|
48
|
-
@recipe['desired_mash_temp']
|
49
|
-
|
50
|
-
@recipe['strike_water_temp'] = script('get_strike_temp', "#{water} #{grain} #{grain_temp} #{@recipe['desired_mash_temp']}").to_f
|
12
|
+
@recipe = Recipe.new(@brewer)
|
51
13
|
end
|
52
14
|
|
53
15
|
def master
|
54
|
-
get_recipe_vars
|
16
|
+
@recipe.get_recipe_vars
|
55
17
|
boot
|
56
18
|
heat_strike_water
|
57
19
|
dough_in
|
@@ -71,9 +33,7 @@ class Procedures
|
|
71
33
|
@brewer.all_relays_status
|
72
34
|
puts @brewer.pid
|
73
35
|
|
74
|
-
@brewer.clear
|
75
36
|
puts Rainbow("Boot finished!").green
|
76
|
-
@brewer.out.unshift("successful boot at #{Time.now}")
|
77
37
|
@com.ping("🍺 boot finished 🍺")
|
78
38
|
true
|
79
39
|
end
|
@@ -120,13 +80,13 @@ class Procedures
|
|
120
80
|
|
121
81
|
# calculate strike temp & set PID to strike temp
|
122
82
|
# this sets PID SV to calculated strike temp automagically
|
123
|
-
@brewer.sv(@recipe
|
83
|
+
@brewer.sv(@recipe.strike_water_temp)
|
124
84
|
puts "SV has been set to calculated strike water temp"
|
125
85
|
# turn on RIMS heater
|
126
86
|
@brewer.pid(1)
|
127
87
|
|
128
88
|
# measure current strike water temp and save
|
129
|
-
@recipe
|
89
|
+
@recipe.starting_strike_temp = @brewer.pv
|
130
90
|
puts "current strike water temp is #{@brewer.pv}. Saved."
|
131
91
|
puts "Heating to #{@brewer.sv}"
|
132
92
|
|
@@ -157,7 +117,7 @@ class Procedures
|
|
157
117
|
end
|
158
118
|
|
159
119
|
def mash
|
160
|
-
@brewer.sv(@recipe
|
120
|
+
@brewer.sv(@recipe.mash_temp)
|
161
121
|
|
162
122
|
puts Rainbow("mash stated. This will take a while.").green
|
163
123
|
@com.ping("Mash started. This will take a while.")
|
@@ -168,8 +128,8 @@ class Procedures
|
|
168
128
|
@brewer.pid(1)
|
169
129
|
|
170
130
|
@brewer.watch
|
171
|
-
@com.ping("Mash temp (#{@brewer.pv} F) reached. Starting timer for #{@recipe
|
172
|
-
@brewer.wait(@recipe
|
131
|
+
@com.ping("Mash temp (#{@brewer.pv} F) reached. Starting timer for #{@recipe.mash_time} minutes.")
|
132
|
+
@brewer.wait(@recipe.mash_time)
|
173
133
|
@com.ping("🍺 Mash complete 🍺. Check for starch conversion.")
|
174
134
|
puts Rainbow("Mash complete").green
|
175
135
|
puts "Check for starch conversion"
|
@@ -178,7 +138,7 @@ class Procedures
|
|
178
138
|
def mashout
|
179
139
|
@com.ping("Start heating sparge water")
|
180
140
|
|
181
|
-
@brewer.sv(@recipe
|
141
|
+
@brewer.sv(@recipe.mashout_temp)
|
182
142
|
|
183
143
|
@brewer.pump(1)
|
184
144
|
@brewer.pid(1)
|
data/lib/recipe.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative "autoload"
|
2
|
+
|
3
|
+
include Helpers
|
4
|
+
|
5
|
+
class Recipe
|
6
|
+
|
7
|
+
attr_accessor :mash_temp, :mash_time, :mashout_temp, :water, :grain, :grain_temp, :desired_mash_temp, :strike_water_temp, :starting_strike_temp
|
8
|
+
|
9
|
+
def initialize(brewer)
|
10
|
+
@brewer = brewer
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_recipe_vars(vars=false)
|
14
|
+
if vars
|
15
|
+
raise "Vars must be a hash" unless vars.is_a? Hash
|
16
|
+
vars.each do |recipe_key, value|
|
17
|
+
instance_variable_set("@" + recipe_key, value)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
puts "Variables for heating strike water"
|
22
|
+
get_strike_temp
|
23
|
+
|
24
|
+
puts "Variables for mash ---"
|
25
|
+
print "Enter mash temperature: "
|
26
|
+
@mash_temp = gets.chomp.to_f
|
27
|
+
print "Enter mash time in minutes: "
|
28
|
+
@mash_time = to_seconds(gets.chomp.to_f)
|
29
|
+
|
30
|
+
puts "Variables for mashout ---"
|
31
|
+
print "Enter mashout temp: "
|
32
|
+
@mashout_temp = gets.chomp.to_f
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_strike_temp
|
36
|
+
print "Input amount of water in quarts: "
|
37
|
+
@water = gets.chomp.to_f
|
38
|
+
|
39
|
+
print "Input amount of grain in lbs: "
|
40
|
+
@grain = gets.chomp.to_f
|
41
|
+
|
42
|
+
print "Input current grain temp (#{@brewer.pv.to_s} F): "
|
43
|
+
@grain_temp = gets.chomp.to_f
|
44
|
+
if @grain_temp == ""
|
45
|
+
@grain_temp = @brewer.pv
|
46
|
+
end
|
47
|
+
|
48
|
+
print "Input desired mash temp (150 F): "
|
49
|
+
@desired_mash_temp = gets.chomp
|
50
|
+
if @desired_mash_temp == ""
|
51
|
+
@desired_mash_temp = 150
|
52
|
+
end
|
53
|
+
@desired_mash_temp
|
54
|
+
|
55
|
+
@strike_water_temp = script('get_strike_temp', "#{@water} #{@grain} #{@grain_temp} #{@desired_mash_temp}").to_f
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/lib/settings.rb
CHANGED
@@ -1,49 +1,139 @@
|
|
1
1
|
require_relative "autoload"
|
2
2
|
|
3
|
-
|
3
|
+
include Helpers
|
4
4
|
|
5
|
-
|
6
|
-
# This might not make sense, its for tests
|
7
|
-
def get_repo_for_settings(adaptibrew)
|
8
|
-
adaptibrew.clone
|
9
|
-
end
|
10
|
-
if !adaptibrew.present?
|
11
|
-
get_repo_for_settings(adaptibrew)
|
12
|
-
end
|
13
|
-
# End nonsense
|
5
|
+
class Settings
|
14
6
|
|
15
|
-
|
16
|
-
|
7
|
+
attr_accessor :settings
|
8
|
+
attr_reader :cache_file, :source
|
17
9
|
|
18
|
-
|
19
|
-
File.open($settings['settings_cache'], 'w')
|
20
|
-
end
|
10
|
+
def initialize(testing=false)
|
21
11
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
12
|
+
@source = adaptibrew_dir('settings.py')
|
13
|
+
@cache_file = brewer_dir('settings.yml')
|
14
|
+
|
15
|
+
@settings = Hash.new
|
27
16
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
17
|
+
if !testing
|
18
|
+
Adaptibrew.new.clone
|
19
|
+
|
20
|
+
unless cache?
|
21
|
+
parse_and_cache
|
22
|
+
else
|
23
|
+
load_cached_settings
|
24
|
+
end
|
25
|
+
|
26
|
+
load_global
|
32
27
|
end
|
33
|
-
parse_setting_from_line(line)
|
34
28
|
end
|
35
29
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
30
|
+
# This will create the cache and populate
|
31
|
+
# it with settings from settings.py
|
32
|
+
def parse_and_cache
|
33
|
+
parse
|
34
|
+
cache
|
35
|
+
end
|
36
|
+
|
37
|
+
# Loads cached settings
|
38
|
+
# If no cached settings, it returns false
|
39
|
+
def load_cached_settings
|
40
|
+
if cache?
|
41
|
+
@settings = YAML.load(File.open(@cache_file))
|
42
|
+
return true
|
40
43
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
47
|
+
# Checks if there are settings in the cache
|
48
|
+
def cache?
|
49
|
+
if File.exists?(@cache_file) and File.readlines(@cache_file).grep(/DEBUG/).size > 0
|
50
|
+
return true
|
51
|
+
end
|
52
|
+
false
|
53
|
+
end
|
54
|
+
|
55
|
+
# Parse the settings from the source file into @settings
|
56
|
+
def parse
|
57
|
+
File.open(@source, 'r') do |file|
|
58
|
+
file.each_line do |line|
|
59
|
+
if line.include? "=" and line[0] != "#"
|
60
|
+
key, value = line.match(/(.+)=(.+)/).captures
|
61
|
+
@settings[key.strip.chomp] = value.strip.chomp
|
62
|
+
end
|
63
|
+
end
|
64
|
+
type_cast
|
65
|
+
return true
|
66
|
+
end
|
67
|
+
false
|
68
|
+
end
|
69
|
+
|
70
|
+
# Creates the cache if there isn't one already
|
71
|
+
def create_cache
|
72
|
+
unless File.exists?(@cache_file)
|
73
|
+
File.open(@cache_file, 'w')
|
46
74
|
end
|
47
|
-
|
75
|
+
true
|
48
76
|
end
|
77
|
+
|
78
|
+
# This will add a new element to the @settings hash
|
79
|
+
# AND re-cache the settings
|
80
|
+
def add(setting)
|
81
|
+
raise "Setting needs to be a hash" unless setting.is_a? Hash
|
82
|
+
setting.each do |key, value|
|
83
|
+
@settings[key] = value
|
84
|
+
end
|
85
|
+
cache
|
86
|
+
end
|
87
|
+
|
88
|
+
# Stores the currents @settings in settings.yml
|
89
|
+
def cache
|
90
|
+
create_cache
|
91
|
+
store = YAML::Store.new @cache_file
|
92
|
+
store.transaction {
|
93
|
+
@settings.each do |k, v|
|
94
|
+
store[k] = v
|
95
|
+
end
|
96
|
+
}
|
97
|
+
true
|
98
|
+
end
|
99
|
+
|
100
|
+
# This deletes the cache file
|
101
|
+
def clear_cache
|
102
|
+
if File.exists?(@cache_file)
|
103
|
+
FileUtils.rm_f @cache_file
|
104
|
+
end
|
105
|
+
true
|
106
|
+
end
|
107
|
+
|
108
|
+
# This is so that the settings are easier to use in my code
|
109
|
+
# and for backwards compatability purposes
|
110
|
+
def load_global
|
111
|
+
parse_and_cache
|
112
|
+
$settings = @settings
|
113
|
+
end
|
114
|
+
|
115
|
+
def change(values)
|
116
|
+
raise "Values to change must be a hash" unless values.is_a? Hash
|
117
|
+
values.each do |k, v|
|
118
|
+
@settings[k] = v
|
119
|
+
end
|
120
|
+
return true
|
121
|
+
end
|
122
|
+
|
123
|
+
# This method is r/badcode, i know
|
124
|
+
def type_cast
|
125
|
+
# Super janky
|
126
|
+
change({
|
127
|
+
'rimsaddressint' => @settings['rimsaddressint'].to_i,
|
128
|
+
'switchaddressint' => @settings['switchaddressint'].to_i,
|
129
|
+
'baudrate' => @settings['baudrate'].to_i,
|
130
|
+
'timeout' => @settings['timeout'].to_i,
|
131
|
+
'spargeToMashRelay' => @settings['spargeToMashRelay'].to_i,
|
132
|
+
'spargeRelay' => @settings['spargeRelay'].to_i,
|
133
|
+
'rimsToMashRelay' => @settings['rimsToMashRelay'].to_i,
|
134
|
+
'pumpRelay' => @settings['pumpRelay'].to_i,
|
135
|
+
'DEBUG' => @settings['DEBUG'].to_b,
|
136
|
+
})
|
137
|
+
end
|
138
|
+
|
49
139
|
end
|
data/spec/brewer_spec.rb
CHANGED
@@ -24,9 +24,9 @@ describe Brewer do
|
|
24
24
|
it "can wait for a number of seconds" do
|
25
25
|
# not using let(:current_time) etc. because
|
26
26
|
# the var is created upon the first calling, which is in the expect()
|
27
|
-
current_time = Time.now.
|
27
|
+
current_time = Time.now.to_i
|
28
28
|
@brewer.wait(1)
|
29
|
-
expect(current_time + 1).to eq(Time.now.
|
29
|
+
expect(current_time + 1).to eq(Time.now.to_i)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -36,17 +36,4 @@ describe Brewer do
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
describe ".clear" do
|
40
|
-
context "when there is output" do
|
41
|
-
let(:brewer) { Brewer.new }
|
42
|
-
before { brewer.script('python_tester') }
|
43
|
-
specify { expect(brewer.out.first).to eq("it worked") }
|
44
|
-
|
45
|
-
it "can clear the output" do
|
46
|
-
@brewer.clear
|
47
|
-
expect(@brewer.out).to be_empty
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
39
|
end
|
data/spec/helpers_spec.rb
CHANGED
@@ -19,4 +19,16 @@ describe "Helpers" do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
describe ".brewer_dir" do
|
23
|
+
it "returns the .brewer directory" do
|
24
|
+
expect(brewer_dir).to eq(Dir.home + "/.brewer/")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".adaptibrew_dir" do
|
29
|
+
it "returns the .adaptibrew directory" do
|
30
|
+
expect(adaptibrew_dir).to eq(Dir.home + "/.brewer/adaptibrew/")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
22
34
|
end
|
data/spec/settings_spec.rb
CHANGED
@@ -4,27 +4,151 @@ require_relative 'spec_helper'
|
|
4
4
|
describe "Settings" do
|
5
5
|
|
6
6
|
before :all do
|
7
|
-
@adaptibrew = Adaptibrew.new
|
7
|
+
@adaptibrew = Adaptibrew.new.clone
|
8
|
+
@settings = Settings.new(true)
|
8
9
|
end
|
9
10
|
|
10
|
-
describe "
|
11
|
-
|
12
|
-
|
11
|
+
describe ".load_cached_settings" do
|
12
|
+
context "when there are cached settings" do
|
13
|
+
before {
|
14
|
+
@settings.parse_and_cache
|
15
|
+
@settings.settings = {}
|
16
|
+
}
|
17
|
+
|
18
|
+
specify { expect(@settings.cache?).to be true }
|
19
|
+
it "loads the cached settings" do
|
20
|
+
@settings.load_cached_settings
|
21
|
+
expect(@settings.settings).not_to be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when there is no settings cache" do
|
26
|
+
before { @settings.clear_cache }
|
27
|
+
|
28
|
+
specify { expect(@settings.cache?).to be false }
|
29
|
+
it "returns false" do
|
30
|
+
expect(@settings.load_cached_settings).to be false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".cache?" do
|
36
|
+
context "when the cache exists" do
|
37
|
+
before {
|
38
|
+
@settings.parse_and_cache
|
39
|
+
}
|
40
|
+
it "returns true" do
|
41
|
+
expect(@settings.cache?).to be true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when the cache does not exist" do
|
46
|
+
before { @settings.clear_cache }
|
47
|
+
|
48
|
+
it "returns false" do
|
49
|
+
expect(@settings.cache?).to be false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe ".parse" do
|
55
|
+
before { @settings.settings = Hash.new }
|
56
|
+
|
57
|
+
it "parses settings from settings.py into @settings" do
|
58
|
+
@settings.parse
|
59
|
+
expect(@settings.settings).not_to be_empty
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe ".create_cache" do
|
64
|
+
context "when the cache exists" do
|
65
|
+
before { @settings.parse_and_cache }
|
66
|
+
|
67
|
+
specify { expect(@settings.cache?).to be true }
|
68
|
+
it "returns true" do
|
69
|
+
expect(@settings.create_cache).to be true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when the cache does not exist" do
|
74
|
+
before { @settings.clear_cache }
|
75
|
+
|
76
|
+
specify { expect(@settings.cache?).to be false }
|
77
|
+
it "creates the cache and returns true" do
|
78
|
+
expect(@settings.create_cache).to be true
|
79
|
+
expect(File.exists?(@settings.cache_file)).to be true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe ".add" do
|
85
|
+
before { @settings = Settings.new }
|
86
|
+
specify { expect(@settings.settings['test_key']).to be nil }
|
87
|
+
it "adds a new setting to the cache" do
|
88
|
+
@settings.add({'test_key' => 'test_value'})
|
89
|
+
expect(@settings.settings['test_key']).to eq('test_value')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe ".cache" do
|
94
|
+
before { @settings.clear_cache }
|
95
|
+
|
96
|
+
specify { expect(@settings.cache?).to be false }
|
97
|
+
it "writes @settings to the cache file" do
|
98
|
+
@settings.parse
|
99
|
+
@settings.cache
|
100
|
+
expect(@settings.cache?).to be true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe ".clear_cache" do
|
105
|
+
before { @settings.parse_and_cache}
|
106
|
+
|
107
|
+
specify { expect(@settings.cache?).to be true }
|
108
|
+
it "deletes the cache file" do
|
109
|
+
@settings.clear_cache
|
110
|
+
expect(File.exists?(@settings.cache_file)).to be false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe ".load_global" do
|
115
|
+
it "creates a global settings variable" do
|
116
|
+
@settings.load_global
|
13
117
|
expect($settings).not_to be_empty
|
14
118
|
end
|
15
119
|
end
|
16
120
|
|
17
|
-
describe "
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
121
|
+
describe ".change" do
|
122
|
+
before { @settings.parse_and_cache }
|
123
|
+
|
124
|
+
specify { expect(@settings.settings['DEBUG'].to_b).to be false}
|
125
|
+
|
126
|
+
context "when the setting already exists" do
|
127
|
+
it "changes the value of a setting" do
|
128
|
+
@settings.change({"DEBUG" => true})
|
129
|
+
expect(@settings.settings['DEBUG']).to be true
|
130
|
+
end
|
131
|
+
end
|
22
132
|
|
23
|
-
|
24
|
-
|
25
|
-
expect(@
|
133
|
+
context "when the setting does not exist" do
|
134
|
+
it "creates the setting" do
|
135
|
+
expect(@settings.settings['doesNotExist']).to be nil
|
136
|
+
@settings.change({"doesNotExist" => true})
|
137
|
+
expect(@settings.settings['doesNotExist']).to be true
|
26
138
|
end
|
27
139
|
end
|
28
140
|
end
|
29
141
|
|
142
|
+
describe ".type_cast" do
|
143
|
+
before { @settings.parse }
|
144
|
+
|
145
|
+
specify { expect(@settings.settings['pumpRelay']).to be_an_instance_of String }
|
146
|
+
specify { expect(@settings.settings['DEBUG']).to eq("False") }
|
147
|
+
it "casts values to correct type" do
|
148
|
+
@settings.type_cast
|
149
|
+
expect(@settings.settings['pumpRelay']).to be_an_instance_of Fixnum
|
150
|
+
expect(@settings.settings['DEBUG']).to be false
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
30
154
|
end
|
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.
|
4
|
+
version: 0.0.76
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Sweeney
|
@@ -244,6 +244,7 @@ extensions: []
|
|
244
244
|
extra_rdoc_files: []
|
245
245
|
files:
|
246
246
|
- Gemfile
|
247
|
+
- Gemfile.lock
|
247
248
|
- README.md
|
248
249
|
- Rakefile
|
249
250
|
- bin/brewer
|
@@ -253,6 +254,7 @@ files:
|
|
253
254
|
- lib/communicator.rb
|
254
255
|
- lib/helpers.rb
|
255
256
|
- lib/procedures.rb
|
257
|
+
- lib/recipe.rb
|
256
258
|
- lib/settings.rb
|
257
259
|
- spec/adaptibrew_spec.rb
|
258
260
|
- spec/brewer_spec.rb
|