trackman 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/trackman.rb +14 -7
- data/lib/trackman/assets.rb +4 -14
- data/lib/trackman/assets/asset.rb +3 -3
- data/lib/trackman/assets/asset_factory.rb +46 -0
- data/lib/trackman/assets/bundled_asset.rb +26 -0
- data/lib/trackman/assets/composite_asset.rb +40 -0
- data/lib/trackman/assets/css_asset.rb +1 -1
- data/lib/trackman/assets/html_asset.rb +1 -1
- data/lib/trackman/assets/persistence.rb +9 -0
- data/lib/trackman/assets/persistence/remote.rb +54 -0
- data/lib/trackman/assets/remote_asset.rb +4 -45
- data/lib/trackman/assets/remote_asset_factory.rb +11 -0
- data/lib/trackman/components.rb +9 -0
- data/lib/trackman/components/conventions.rb +21 -0
- data/lib/trackman/components/diffable.rb +28 -0
- data/lib/trackman/components/hashable.rb +27 -0
- data/lib/trackman/components/shippable.rb +29 -0
- data/lib/trackman/errors.rb +9 -0
- data/lib/trackman/errors/asset_not_found_error.rb +6 -0
- data/lib/trackman/errors/config_not_found_error.rb +6 -0
- data/lib/trackman/errors/config_setup_error.rb +7 -0
- data/lib/trackman/path.rb +9 -0
- data/lib/trackman/path/rails32_resolver.rb +35 -0
- data/lib/trackman/path/rails_resolver.rb +29 -0
- data/lib/trackman/path/resolver.rb +32 -0
- data/lib/trackman/scaffold.rb +2 -14
- data/lib/trackman/utility.rb +9 -0
- data/lib/trackman/utility/configuration.rb +98 -0
- data/lib/trackman/{core_extensions.rb → utility/core_extensions.rb} +0 -0
- data/lib/trackman/utility/debugger.rb +24 -0
- data/lib/{trackman_railtie.rb → trackman/utility/railtie.rb} +2 -1
- data/lib/trackman/version.rb +1 -1
- data/rails_generators/trackman_tasks/templates/trackman.rake +1 -1
- data/spec/asset_factory_spec.rb +3 -3
- data/spec/asset_spec.rb +1 -1
- data/spec/composite_asset_spec.rb +2 -2
- data/spec/{configuration_handler_spec.rb → configuration_spec.rb} +6 -6
- data/spec/diffable_spec.rb +2 -2
- data/spec/helpers/act_like_rails2311.rb +2 -2
- data/spec/helpers/act_like_rails32.rb +2 -2
- data/spec/helpers/app_creator.rb +12 -5
- data/spec/helpers/fakable_pathman_tester.rb +5 -5
- data/spec/paths/pathman_spec.rb +2 -2
- data/spec/paths/rails32_pathman_spec.rb +2 -2
- data/spec/{rails32_path_resolver_spec.rb → rails32_resolver_spec.rb} +3 -3
- data/spec/remote_asset_spec.rb +13 -17
- data/spec/{scaffolding_spec.rb → scaffold_spec.rb} +0 -0
- data/spec/shippable_spec.rb +2 -2
- data/spec/spec_helper.rb +6 -6
- data/spec/sync_spec.rb +1 -1
- metadata +32 -27
- data/lib/trackman/assets/components.rb +0 -13
- data/lib/trackman/assets/components/asset_factory.rb +0 -48
- data/lib/trackman/assets/components/bundled_asset.rb +0 -29
- data/lib/trackman/assets/components/composite_asset.rb +0 -42
- data/lib/trackman/assets/components/conventions.rb +0 -23
- data/lib/trackman/assets/components/diffable.rb +0 -30
- data/lib/trackman/assets/components/hashable.rb +0 -29
- data/lib/trackman/assets/components/path_resolver.rb +0 -34
- data/lib/trackman/assets/components/rails32_path_resolver.rb +0 -39
- data/lib/trackman/assets/components/rails_path_resolver.rb +0 -31
- data/lib/trackman/assets/components/remote_asset_factory.rb +0 -13
- data/lib/trackman/assets/components/shippable.rb +0 -31
- data/lib/trackman/assets/errors.rb +0 -10
- data/lib/trackman/assets/errors/asset_not_found_error.rb +0 -8
- data/lib/trackman/assets/errors/config_not_found_error.rb +0 -8
- data/lib/trackman/configuration_handler.rb +0 -99
- data/lib/trackman/debugger.rb +0 -9
@@ -0,0 +1,29 @@
|
|
1
|
+
module Trackman
|
2
|
+
module Components
|
3
|
+
module Shippable
|
4
|
+
def ship diff
|
5
|
+
to_ship = diff.inject([])do |memo, (k, v)|
|
6
|
+
memo + v.map{ |x| {:proc => build_proc(k, x), :value => x} }
|
7
|
+
end
|
8
|
+
|
9
|
+
to_ship.sort_by{ |x| x[:value] }.each do |x|
|
10
|
+
x[:proc].call
|
11
|
+
end
|
12
|
+
end
|
13
|
+
private
|
14
|
+
def build_proc symbol, instance
|
15
|
+
case symbol
|
16
|
+
when :update
|
17
|
+
proc = Proc.new { instance.update }
|
18
|
+
when :create
|
19
|
+
proc = Proc.new { instance.insert }
|
20
|
+
when :delete
|
21
|
+
proc = Proc.new { instance.delete }
|
22
|
+
else
|
23
|
+
raise "something is wrong."
|
24
|
+
end
|
25
|
+
proc
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Trackman
|
2
|
+
module Path
|
3
|
+
module Rails32Resolver
|
4
|
+
include Resolver
|
5
|
+
|
6
|
+
def translate url, parent_url
|
7
|
+
root = working_dir.realpath
|
8
|
+
|
9
|
+
path = url.dup
|
10
|
+
path.slice! /^(\/assets|assets\/)/
|
11
|
+
path = Pathname.new path
|
12
|
+
|
13
|
+
path = prepare_for_sprocket(path, parent_url, root) if path.relative?
|
14
|
+
begin
|
15
|
+
path = sprockets.resolve path
|
16
|
+
rescue Sprockets::FileNotFound => e
|
17
|
+
Trackman::Utility::Debugger.trace "Could not find path: #{path}\n#{e.message}"
|
18
|
+
return nil
|
19
|
+
end
|
20
|
+
path.relative_path_from(root).to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
def prepare_for_sprocket path, parent_url, root
|
24
|
+
folder = (root + Pathname.new(parent_url)).parent.realpath
|
25
|
+
path = (folder + path).to_s
|
26
|
+
path.slice! sprockets.paths.select{|p| path.include? p }.first
|
27
|
+
path
|
28
|
+
end
|
29
|
+
|
30
|
+
def sprockets
|
31
|
+
::Rails.application.assets
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Trackman
|
2
|
+
module Path
|
3
|
+
module RailsResolver
|
4
|
+
include Resolver
|
5
|
+
|
6
|
+
alias old_translate translate
|
7
|
+
alias old_parent_of parent_of
|
8
|
+
|
9
|
+
def parent_of(url)
|
10
|
+
if url.to_s.include?('assets')
|
11
|
+
old_parent_of(url).ascend do |p|
|
12
|
+
return p if p.basename.to_s == 'assets'
|
13
|
+
end
|
14
|
+
else
|
15
|
+
return old_parent_of(url)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def translate url, parent_url
|
20
|
+
path = old_translate(url, parent_url)
|
21
|
+
|
22
|
+
parts = path.split('/')
|
23
|
+
parts.insert(0, 'public') if parts.first != 'public'
|
24
|
+
|
25
|
+
parts.join('/')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Trackman
|
2
|
+
module Path
|
3
|
+
module Resolver
|
4
|
+
def translate url, parent_url
|
5
|
+
raise "parent_url: #{parent_url} is required to be relative" if Pathname.new(parent_url).absolute?
|
6
|
+
|
7
|
+
url = Pathname.new(url) unless url.is_a? Pathname
|
8
|
+
parent_url = Pathname.new(parent_url) unless parent_url.is_a? Pathname
|
9
|
+
|
10
|
+
if url.relative?
|
11
|
+
parent = parent_of(parent_url)
|
12
|
+
child = url
|
13
|
+
else
|
14
|
+
parent = working_dir
|
15
|
+
s = url.to_s
|
16
|
+
child = Pathname.new(s[1...s.length])
|
17
|
+
end
|
18
|
+
|
19
|
+
(parent + child).relative_path_from(working_dir).to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
def working_dir
|
23
|
+
Pathname.new Dir.pwd
|
24
|
+
end
|
25
|
+
|
26
|
+
def parent_of(url)
|
27
|
+
(working_dir + url).parent
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
data/lib/trackman/scaffold.rb
CHANGED
@@ -1,19 +1,7 @@
|
|
1
1
|
module Trackman
|
2
2
|
module Scaffold
|
3
|
-
|
4
|
-
|
5
|
-
def self.autoloads path, items
|
6
|
-
items.each do |s|
|
7
|
-
if block_given?
|
8
|
-
yield(s, "#{path}/#{s.trackman_underscore}" )
|
9
|
-
else
|
10
|
-
autoload s, "#{path}/#{s.trackman_underscore}"
|
11
|
-
end
|
12
|
-
end
|
3
|
+
Trackman.autoloads 'trackman/scaffold', [:ContentSaver] do |s,p|
|
4
|
+
autoload s, p
|
13
5
|
end
|
14
|
-
|
15
|
-
@@modules = [:ContentSaver]
|
16
|
-
|
17
|
-
autoloads 'trackman/scaffold', @@modules
|
18
6
|
end
|
19
7
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'versionomy'
|
2
|
+
|
3
|
+
module Trackman
|
4
|
+
module Utility
|
5
|
+
class Configuration
|
6
|
+
@@ERROR = 'ERROR_PAGE_URL'
|
7
|
+
@@MAINTENANCE = 'MAINTENANCE_PAGE_URL'
|
8
|
+
@@TRACKMAN_ERROR = 'TRACKMAN_ERROR_PAGE_URL'
|
9
|
+
@@TRACKMAN_MAINTENANCE = 'TRACKMAN_MAINTENANCE_PAGE_URL'
|
10
|
+
|
11
|
+
attr_accessor :configs, :heroku_version, :options
|
12
|
+
|
13
|
+
def initialize(heroku_version, options = {})
|
14
|
+
self.options = options
|
15
|
+
self.heroku_version = heroku_version
|
16
|
+
self.configs = get_configs
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup
|
20
|
+
raise Trackman::Errors::ConfigSetupError, "Your heroku version is too low, trackman requires '~> 2.26'." unless is_heroku_valid
|
21
|
+
rename_configs
|
22
|
+
add_configs
|
23
|
+
puts "Done!"
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_configs
|
27
|
+
result = run "heroku config -s" do |option|
|
28
|
+
"heroku config -s #{option}"
|
29
|
+
end
|
30
|
+
Trackman::Configuration.s_to_h(result)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def add_configs
|
35
|
+
if configs.include?(@@TRACKMAN_ERROR) && configs.include?(@@TRACKMAN_MAINTENANCE)
|
36
|
+
trackman_configs = {}
|
37
|
+
[[@@TRACKMAN_ERROR, @@ERROR], [@@TRACKMAN_MAINTENANCE, @@MAINTENANCE]].each do |old_c, new_c|
|
38
|
+
trackman_configs[new_c] = configs[old_c]
|
39
|
+
end
|
40
|
+
|
41
|
+
add = trackman_configs.map{|k,v| "#{k}=#{v}" }.join(' ')
|
42
|
+
add_config add
|
43
|
+
else
|
44
|
+
raise Trackman::Errors::ConfigSetupError, "cannot find trackman configuration, make sure trackman addon is installed"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def rename_configs
|
49
|
+
bkp = {}
|
50
|
+
[@@ERROR, @@MAINTENANCE].each do |c|
|
51
|
+
bkp[c] = configs[c] if configs.include? c
|
52
|
+
end
|
53
|
+
|
54
|
+
add = Hash[bkp.map {|k, v| [k + "_bkp", v] }].map{|k,v| "#{k}=#{v}" }.select{|c| !configs.include? c }.join(' ')
|
55
|
+
|
56
|
+
unless add.empty?
|
57
|
+
add_config add
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.s_to_h configs
|
62
|
+
new_configs = {}
|
63
|
+
configs.split(" ").each do |a|
|
64
|
+
key_val = a.split("=")
|
65
|
+
new_configs[key_val[0]] = key_val[1]
|
66
|
+
end
|
67
|
+
new_configs
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.h_to_s configs
|
71
|
+
out = []
|
72
|
+
configs.each do |k,v|
|
73
|
+
out << k + "=" + v
|
74
|
+
end
|
75
|
+
out.join ' '
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
def is_heroku_valid
|
80
|
+
Versionomy.parse(heroku_version) >= Versionomy.parse("2.26.2")
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_config add
|
84
|
+
run "heroku config:add #{add}" do |option|
|
85
|
+
"heroku config:add #{option} #{add}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def run command
|
90
|
+
command = yield("--app #{options[:app]}") unless self.options[:app].nil?
|
91
|
+
puts "exec: #{command}"
|
92
|
+
result = `#{command}`
|
93
|
+
raise "An error occured running the last command." if $? != 0
|
94
|
+
result
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
module Trackman
|
5
|
+
module Utility
|
6
|
+
class Debugger
|
7
|
+
@@server_url = ENV['TRACKMAN_URL']
|
8
|
+
|
9
|
+
def self.debug_mode?
|
10
|
+
!ENV['TRACKMAN_DEBUG_MODE'].nil? && ENV['TRACKMAN_DEBUG_MODE'] == 'true'
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.trace data
|
14
|
+
puts data if debug_mode?
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.log_exception ex
|
18
|
+
RestClient.post "#{@@server_url}/exceptions", :exception => { :message => ex.message, :backtrace => ex.backtrace }, :ssl_version => 'SSLv3'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
RestClient.log = Logger.new(STDOUT) if Trackman::Utility::Debugger.debug_mode?
|
@@ -19,7 +19,8 @@ if defined?(Rails)
|
|
19
19
|
module Trackman
|
20
20
|
class Railtie < Rails::Railtie
|
21
21
|
rake_tasks do
|
22
|
-
|
22
|
+
path = '../rails_generators/trackman_tasks/templates/*.rake'
|
23
|
+
Dir[File.join(File.dirname(__FILE__), path)].each { |f| load f }
|
23
24
|
end
|
24
25
|
|
25
26
|
initializer "trackman.hook" do |app|
|
data/lib/trackman/version.rb
CHANGED
@@ -12,6 +12,6 @@ namespace :trackman do
|
|
12
12
|
desc "Sets up the heroku configs required by Trackman"
|
13
13
|
task :setup, :app do |t, args|
|
14
14
|
heroku_version = Gem.loaded_specs["heroku"].version.to_s
|
15
|
-
Trackman::
|
15
|
+
Trackman::Configuration.new(heroku_version, :app => args[:app]).setup
|
16
16
|
end
|
17
17
|
end
|
data/spec/asset_factory_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Trackman::Assets::
|
3
|
+
describe Trackman::Assets::AssetFactory do
|
4
4
|
class TestFactory
|
5
|
-
extend Trackman::Assets::
|
5
|
+
extend Trackman::Assets::AssetFactory
|
6
6
|
end
|
7
7
|
|
8
8
|
before :all do
|
@@ -68,6 +68,6 @@ describe Trackman::Assets::Components::AssetFactory do
|
|
68
68
|
|
69
69
|
TestFactory.asset_pipeline_enabled?.should be_false
|
70
70
|
asset = TestFactory.create(:path => 'x.css')
|
71
|
-
asset.should_not be_a_kind_of
|
71
|
+
asset.should_not be_a_kind_of Rails32Resolver
|
72
72
|
end
|
73
73
|
end
|
data/spec/asset_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'digest/md5'
|
|
4
4
|
describe Trackman::Assets::Asset do
|
5
5
|
it "should raise an exception if the path is not good" do
|
6
6
|
wrong_path = "./wrong_path.html"
|
7
|
-
lambda { Asset.new(:path => wrong_path) }.should raise_error Trackman::
|
7
|
+
lambda { Asset.new(:path => wrong_path) }.should raise_error Trackman::Errors::AssetNotFoundError
|
8
8
|
end
|
9
9
|
|
10
10
|
it "is equal if the path is the same" do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class TestComposite
|
4
|
-
include Trackman::Assets::
|
4
|
+
include Trackman::Assets::CompositeAsset
|
5
5
|
|
6
6
|
def path
|
7
7
|
'parent'
|
@@ -18,7 +18,7 @@ class TestAsset < Trackman::Assets::Asset
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe Trackman::Assets::
|
21
|
+
describe Trackman::Assets::CompositeAsset do
|
22
22
|
before :each do
|
23
23
|
@composite = TestComposite.new
|
24
24
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestConfiguration < Trackman::Utility::Configuration
|
4
4
|
def get_configs
|
5
5
|
{
|
6
6
|
"TRACKMAN_MAINTENANCE_PAGE_URL" => "\"en_US.UTF-8\"",
|
@@ -12,7 +12,7 @@ class TestConfigurationHandler < Trackman::ConfigurationHandler
|
|
12
12
|
attr_accessor :heroku_configs
|
13
13
|
|
14
14
|
def add_config add
|
15
|
-
self.heroku_configs = (heroku_configs || {}).merge(
|
15
|
+
self.heroku_configs = (heroku_configs || {}).merge(Configuration.s_to_h(add))
|
16
16
|
end
|
17
17
|
|
18
18
|
def run command
|
@@ -20,9 +20,9 @@ class TestConfigurationHandler < Trackman::ConfigurationHandler
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
23
|
+
describe Configuration do
|
24
24
|
before :each do
|
25
|
-
@config =
|
25
|
+
@config = TestConfiguration.new "2.26.2"
|
26
26
|
end
|
27
27
|
|
28
28
|
it "creates heroku configs" do
|
@@ -44,13 +44,13 @@ describe ConfigurationHandler do
|
|
44
44
|
"TRACKMANw_ERROR_PAGE_URL" => "\"error_page_url\""
|
45
45
|
}
|
46
46
|
|
47
|
-
lambda{ @config.setup }.should raise_error(Trackman::
|
47
|
+
lambda{ @config.setup }.should raise_error(Trackman::Errors::ConfigSetupError)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "raises an error if trackman version is bad" do
|
51
51
|
@config.heroku_version = "2.22.2"
|
52
52
|
|
53
|
-
lambda{ @config.setup }.should raise_error(Trackman::
|
53
|
+
lambda{ @config.setup }.should raise_error(Trackman::Errors::ConfigSetupError)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "backups configs when they already exist and add the new ones" do
|