trackman 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
- pkg/*
4
+ pkg/*
5
+ *.orig
data/Gemfile.lock CHANGED
@@ -12,6 +12,7 @@ GEM
12
12
  remote: http://rubygems.org/
13
13
  specs:
14
14
  addressable (2.2.8)
15
+ blockenspiel (0.4.5)
15
16
  diff-lcs (1.1.3)
16
17
  excon (0.14.1)
17
18
  heroku (2.28.2)
@@ -48,11 +49,15 @@ GEM
48
49
  rack (~> 1.0)
49
50
  tilt (~> 1.1, != 1.3.0)
50
51
  tilt (1.3.3)
52
+ versionomy (0.4.4)
53
+ blockenspiel (>= 0.4.5)
51
54
 
52
55
  PLATFORMS
53
56
  ruby
54
57
 
55
58
  DEPENDENCIES
56
59
  rspec
60
+ rspec-mocks
57
61
  sprockets
58
62
  trackman!
63
+ versionomy
data/README.md CHANGED
@@ -36,7 +36,8 @@ This will add trackman.rake to lib/tasks/
36
36
  ```console
37
37
  rake trackman:setup
38
38
  ```
39
- Sets up your initial configuration.
39
+ This sets your initial heroku configurations and ensures that when your app is down or in maintenance your pages will be requested by heroku.
40
+ If you have maintenance or error pages setup for heroku, we will back them up in a configuration before we override them.
40
41
 
41
42
  ### Optional
42
43
  ```console
@@ -0,0 +1,86 @@
1
+ require 'versionomy'
2
+
3
+ module Trackman
4
+ class ConfigurationHandler
5
+ @@ERROR = 'ERROR_PAGE_URL'
6
+ @@MAINTENANCE = 'MAINTENANCE_PAGE_URL'
7
+ @@TRACKMAN_ERROR = 'TRACKMAN_ERROR_PAGE_URL'
8
+ @@TRACKMAN_MAINTENANCE = 'TRACKMAN_MAINTENANCE_PAGE_URL'
9
+
10
+ attr_accessor :configs, :heroku_version
11
+
12
+ def initialize(configs, heroku_version)
13
+ self.configs = configs
14
+ self.heroku_version = heroku_version
15
+ end
16
+
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
25
+ end
26
+
27
+ def add_configs
28
+ puts "overriding the required heroku configs #{@@MAINTENANCE} and #{@@ERROR}"
29
+
30
+ if configs.include?(@@TRACKMAN_ERROR) && configs.include?(@@TRACKMAN_MAINTENANCE)
31
+ trackman_configs = {}
32
+ [[@@TRACKMAN_ERROR, @@ERROR], [@@TRACKMAN_MAINTENANCE, @@MAINTENANCE]].each do |old_c, new_c|
33
+ trackman_configs[new_c] = configs[old_c]
34
+ end
35
+
36
+ add = trackman_configs.map{|k,v| "#{k}=#{v}" }.join(' ')
37
+ add_config add
38
+ else
39
+ raise SetupException, "cannot find trackman configuration, make sure trackman addon is installed"
40
+ end
41
+ end
42
+
43
+ def rename_configs
44
+ bkp = {}
45
+ [@@ERROR, @@MAINTENANCE].each do |c|
46
+ bkp[c] = configs[c] if configs.include? c
47
+ end
48
+
49
+ add = Hash[bkp.map {|k, v| [k + ".bkp", v] }].map{|k,v| "#{k}=#{v}" }.select{|c| !configs.include? c }.join(' ')
50
+
51
+ unless add.empty?
52
+ puts "backuping configs to heroku..."
53
+ add_config add
54
+ end
55
+ end
56
+
57
+ private
58
+ def is_heroku_valid
59
+ Versionomy.parse(heroku_version) >= Versionomy.parse("2.26.2")
60
+ end
61
+
62
+ def add_config add
63
+ `heroku config:add #{add}`
64
+ end
65
+
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
82
+ end
83
+
84
+ class SetupException < Exception
85
+ end
86
+ end
@@ -1,3 +1,3 @@
1
1
  module Trackman
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/trackman.rb CHANGED
@@ -4,7 +4,8 @@ require 'tasks'
4
4
 
5
5
  module Trackman
6
6
  autoload :RackMiddleware, 'trackman/rack_middleware'
7
- autoload :Assets, 'trackman/assets'
7
+ autoload :Assets, 'trackman/assets'
8
+ autoload :ConfigurationHandler, 'trackman/configuration_handler'
8
9
  end
9
10
 
10
11
  autoload :Debugger, 'trackman/debugger'
@@ -1,62 +1,17 @@
1
1
  require 'rest-client'
2
+ require 'trackman'
2
3
 
3
4
  namespace :trackman do
4
- ERROR = 'ERROR_PAGE_URL'
5
- MAINTENANCE = 'MAINTENANCE_PAGE_URL'
6
- TRACKMAN_ERROR = 'TRACKMAN_ERROR_PAGE_URL'
7
- TRACKMAN_MAINTENANCE = 'TRACKMAN_MAINTENANCE_PAGE_URL'
8
-
9
5
  desc "Syncs your assets with the server, this is what gets executed when you deploy to heroku."
10
- task :sync => :environment do
11
- require 'trackman'
6
+ task :sync => :environment do
12
7
  RestClient.log = Logger.new(STDOUT) if Debugger.debug_mode?
13
8
  Trackman::Assets::Asset.sync
14
9
  end
15
10
 
16
11
  desc "Sets up the heroku configs required by Trackman"
17
12
  task :setup do
18
- heroku_version = `heroku version`
19
- if heroku_version !~ /^[2-9]\.[2-9]/
20
- puts "your heroku version is too low, we recommend '~> 2.26' at least"
21
- else
22
- configs = `heroku config -s`
23
- rename_configs configs
24
- add_configs configs
25
- puts "done! Thank you for using Trackman!"
26
- end
13
+ configs = ConfigurationHandler.s_to_h(`heroku config -s`)
14
+ heroku_version = `heroku -v`[/[\d]*\.[\d]*.[\d]*/]
15
+ ConfigurationHandler.new(configs, heroku_version).setup
27
16
  end
28
-
29
- def rename_configs configs
30
- bkp = {}
31
-
32
- [ERROR, MAINTENANCE].each do |c|
33
- bkp[c] = extract_config_value(configs, c) if configs.include? c
34
- end
35
-
36
- add = Hash[bkp.map {|k, v| [k + ".bkp", v] }].map{|k,v| "#{k}=#{v}" }.join(' ')
37
-
38
- `heroku config:add #{add}`
39
- puts "backuping configs to heroku...\n running heroku config:add #{add}"
40
- end
41
-
42
- def add_configs configs
43
- puts "overriding the required heroku configs #{MAINTENANCE} and #{ERROR}"
44
-
45
- if configs.include?(TRACKMAN_ERROR) && configs.include?(TRACKMAN_MAINTENANCE)
46
- trackman_configs = {}
47
- [[TRACKMAN_ERROR, ERROR], [TRACKMAN_MAINTENANCE, MAINTENANCE]].each do |old_c, new_c|
48
- trackman_configs[new_c] = extract_config_value(configs, old_c)
49
- end
50
-
51
- add = trackman_configs.map{|k,v| "#{k}=#{v}" }.join(' ')
52
- `heroku config:add #{add}`
53
- puts "running heroku config:add #{add}"
54
- else
55
- puts "cannot find trackman configuration, make sure trackman addon is installed"
56
- end
57
- end
58
-
59
- def extract_config_value configs, name
60
- configs[/#{name}=.+$/][/[^=]+$/]
61
- end
62
17
  end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
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
12
+ end
13
+
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
+ }
20
+
21
+ config_handler= ConfigurationHandler.new(configs, "2.26.2")
22
+ config_handler.setup
23
+ config_hash = config_handler.configs
24
+
25
+
26
+ config_hash.should include("ERROR_PAGE_URL")
27
+ config_hash.should include("MAINTENANCE_PAGE_URL")
28
+ config_hash["ERROR_PAGE_URL"].should == "\"error_page_url\""
29
+ config_hash["MAINTENANCE_PAGE_URL"].should == "\"en_US.UTF-8\""
30
+ end
31
+
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
+ }
37
+
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")
40
+ end
41
+
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")
45
+ end
46
+
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\"",
49
+ "TRACKMAN_URL" => "\"url\"",
50
+ "TRACKMAN_ERROR_PAGE_URL" => "\"error_page_url\"",
51
+ "MAINTENANCE_PAGE_URL" => "\"en_US.UTF-8_old\"",
52
+ "SOME_CONFIG" => "\"url\"",
53
+ "ERROR_PAGE_URL" => "\"error_page_url_old\""
54
+ }
55
+ config_handler = ConfigurationHandler.new(configs, "2.26.2")
56
+ config_handler.setup
57
+ config_hash = config_handler.configs
58
+
59
+ puts config_hash
60
+
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\""
65
+ end
66
+
67
+ it "should not backup configs when they do not exist" do
68
+ configs = {"TRACKMAN_MAINTENANCE_PAGE_URL" => "\"en_US.UTF-8\"",
69
+ "TRACKMAN_URL" => "\"url\"",
70
+ "TRACKMAN_ERROR_PAGE_URL" => "\"error_page_url\"",
71
+ "SOME_CONFIG" => "\"url\""
72
+ }
73
+ config_handler= ConfigurationHandler.new(configs, "2.26.2")
74
+
75
+ config_handler.setup
76
+ config_hash = config_handler.configs
77
+
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\""
82
+ end
83
+ end
@@ -21,6 +21,10 @@ class AppCreator
21
21
  end
22
22
 
23
23
  def self.reset
24
+ RemoteAsset.all.each do |a|
25
+ a.delete
26
+ end
27
+
24
28
  @@config.each do |k,v|
25
29
  RemoteAsset.send(:class_variable_set, k, v)
26
30
  end
File without changes
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,7 @@
5
5
  #
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
7
  require 'trackman'
8
+
8
9
  RSpec.configure do |config|
9
10
  config.treat_symbols_as_metadata_keys_with_true_values = true
10
11
  config.run_all_when_everything_filtered = true
@@ -19,4 +20,5 @@ RemoteAsset = Trackman::Assets::RemoteAsset unless defined?(RemoteAsset)
19
20
 
20
21
  PathResolver = Trackman::Assets::Components::PathResolver unless defined?(PathResolver)
21
22
  Rails32PathResolver = Trackman::Assets::Components::Rails32PathResolver unless defined?(Rails32PathResolver)
22
- RailsPathResolver = Trackman::Assets::Components::RailsPathResolver unless defined?(RailsPathResolver)
23
+ RailsPathResolver = Trackman::Assets::Components::RailsPathResolver unless defined?(RailsPathResolver)
24
+ ConfigurationHandler = Trackman::ConfigurationHandler unless defined?(ConfigurationHandler)
data/trackman.gemspec CHANGED
@@ -26,4 +26,6 @@ Gem::Specification.new do |s|
26
26
 
27
27
  s.add_development_dependency "rspec"
28
28
  s.add_development_dependency "sprockets"
29
+ s.add_development_dependency "rspec-mocks"
30
+ s.add_development_dependency "versionomy"
29
31
  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.1.9
4
+ version: 0.2.0
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-06-25 00:00:00.000000000 Z
13
+ date: 2012-07-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -124,6 +124,38 @@ dependencies:
124
124
  - - ! '>='
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: rspec-mocks
129
+ requirement: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: versionomy
145
+ requirement: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ type: :development
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
127
159
  description: Trackman hosts your maintenances and app-down pages (503s) and lets you
128
160
  keep them in your current development environment so that you can focus on delivering
129
161
  and not configuring.
@@ -147,7 +179,6 @@ files:
147
179
  - lib/trackman/assets/asset.rb
148
180
  - lib/trackman/assets/components.rb
149
181
  - lib/trackman/assets/components/asset_factory.rb
150
- - lib/trackman/assets/components/asset_factory.rb.orig
151
182
  - lib/trackman/assets/components/composite_asset.rb
152
183
  - lib/trackman/assets/components/conventions.rb
153
184
  - lib/trackman/assets/components/diffable.rb
@@ -162,6 +193,7 @@ files:
162
193
  - lib/trackman/assets/errors/config_not_found_error.rb
163
194
  - lib/trackman/assets/html_asset.rb
164
195
  - lib/trackman/assets/remote_asset.rb
196
+ - lib/trackman/configuration_handler.rb
165
197
  - lib/trackman/debugger.rb
166
198
  - lib/trackman/rack_middleware.rb
167
199
  - lib/trackman/railtie.rb
@@ -172,6 +204,7 @@ files:
172
204
  - spec/asset_factory_spec.rb
173
205
  - spec/asset_spec.rb
174
206
  - spec/composite_asset_spec.rb
207
+ - spec/configuration_handler_spec.rb
175
208
  - spec/css_asset_spec.rb
176
209
  - spec/diffable_spec.rb
177
210
  - spec/fixtures/rails2311/fully-loaded/README
@@ -409,6 +442,7 @@ files:
409
442
  - spec/helpers/act_like_rails2311.rb
410
443
  - spec/helpers/act_like_rails32.rb
411
444
  - spec/helpers/app_creator.rb
445
+ - spec/helpers/config_helper.rb
412
446
  - spec/helpers/fakable_pathman_tester.rb
413
447
  - spec/html_asset_spec.rb
414
448
  - spec/paths/pathman_spec.rb
@@ -470,7 +504,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
470
504
  version: '0'
471
505
  requirements: []
472
506
  rubyforge_project:
473
- rubygems_version: 1.8.24
507
+ rubygems_version: 1.8.22
474
508
  signing_key:
475
509
  specification_version: 3
476
510
  summary: Client version of the Trackman addon on Heroku
@@ -1,54 +0,0 @@
1
- module Trackman
2
- module Assets
3
- module Components
4
- module AssetFactory
5
- def create attributes = {}
6
- path = attributes[:path]
7
-
8
- if File.extname(path) == '.html'
9
- parent = HtmlAsset
10
- elsif File.extname(path) == '.css'
11
- parent = CssAsset
12
- else
13
- parent = Asset
14
- end
15
-
16
- instance = parent.new attributes
17
- <<<<<<< HEAD
18
- instance.extend Rails32PathResolver if asset_pipeline_enabled?
19
- instance
20
- end
21
-
22
- def rails_defined?
23
- const_defined? :Rails
24
- =======
25
-
26
- if uses_rails32?
27
- instance.extend Rails32PathResolver
28
- elsif uses_rails? #fallback to rails without asset pipeline
29
- instance.extend RailsPathResolver
30
- end
31
-
32
- instance
33
- end
34
-
35
- def uses_rails?
36
- const_defined?(:Rails)
37
- end
38
-
39
- def uses_rails32?
40
- uses_rails? && ::Rails::VERSION::STRING =~ /^[3-9]\.[1-9]/
41
- >>>>>>> c8c05bfdca05b2ee989fd7040676cebe6f2f2b88
42
- end
43
-
44
- def asset_pipeline_enabled?
45
- rails_defined? &&
46
- Rails.respond_to?(:application) &&
47
- Rails.application.respond_to?(:config) &&
48
- Rails.application.config.respond_to?(:assets) &&
49
- Rails.application.config.assets.enabled
50
- end
51
- end
52
- end
53
- end
54
- end