trackman 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/lib/trackman.rb +14 -7
  2. data/lib/trackman/assets.rb +4 -14
  3. data/lib/trackman/assets/asset.rb +3 -3
  4. data/lib/trackman/assets/asset_factory.rb +46 -0
  5. data/lib/trackman/assets/bundled_asset.rb +26 -0
  6. data/lib/trackman/assets/composite_asset.rb +40 -0
  7. data/lib/trackman/assets/css_asset.rb +1 -1
  8. data/lib/trackman/assets/html_asset.rb +1 -1
  9. data/lib/trackman/assets/persistence.rb +9 -0
  10. data/lib/trackman/assets/persistence/remote.rb +54 -0
  11. data/lib/trackman/assets/remote_asset.rb +4 -45
  12. data/lib/trackman/assets/remote_asset_factory.rb +11 -0
  13. data/lib/trackman/components.rb +9 -0
  14. data/lib/trackman/components/conventions.rb +21 -0
  15. data/lib/trackman/components/diffable.rb +28 -0
  16. data/lib/trackman/components/hashable.rb +27 -0
  17. data/lib/trackman/components/shippable.rb +29 -0
  18. data/lib/trackman/errors.rb +9 -0
  19. data/lib/trackman/errors/asset_not_found_error.rb +6 -0
  20. data/lib/trackman/errors/config_not_found_error.rb +6 -0
  21. data/lib/trackman/errors/config_setup_error.rb +7 -0
  22. data/lib/trackman/path.rb +9 -0
  23. data/lib/trackman/path/rails32_resolver.rb +35 -0
  24. data/lib/trackman/path/rails_resolver.rb +29 -0
  25. data/lib/trackman/path/resolver.rb +32 -0
  26. data/lib/trackman/scaffold.rb +2 -14
  27. data/lib/trackman/utility.rb +9 -0
  28. data/lib/trackman/utility/configuration.rb +98 -0
  29. data/lib/trackman/{core_extensions.rb → utility/core_extensions.rb} +0 -0
  30. data/lib/trackman/utility/debugger.rb +24 -0
  31. data/lib/{trackman_railtie.rb → trackman/utility/railtie.rb} +2 -1
  32. data/lib/trackman/version.rb +1 -1
  33. data/rails_generators/trackman_tasks/templates/trackman.rake +1 -1
  34. data/spec/asset_factory_spec.rb +3 -3
  35. data/spec/asset_spec.rb +1 -1
  36. data/spec/composite_asset_spec.rb +2 -2
  37. data/spec/{configuration_handler_spec.rb → configuration_spec.rb} +6 -6
  38. data/spec/diffable_spec.rb +2 -2
  39. data/spec/helpers/act_like_rails2311.rb +2 -2
  40. data/spec/helpers/act_like_rails32.rb +2 -2
  41. data/spec/helpers/app_creator.rb +12 -5
  42. data/spec/helpers/fakable_pathman_tester.rb +5 -5
  43. data/spec/paths/pathman_spec.rb +2 -2
  44. data/spec/paths/rails32_pathman_spec.rb +2 -2
  45. data/spec/{rails32_path_resolver_spec.rb → rails32_resolver_spec.rb} +3 -3
  46. data/spec/remote_asset_spec.rb +13 -17
  47. data/spec/{scaffolding_spec.rb → scaffold_spec.rb} +0 -0
  48. data/spec/shippable_spec.rb +2 -2
  49. data/spec/spec_helper.rb +6 -6
  50. data/spec/sync_spec.rb +1 -1
  51. metadata +32 -27
  52. data/lib/trackman/assets/components.rb +0 -13
  53. data/lib/trackman/assets/components/asset_factory.rb +0 -48
  54. data/lib/trackman/assets/components/bundled_asset.rb +0 -29
  55. data/lib/trackman/assets/components/composite_asset.rb +0 -42
  56. data/lib/trackman/assets/components/conventions.rb +0 -23
  57. data/lib/trackman/assets/components/diffable.rb +0 -30
  58. data/lib/trackman/assets/components/hashable.rb +0 -29
  59. data/lib/trackman/assets/components/path_resolver.rb +0 -34
  60. data/lib/trackman/assets/components/rails32_path_resolver.rb +0 -39
  61. data/lib/trackman/assets/components/rails_path_resolver.rb +0 -31
  62. data/lib/trackman/assets/components/remote_asset_factory.rb +0 -13
  63. data/lib/trackman/assets/components/shippable.rb +0 -31
  64. data/lib/trackman/assets/errors.rb +0 -10
  65. data/lib/trackman/assets/errors/asset_not_found_error.rb +0 -8
  66. data/lib/trackman/assets/errors/config_not_found_error.rb +0 -8
  67. data/lib/trackman/configuration_handler.rb +0 -99
  68. data/lib/trackman/debugger.rb +0 -9
@@ -1,29 +0,0 @@
1
- module Trackman
2
- module Assets
3
- module Components
4
- module BundledAsset
5
- include Hashable
6
-
7
- def env
8
- @@env ||= ::Rails.application.assets.index
9
- end
10
-
11
- def data
12
- result = (@bundled ||= init_data)
13
-
14
- return super if result.nil? || result.length == 0
15
- result
16
- end
17
-
18
- def init_data
19
- begin
20
- return env[env.attributes_for(path.realpath).pathname].to_s
21
- rescue
22
- return nil
23
- end
24
- end
25
-
26
- end
27
- end
28
- end
29
- end
@@ -1,42 +0,0 @@
1
- module Trackman
2
- module Assets
3
- module Components
4
- module CompositeAsset
5
- @@url = /url\(['"]?([^'")]+)['"]?\)/
6
- @@import = /url\(['"]?[^'"]+['"]?\)/
7
-
8
- def self.included(mod)
9
- mod.send(:include, PathResolver)
10
- end
11
- def self.extended(mod)
12
- mod.send(:extend, PathResolver)
13
- end
14
-
15
- def assets
16
- internals = children_paths.select{|p| p.internal_path? }.map{|p| {:old => p, :new_path => translate(p, path)} }
17
- internals = internals.select{|p| !p[:new_path].nil? }.map{|p| asset_from(p[:old], p[:new_path])}
18
- internals.inject([]) do |sum, a|
19
- (sum << a) + a.assets.select{|child| !sum.include?(child) }
20
- end
21
- end
22
-
23
- def asset_from(virtual, physical)
24
- Asset.create(:virtual_path => virtual, :path => physical)
25
- end
26
-
27
- def inner_css_paths
28
- data.scan(@@import).collect{|x| @@url.match(x)[1]}.select{|x| !x.embedded? }
29
- end
30
- end
31
- end
32
- end
33
- end
34
-
35
- class String
36
- def internal_path?
37
- self !~ /^http/
38
- end
39
- def embedded?
40
- self.include? 'data:'
41
- end
42
- end
@@ -1,23 +0,0 @@
1
- module Trackman
2
- module Assets
3
- module Components
4
- module Conventions
5
- Asset = Trackman::Assets::Asset
6
-
7
- def maintenance_path
8
- Pathname.new 'public/503.html'
9
- end
10
- def error_path
11
- Pathname.new 'public/503-error.html'
12
- end
13
- def maintenance_page
14
- Asset.create(:path => maintenance_path, :virtual_path => maintenance_path)
15
- end
16
- def error_page
17
- Asset.create(:path => error_path, :virtual_path => error_path)
18
- end
19
- end
20
- end
21
- end
22
- end
23
-
@@ -1,30 +0,0 @@
1
- module Trackman
2
- module Assets
3
- module Components
4
- module Diffable
5
- def diff local, remote
6
- to_create = local.select{|a| remote.all? { |s| a.path != s.path } }.map{|a| a.to_remote }
7
-
8
- {
9
- :create => to_create,
10
- :update => remote.select{|a| local.any?{ |s| a.path == s.path && a.file_hash != s.file_hash }},
11
- :delete => define_deleted(local, remote) do |a|
12
- to_create.any?{ |c| c.path.basename == a.path.basename }
13
- end
14
- }
15
- end
16
-
17
- private
18
- # will not delete an html for now.
19
- # this behaviour is to avoid the removal of the default templates.
20
- def define_deleted local, remote
21
- to_delete = remote.select do |a|
22
- local.all? { |s| s.path != a.path }
23
- end
24
-
25
- to_delete.reject{|a| a.path.to_s =~ /.html$/ }.to_a
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,29 +0,0 @@
1
- require 'digest/md5'
2
-
3
- module Trackman
4
- module Assets
5
- module Components
6
- module Hashable
7
- def data
8
- @data ||= read_file(path)
9
- end
10
-
11
- def file_hash
12
- @file_hash ||= (data.nil? ? "" : Digest::MD5.hexdigest(data))
13
- end
14
-
15
- protected
16
- def read_file(file_path)
17
- begin
18
- file = File.open(file_path)
19
- return file.read
20
- rescue
21
- return nil
22
- ensure
23
- file.close unless file.nil?
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,34 +0,0 @@
1
- module Trackman
2
- module Assets
3
- module Components
4
- module PathResolver
5
- def translate url, parent_url
6
- raise "parent_url: #{parent_url} is required to be relative" if Pathname.new(parent_url).absolute?
7
-
8
- url = Pathname.new(url) unless url.is_a? Pathname
9
- parent_url = Pathname.new(parent_url) unless parent_url.is_a? Pathname
10
-
11
- if url.relative?
12
- parent = parent_of(parent_url)
13
- child = url
14
- else
15
- parent = working_dir
16
- s = url.to_s
17
- child = Pathname.new(s[1...s.length])
18
- end
19
-
20
- (parent + child).relative_path_from(working_dir).to_s
21
- end
22
-
23
- def working_dir
24
- Pathname.new Dir.pwd
25
- end
26
-
27
- def parent_of(url)
28
- (working_dir + url).parent
29
- end
30
- end
31
- end
32
- end
33
- end
34
-
@@ -1,39 +0,0 @@
1
- require 'sprockets'
2
-
3
- module Trackman
4
- module Assets
5
- module Components
6
- module Rails32PathResolver
7
- include PathResolver
8
-
9
- def translate url, parent_url
10
- root = working_dir.realpath
11
-
12
- path = url.dup
13
- path.slice! /^(\/assets|assets\/)/
14
- path = Pathname.new path
15
-
16
- path = prepare_for_sprocket(path, parent_url, root) if path.relative?
17
- begin
18
- path = sprockets.resolve path
19
- rescue Sprockets::FileNotFound => e
20
- Debugger.trace "Could not find path: #{path}\n#{e.message}"
21
- return nil
22
- end
23
- path.relative_path_from(root).to_s
24
- end
25
-
26
- def prepare_for_sprocket path, parent_url, root
27
- folder = (root + Pathname.new(parent_url)).parent.realpath
28
- path = (folder + path).to_s
29
- path.slice! sprockets.paths.select{|p| path.include? p }.first
30
- path
31
- end
32
-
33
- def sprockets
34
- ::Rails.application.assets
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,31 +0,0 @@
1
- module Trackman
2
- module Assets
3
- module Components
4
- module RailsPathResolver
5
- include PathResolver
6
-
7
- alias old_translate translate
8
- alias old_parent_of parent_of
9
-
10
- def parent_of(url)
11
- if url.to_s.include?('assets')
12
- old_parent_of(url).ascend do |p|
13
- return p if p.basename.to_s == 'assets'
14
- end
15
- else
16
- return old_parent_of(url)
17
- end
18
- end
19
-
20
- def translate url, parent_url
21
- path = old_translate(url, parent_url)
22
-
23
- parts = path.split('/')
24
- parts.insert(0, 'public') if parts.first != 'public'
25
-
26
- parts.join('/')
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,13 +0,0 @@
1
- module Trackman
2
- module Assets
3
- module Components
4
- module RemoteAssetFactory
5
- include AssetFactory
6
-
7
- def retrieve_parent(path)
8
- RemoteAsset
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,31 +0,0 @@
1
- module Trackman
2
- module Assets
3
- module Components
4
- module Shippable
5
- def ship diff
6
- to_ship = diff.inject([])do |memo, (k, v)|
7
- memo + v.map{ |x| {:proc => build_proc(k, x), :value => x} }
8
- end
9
-
10
- to_ship.sort_by{ |x| x[:value] }.each do |x|
11
- x[:proc].call
12
- end
13
- end
14
- private
15
- def build_proc symbol, instance
16
- case symbol
17
- when :update
18
- proc = Proc.new { instance.update }
19
- when :create
20
- proc = Proc.new { instance.insert }
21
- when :delete
22
- proc = Proc.new { instance.delete }
23
- else
24
- raise "something is wrong."
25
- end
26
- proc
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,10 +0,0 @@
1
- module Trackman
2
- module Assets
3
- module Errors
4
- @@classes = [:AssetNotFoundError, :ConfigNotFoundError]
5
- ::Trackman::Assets.autoloads 'trackman/assets/errors', @@classes do |s,p|
6
- autoload s, p
7
- end
8
- end
9
- end
10
- end
@@ -1,8 +0,0 @@
1
- module Trackman
2
- module Assets
3
- module Errors
4
- class AssetNotFoundError < StandardError
5
- end
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Trackman
2
- module Assets
3
- module Errors
4
- class ConfigNotFoundError < StandardError
5
- end
6
- end
7
- end
8
- end
@@ -1,99 +0,0 @@
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, :options
11
-
12
- def initialize(heroku_version, options = {})
13
- self.options = options
14
- self.heroku_version = heroku_version
15
- self.configs = get_configs
16
- end
17
-
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!"
23
- end
24
-
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
-
32
-
33
- def add_configs
34
- if configs.include?(@@TRACKMAN_ERROR) && configs.include?(@@TRACKMAN_MAINTENANCE)
35
- trackman_configs = {}
36
- [[@@TRACKMAN_ERROR, @@ERROR], [@@TRACKMAN_MAINTENANCE, @@MAINTENANCE]].each do |old_c, new_c|
37
- trackman_configs[new_c] = configs[old_c]
38
- end
39
-
40
- add = trackman_configs.map{|k,v| "#{k}=#{v}" }.join(' ')
41
- add_config add
42
- else
43
- raise SetupException, "cannot find trackman configuration, make sure trackman addon is installed"
44
- end
45
- end
46
-
47
- def rename_configs
48
- bkp = {}
49
- [@@ERROR, @@MAINTENANCE].each do |c|
50
- bkp[c] = configs[c] if configs.include? c
51
- end
52
-
53
- add = Hash[bkp.map {|k, v| [k + "_bkp", v] }].map{|k,v| "#{k}=#{v}" }.select{|c| !configs.include? c }.join(' ')
54
-
55
- unless add.empty?
56
- add_config add
57
- end
58
- end
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
-
77
- private
78
- def is_heroku_valid
79
- Versionomy.parse(heroku_version) >= Versionomy.parse("2.26.2")
80
- end
81
-
82
- def add_config add
83
- run "heroku config:add #{add}" do |option|
84
- "heroku config:add #{option} #{add}"
85
- end
86
- end
87
-
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
95
- end
96
-
97
- class SetupException < Exception
98
- end
99
- end