bub_bot 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56a3e504964a815eb7f1424fd0dc0d2c7c4193f4
4
- data.tar.gz: cf11d85e4fd9a2f81728ceee6067a4a6e039e286
3
+ metadata.gz: f624985c964068cf82f1766cb94e27e0ee895ab4
4
+ data.tar.gz: 112176a7a01c8bdd9f40434ee8f37eee12e355bc
5
5
  SHA512:
6
- metadata.gz: 53d5b06e8a41488bc2bbed625f235ca8484bf6dd4c413bd7bff89f12a31aba23dcd82e2af0f7222c6244887205b2e6b5b8a4a1ed54b4ed33e845bcf92994dfeb
7
- data.tar.gz: 93a21d75d1586ec8ab08ffc4b95a116ae2f81568652b6b41566461d146ded203ba48cc02ea3654a90fdce1c26984ff77fd17580df7cef3dc2111866fb49f611e
6
+ metadata.gz: 45a161978eaae8e736497d6fa2f5d2eeea829424236d50b47d2c20533fb4644ac980f6d8f1dbb0161317389e10ed9e2bdf0661ded67b8cc4cc997de814776147
7
+ data.tar.gz: 88adca1eb0da42fc256a4989a3b347872370c962473e3f104f6d0cf541df49edea24d46c0d6f814c774762e7a03135f6a2701f18558dc559c95b96d73306bd53
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  test_config.yml
11
11
  deploy_web.sh
12
+ .env
data/bub_bot.gemspec CHANGED
@@ -34,4 +34,5 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency "rspec", "~> 3.0"
35
35
  spec.add_development_dependency "rspec-mocks", "~> 3.5"
36
36
  spec.add_development_dependency "pry-byebug"
37
+ spec.add_development_dependency "dotenv"
37
38
  end
data/lib/bub_bot.rb CHANGED
@@ -8,6 +8,7 @@ require 'active_support/core_ext'
8
8
 
9
9
  if ENV['RACK_ENV'] == 'development'
10
10
  require 'pry-byebug'
11
+ require 'dotenv/load'
11
12
  end
12
13
 
13
14
  module BubBot
@@ -17,7 +17,7 @@ class BubBot::Configuration
17
17
 
18
18
  OPTIONS = RACK_OPTIONS + BUB_BOT_OPTIONS
19
19
 
20
- attr_accessor *OPTIONS
20
+ attr_writer *OPTIONS
21
21
 
22
22
  def rack_options_hash
23
23
  RACK_OPTIONS.each_with_object({}) do |option_name, options_hash|
@@ -31,4 +31,43 @@ class BubBot::Configuration
31
31
  true
32
32
  end
33
33
 
34
+ # Each config option will, when requested (eg BubBot.configuration.bot_name), be
35
+ # run through ERB. You can provide optional additional context for the erb call.
36
+ # This is is a good way to provide variable that you want to access in the yaml.
37
+ # Eg if the bot_name is "friendly_bot_<%= phase_of_moon %>" in the yaml, you could
38
+ # call `BubBot.configuration.bot_name(phase_of_moon: 'waxing')`.
39
+ OPTIONS.each do |option|
40
+ define_method(option) do |extra_context = {}|
41
+ option_data = instance_variable_get("@#{option}".to_sym)
42
+ interpolate(option_data, extra_context)
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def interpolate(data, extra_context)
49
+ if data.is_a?(String)
50
+ ERB.new(data).result(get_binding(extra_context))
51
+ elsif data.is_a?(Array)
52
+ data.map { |element| interpolate(element, extra_context) }
53
+ elsif data.is_a?(Hash)
54
+ data.each_with_object({}) do |(key, value), new_hash|
55
+ new_hash[key] = interpolate(value, extra_context)
56
+ end
57
+ else
58
+ data
59
+ end
60
+ end
61
+
62
+ # Gets a binding object with the given variables defined in it. You'd *think*
63
+ # there'd be a simpler way. Well, ok, there is, but there's no simpler way that
64
+ # doesn't *also* polute the binding with variables from the outer scope.
65
+ def get_binding(variables)
66
+ obj = Class.new {
67
+ attr_accessor *variables.keys
68
+ def get_binding(); binding end
69
+ }.new
70
+ variables.each { |name, value| obj.public_send(:"#{name}=", value) }
71
+ obj.get_binding
72
+ end
34
73
  end
@@ -10,7 +10,7 @@ class BubBot::DeployManager
10
10
 
11
11
  begin
12
12
  DeployState[server, target_name].set(true)
13
- target_config = target(target_name)
13
+ target_config = target(target_name, server)
14
14
 
15
15
  unless deploy_config = target_config['deploy']
16
16
  raise "Missing deploy config for #{target_name}"
@@ -24,7 +24,6 @@ class BubBot::DeployManager
24
24
  # TODO: maybe handle multiple deploys for each target? Right now the
25
25
  # workaround to do that is to just have a script-type deploy that does that.
26
26
  if deploy_git_remote = deploy_config['git']
27
- deploy_git_remote = ERB.new(deploy_git_remote).result(get_binding(locals))
28
27
  repo(target_name, server).push(branch, deploy_git_remote)
29
28
  elsif deploy_script = deploy_config['script']
30
29
  puts "xdeploying web script #{deploy_script}"
@@ -42,11 +41,8 @@ class BubBot::DeployManager
42
41
  elsif deploy_url = deploy_config['http']
43
42
  raise RespondableError.new('Sorry, deploys by http request are not supported yet')
44
43
  end
45
-
46
- DeployState[server, target_name].set(false)
47
- rescue
44
+ ensure
48
45
  DeployState[server, target_name].set(false)
49
- raise
50
46
  end
51
47
  end
52
48
 
@@ -62,17 +58,17 @@ class BubBot::DeployManager
62
58
 
63
59
  def repo(target_name, server)
64
60
  @repos ||= {}
65
- target = target(target_name)
61
+ target = target(target_name, server)
66
62
  @repos[target_name + '__' + server] ||= Repo.new(target_name, target['git'], server)
67
63
  end
68
64
 
69
65
  # Returns a hash of config data for the target with this name
70
- def target(target_name)
71
- targets.find { |name, _| name == target_name }.last
66
+ def target(target_name, server = nil)
67
+ targets(server).find { |name, _| name == target_name }.last
72
68
  end
73
69
 
74
- def targets
75
- BubBot.configuration.deploy_targets
70
+ def targets(server = nil)
71
+ BubBot.configuration.deploy_targets(server: server)
76
72
  end
77
73
 
78
74
  # Gets a binding object with the given variables defined in it. You'd *think*
@@ -1,3 +1,3 @@
1
1
  module BubBot
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bub_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Kuchta
@@ -192,6 +192,20 @@ dependencies:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: dotenv
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
195
209
  description:
196
210
  email:
197
211
  - kevin@kevinkuchta.com