trackman 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trackman (0.2.90)
4
+ trackman (0.3.1)
5
5
  heroku (>= 2.26.2)
6
6
  json
7
7
  nokogiri
@@ -7,26 +7,30 @@ module Trackman
7
7
  @@TRACKMAN_ERROR = 'TRACKMAN_ERROR_PAGE_URL'
8
8
  @@TRACKMAN_MAINTENANCE = 'TRACKMAN_MAINTENANCE_PAGE_URL'
9
9
 
10
- attr_accessor :configs, :heroku_version
10
+ attr_accessor :configs, :heroku_version, :options
11
11
 
12
- def initialize(configs, heroku_version)
13
- self.configs = configs
14
- self.heroku_version = heroku_version
12
+ def initialize(heroku_version, options = {})
13
+ self.options = options
14
+ self.heroku_version = heroku_version
15
+ self.configs = get_configs
15
16
  end
16
17
 
17
- def setup
18
- unless is_heroku_valid
19
- raise SetupException, "your heroku version is too low, we recommend '~> 2.26' at least"
20
- else
21
- rename_configs
22
- add_configs
23
- puts "done! Thank you for using Trackman!"
24
- end
18
+ def setup
19
+ raise SetupException, "Your heroku version is too low, trackman requires '~> 2.26'." unless is_heroku_valid
20
+ rename_configs
21
+ add_configs
22
+ puts "Done!"
25
23
  end
26
24
 
27
- def add_configs
28
- puts "overriding the required heroku configs #{@@MAINTENANCE} and #{@@ERROR}"
25
+ def get_configs
26
+ result = run "heroku config -s" do |option|
27
+ "heroku config -s #{option}"
28
+ end
29
+ Trackman::ConfigurationHandler.s_to_h(result)
30
+ end
31
+
29
32
 
33
+ def add_configs
30
34
  if configs.include?(@@TRACKMAN_ERROR) && configs.include?(@@TRACKMAN_MAINTENANCE)
31
35
  trackman_configs = {}
32
36
  [[@@TRACKMAN_ERROR, @@ERROR], [@@TRACKMAN_MAINTENANCE, @@MAINTENANCE]].each do |old_c, new_c|
@@ -36,7 +40,7 @@ module Trackman
36
40
  add = trackman_configs.map{|k,v| "#{k}=#{v}" }.join(' ')
37
41
  add_config add
38
42
  else
39
- raise SetupException, "cannot find trackman configuration, make sure trackman addon is installed"
43
+ raise SetupException, "Can't find trackman configuration, make sure trackman addon is installed."
40
44
  end
41
45
  end
42
46
 
@@ -49,36 +53,45 @@ module Trackman
49
53
  add = Hash[bkp.map {|k, v| [k + "_bkp", v] }].map{|k,v| "#{k}=#{v}" }.select{|c| !configs.include? c }.join(' ')
50
54
 
51
55
  unless add.empty?
52
- puts "backing configs to heroku..."
53
56
  add_config add
54
57
  end
55
58
  end
56
59
 
60
+ def self.s_to_h configs
61
+ new_configs = {}
62
+ configs.split(" ").each do |a|
63
+ key_val = a.split("=")
64
+ new_configs[key_val[0]] = key_val[1]
65
+ end
66
+ new_configs
67
+ end
68
+
69
+ def self.h_to_s configs
70
+ out = []
71
+ configs.each do |k,v|
72
+ out << k + "=" + v
73
+ end
74
+ out.join ' '
75
+ end
76
+
57
77
  private
58
78
  def is_heroku_valid
59
79
  Versionomy.parse(heroku_version) >= Versionomy.parse("2.26.2")
60
80
  end
61
81
 
62
82
  def add_config add
63
- `heroku config:add #{add}`
83
+ run "heroku config:add #{add}" do |option|
84
+ "heroku config:add #{option} #{add}"
85
+ end
64
86
  end
65
87
 
66
- def self.s_to_h configs
67
- new_configs = {}
68
- configs.split(" ").each do |a|
69
- key_val = a.split("=")
70
- new_configs[key_val[0]] = key_val[1]
71
- end
72
- new_configs
73
- end
74
-
75
- def self.h_to_s configs
76
- out = []
77
- configs.each do |k,v|
78
- out << k + "=" + v
79
- end
80
- out.join ' '
81
- end
88
+ def run command
89
+ command = yield("--app #{options[:app]}") unless self.options[:app].nil?
90
+ puts "exec: #{command}"
91
+ result = `#{command}`
92
+ raise "An error occured running the last command." if $? != 0
93
+ result
94
+ end
82
95
  end
83
96
 
84
97
  class SetupException < Exception
@@ -1,3 +1,3 @@
1
1
  module Trackman
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -9,9 +9,9 @@ namespace :trackman do
9
9
  end
10
10
 
11
11
  desc "Sets up the heroku configs required by Trackman"
12
- task :setup do
13
- configs = Trackman::ConfigurationHandler.s_to_h(`heroku config -s`)
12
+ task :setup, :app do |t, args|
13
+
14
14
  heroku_version = Gem.loaded_specs["heroku"].version.to_s
15
- Trackman::ConfigurationHandler.new(configs, heroku_version).setup
15
+ Trackman::ConfigurationHandler.new(heroku_version, app: args[:app]).setup
16
16
  end
17
17
  end
@@ -1,83 +1,88 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ConfigurationHandler do
4
- before :each do
5
- module Trackman
6
- class ConfigurationHandler
7
- def add_config add
8
- self.configs = configs.merge(ConfigurationHandler.s_to_h(add))
9
- end
10
- end
11
- end
3
+ class TestConfigurationHandler < Trackman::ConfigurationHandler
4
+ def get_configs
5
+ {
6
+ "TRACKMAN_MAINTENANCE_PAGE_URL" => "\"en_US.UTF-8\"",
7
+ "TRACKMAN_URL" => "\"url\"",
8
+ "TRACKMAN_ERROR_PAGE_URL" => "\"error_page_url\"",
9
+ "SOME_CONFIG" => "\"url\""
10
+ }
11
+ end
12
+ attr_accessor :heroku_configs
13
+
14
+ def add_config add
15
+ self.heroku_configs = (heroku_configs || {}).merge(ConfigurationHandler.s_to_h(add))
12
16
  end
13
17
 
14
- it "should create heroku configs" do
15
- configs = {"TRACKMAN_MAINTENANCE_PAGE_URL" => "\"en_US.UTF-8\"",
16
- "TRACKMAN_URL" => "\"url\"",
17
- "TRACKMAN_ERROR_PAGE_URL" => "\"error_page_url\"",
18
- "SOME_CONFIG" => "\"url\""
19
- }
18
+ def run command
19
+ puts "exec: #{command}"
20
+ end
21
+ end
20
22
 
21
- config_handler= ConfigurationHandler.new(configs, "2.26.2")
22
- config_handler.setup
23
- config_hash = config_handler.configs
23
+ describe ConfigurationHandler do
24
+ before :each do
25
+ @config = TestConfigurationHandler.new "2.26.2"
26
+ end
24
27
 
28
+ it "creates heroku configs" do
29
+
30
+ @config.setup
31
+
32
+ config_hash = @config.heroku_configs
25
33
 
26
34
  config_hash.should include("ERROR_PAGE_URL")
27
- config_hash.should include("MAINTENANCE_PAGE_URL")
35
+ config_hash.should include("MAINTENANCE_PAGE_URL")
28
36
  config_hash["ERROR_PAGE_URL"].should == "\"error_page_url\""
29
37
  config_hash["MAINTENANCE_PAGE_URL"].should == "\"en_US.UTF-8\""
30
38
  end
31
39
 
32
- it "should raise an error if a configuration is missing" do
33
- configs = {"TRACKMANw_MAINTENANCE_PAGE_URL" => "\"en_US.UTF-8\"",
34
- "TRACKMANw_URL" => "\"url\"",
35
- "TRACKMANw_ERROR_PAGE_URL" => "\"error_page_url\""
36
- }
40
+ it "raises an error if a configuration is missing" do
41
+ @config.configs = {
42
+ "TRACKMANw_MAINTENANCE_PAGE_URL" => "\"en_US.UTF-8\"",
43
+ "TRACKMANw_URL" => "\"url\"",
44
+ "TRACKMANw_ERROR_PAGE_URL" => "\"error_page_url\""
45
+ }
37
46
 
38
- config_handler = ConfigurationHandler.new(configs, "2.26.2")
39
- lambda{ config_handler.setup }.should raise_error(Trackman::SetupException, "cannot find trackman configuration, make sure trackman addon is installed")
47
+ lambda{ @config.setup }.should raise_error(Trackman::SetupException)
40
48
  end
41
49
 
42
- it "should raise an error if trackman version is bad" do
43
- config_handler = ConfigurationHandler.new(@configs, "2.22.2")
44
- lambda{ config_handler.setup }.should raise_error(Trackman::SetupException, "your heroku version is too low, we recommend '~> 2.26' at least")
50
+ it "raises an error if trackman version is bad" do
51
+ @config.heroku_version = "2.22.2"
52
+
53
+ lambda{ @config.setup }.should raise_error(Trackman::SetupException)
45
54
  end
46
55
 
47
- it "should backup configs when they already exist and add the new ones" do
48
- configs = {"TRACKMAN_MAINTENANCE_PAGE_URL" => "\"en_US.UTF-8\"",
56
+ it "backups configs when they already exist and add the new ones" do
57
+ @config.configs = {"TRACKMAN_MAINTENANCE_PAGE_URL" => "\"en_US.UTF-8\"",
49
58
  "TRACKMAN_URL" => "\"url\"",
50
59
  "TRACKMAN_ERROR_PAGE_URL" => "\"error_page_url\"",
51
60
  "MAINTENANCE_PAGE_URL" => "\"en_US.UTF-8_old\"",
52
61
  "SOME_CONFIG" => "\"url\"",
53
62
  "ERROR_PAGE_URL" => "\"error_page_url_old\""
54
63
  }
55
- config_handler = ConfigurationHandler.new(configs, "2.26.2")
56
- config_handler.setup
57
- config_hash = config_handler.configs
64
+ @config.setup
58
65
 
59
- puts config_hash
60
66
 
61
- config_hash["ERROR_PAGE_URL_bkp"].should == "\"error_page_url_old\""
62
- config_hash["MAINTENANCE_PAGE_URL_bkp"].should == "\"en_US.UTF-8_old\""
63
- config_hash["ERROR_PAGE_URL"].should == "\"error_page_url\""
64
- config_hash["MAINTENANCE_PAGE_URL"].should == "\"en_US.UTF-8\""
67
+ @config.heroku_configs["ERROR_PAGE_URL_bkp"].should == "\"error_page_url_old\""
68
+ @config.heroku_configs["MAINTENANCE_PAGE_URL_bkp"].should == "\"en_US.UTF-8_old\""
69
+ @config.heroku_configs["ERROR_PAGE_URL"].should == "\"error_page_url\""
70
+ @config.heroku_configs["MAINTENANCE_PAGE_URL"].should == "\"en_US.UTF-8\""
65
71
  end
66
72
 
67
- it "should not backup configs when they do not exist" do
68
- configs = {"TRACKMAN_MAINTENANCE_PAGE_URL" => "\"en_US.UTF-8\"",
73
+ it "does not backup configs when they do not exist" do
74
+ @config.configs = {"TRACKMAN_MAINTENANCE_PAGE_URL" => "\"en_US.UTF-8\"",
69
75
  "TRACKMAN_URL" => "\"url\"",
70
76
  "TRACKMAN_ERROR_PAGE_URL" => "\"error_page_url\"",
71
77
  "SOME_CONFIG" => "\"url\""
72
78
  }
73
- config_handler = ConfigurationHandler.new(configs, "2.26.2")
74
-
75
- config_handler.setup
76
- config_hash = config_handler.configs
79
+
80
+ @config.setup
81
+
77
82
 
78
- config_hash.keys.should_not include("ERROR_PAGE_URL_bkp")
79
- config_hash.keys.should_not include("MAINTENANCE_PAGE_URL_bkp")
80
- config_hash["ERROR_PAGE_URL"].should == "\"error_page_url\""
81
- config_hash["MAINTENANCE_PAGE_URL"].should == "\"en_US.UTF-8\""
83
+ @config.heroku_configs.keys.should_not include("ERROR_PAGE_URL_bkp")
84
+ @config.heroku_configs.keys.should_not include("MAINTENANCE_PAGE_URL_bkp")
85
+ @config.heroku_configs["ERROR_PAGE_URL"].should == "\"error_page_url\""
86
+ @config.heroku_configs["MAINTENANCE_PAGE_URL"].should == "\"en_US.UTF-8\""
82
87
  end
83
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trackman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-22 00:00:00.000000000 Z
13
+ date: 2012-08-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client